简体   繁体   中英

Java/Groovy method to Invoke SOAP Web Service (Version 1.2)

I am trying to invoke Web Service (Version 1.2 and dont have a Version 1.1 for this service) using Java/Groovy code. I have tried below options

Using SAAJ

String endpointURL = <<endpoint>>
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// Send SOAP Message to SOAP Server
def Request = <<Request XML>>
InputStream is = new ByteArrayInputStream(Request.getBytes());
SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, is);      
SOAPMessage soapResponse = soapConnection.call(soapMessage, endpointURL)

Using Groovy WsLite

 def client = new SOAPClient(<<endpoint>>)
 def response = client.send(SOAPVersion.V1_2, <<RequestXML>>)

In both cases the I am receivig and error from service indicating version mismatch. Underlying architecture is Oracle Service Bus.

I am able to invoke Web Services which are available with both Versions 1.1 and 1.2 with the same code. I am suspecting that in this case we are able to invoke only Service belonging to version 1.1

Could someone help me understand what is that I am missing here?

The issue was resolved by adding SOAPAction as mimeheader in case of SOAP version 1.2. I was able to resolve this issue by passing SOAPAction along with the SOAPVersion

In case of SAAJ passed

MimeHeaders mimeh = message.getMimeHeaders();
mimeh.addHeader("SOAPAction",<<soapaction>>);

In case of Groovy wslite

def response = client.send(SOAPVersion.V1_2, SOAPAction: <<soapaction>>,<<RequestXML>>)

Your underlying oracle service bus might be configured to support only SOAP 1.1 version. Did you change your code to use SOAPConstants.SOAP_1_1_PROTOCOL and try the same.

If this works, your OSB has to be enabled to support both 1.1 and 1.2 soap versions.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM