Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a string to a SOAPMessage in Java?

Tags:

java

string

soap

I wonder is there any way to convert a string to SOAPMessage?

Let me say I have a string as follows:

String send = "<soap:Envelope xmlns:mrns0=\"http://sdp.SOMETHING.com/mapping/TSO\" xmlns:sdp=\"http://sdp.SOMETHING.com.tr/mapping/generated\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"         + "<soap:Header>"         + "<sdp:token>"         + "<sdp:sessionId>" + sessionId + "</sdp:sessionId>"         + "</sdp:token>"         + "<sdp:transaction-list>"         + "<sdp:transaction-id>" + 11 + "</sdp:transaction-id>"         + "</sdp:transaction-list>"         + "</soap:Header>"         + "<soap:Body>"         + "<sdp:SendSMSInput>"         + "<sdp:EXPIRY_DATE>" + extime + "</sdp:EXPIRY_DATE>"         + "<sdp:MESSAGE_CLASS>0</sdp:MESSAGE_CLASS>"         + "<sdp:S_DATE>" + time + "</sdp:S_DATE>"         + "<sdp:SHORT_NUMBER>1905</sdp:SHORT_NUMBER>"         + "<sdp:SRC_MSISDN>" + numSend + "</sdp:SRC_MSISDN>"         + "<sdp:TO_RECEIVERS>"         + "<sdp:msisdn>" + numSend + "</sdp:msisdn>"         + "</sdp:TO_RECEIVERS>"         + "<sdp:MESSAGE_BODY>"         + "<sdp:message>Message body here.</sdp:message>"         + "</sdp:MESSAGE_BODY>"         + "</sdp:SendSMSInput>"         + "</soap:Body>"         + "</soap:Envelope>"; 

How do I convert the string?

like image 404
Ali Yucel Akgul Avatar asked Nov 28 '12 21:11

Ali Yucel Akgul


People also ask

How do you convert SOAPBody to string?

Element, the easiest way would probably be using TrAX : SOAPBody element = ... // Whatever DOMSource source = new DOMSource(element); StringWriter stringResult = new StringWriter(); TransformerFactory. newInstance(). newTransformer().

How do you make a SOAP envelope in Java?

SOAPEnvelope envelope = soapPart. getEnvelope(); You can now use the getHeader and getBody methods of envelope to retrieve its empty SOAPHeader and SOAPBody objects. SOAPHeader header = envelope.


1 Answers

Convert the String into an input stream, then read it into the SOAP message factory.

InputStream is = new ByteArrayInputStream(send.getBytes()); SOAPMessage request = MessageFactory.newInstance().createMessage(null, is); 

You can read about how to do this here.

like image 177
durron597 Avatar answered Sep 16 '22 11:09

durron597