problem with handling the response from sending a SOAP message

I just write a simple java program to test about sending soap message, it works.

at the end of the program, I use :

reply.writeTo(System.out);

System.out.println();

to output the response, but is there anyway to convert the response to string, so that I can use it.

is there any function like

reply.toString().....

Thanks

[371 byte] By [stchonga] at [2007-10-2 5:50:11]
# 1
SOAPMessageContext msgCtx = (SOAPMessageContext) reply;String sReply = msgCtx.getMessage().toString();
swatdbaa at 2007-7-16 1:59:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
thanks for your reply
stchonga at 2007-7-16 1:59:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
after I use the SOAPMessageContext, I get the following reply:com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Implit's not the reply with xml format.anyway to solve it? thanks
stchonga at 2007-7-16 1:59:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

IT seems like you are using Axis. I'm no expert in Axis but the method you called

looks like it expects an OutputStream, so create one on your own and pass it to the method instead of System.out. Thus you could have the contents of the stream dump into a StringBuffer or alike.

Ricardo B.

rbuitragoca at 2007-7-16 1:59:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Here is some code to do what you are looking for:

public static String returnSOAPMessageAsString(SOAPMessage msg)

{

ByteArrayOutputStream baos = null;

String s = null;

try {

baos = new ByteArrayOutputStream();

msg.writeTo(baos);

s = baos.toString();

} catch(Exception e) {

e.printStackTrace();

}

return s;

}

ARTFISHa at 2007-7-16 1:59:34 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...