Need Code to Print SOAP Message
I'm using SAAJ to create SOAP messages and I'm looking for code that will print a SOAP message, including all tags, attributes, etc. as it would look if it had been hand-coded.
I've searched through this forum and found some similar posts, but the answers either just use the SOAPMessage writeTo() method, or do not print output formatted the way I want.
Is it possible to do this?
Thanks.
Hello.
Try this (soapMessage is your SoapMessage object instance that you created)
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
soapMessage.writeTo( outputStream );
byte[] byteArray = outputStream.toByteArray();
String soapMsg = new String( byteArray, "UTF-8");
// print the soapMsg
Hope this helps.
Similar Messages
-
Printing SOAP message sent / received
We've developed a web service that allows a client to send and receive the expected data from a java and a .net client. We're having a problem however when instantiating an object to pass as a param to the webservice from the .net client. It works fine with java primitive type or String - we've tested this. But when we create a class that has a three strings as attributes, none of the params are getting across - the object isn't null, its just marshalled or unmarshalled incorrectly (we think).
What I need to know is how to turn on some type of verbosity so I can see the soap message when using the external .net client? I can see the message fine on the java side, but not when invoking from .net.You could also monitor this from the .NET client end. One approach is to
write a SOAP extension to intercept the AfterSerialize and BeforeDeserialize
events. Here's a sample code that logs the SOAP request and response:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconalteringsoapmessag
eusingsoapextensions.asp
Jorge
"Andrew Bray" <[email protected]> wrote in message
news:[email protected]..
We've developed a web service that allows a client to send and receive theexpected data from a java and a .net client. We're having a problem however
when instantiating an object to pass as a param to the webservice from the
.net client. It works fine with java primitive type or String - we've
tested this. But when we create a class that has a three strings as
attributes, none of the params are getting across - the object isn't null,
its just marshalled or unmarshalled incorrectly (we think).
>
What I need to know is how to turn on some type of verbosity so I can seethe soap message when using the external .net client? I can see the message
fine on the java side, but not when invoking from .net. -
Printing formatted Soap Message in conole
Hello,
I have written one service and one SOAPMessageHandler, in this class i need to print formatted soap message,but how i dont know
here is my code:
SOAPMessage soapMessage = context.getMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
if (soapHeader == null) {
System.out.println(" Adding Empty Header [" + this.getClass().getSimpleName() + "]");
soapHeader = soapEnv.addHeader();
QName qIdName =.....
SOAPHeaderElement soapHeaderElem = soapHeader.addHeaderElement(qIdName);
soapHeaderElem.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
soapHeaderElem.addTextNode("some id name");
soapMessage.writeTo(System.out);Can anyone tell me how to do that? is there some parameter set needed (As it is JAXB_FORMATTED_OUTPUT )?Hi,
Can you try using ByteArrayOutputStream to print soap message
here is the snippet of code
=================
SOAPMessage soapMessage = messageContext.getMessage()
dumpSOAPMessage(soapMessage);
============================
private void dumpSOAPMessage(SOAPMessage msg) {
if (msg == null) {
System.out.println("SOAP Message is null");
return;
System.out.println("");
System.out.println("--------------------");
System.out.println("DUMP OF SOAP MESSAGE");
System.out.println("--------------------");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
msg.writeTo(baos);
System.out.println(baos.toString(getMessageEncoding(msg)));
// show included values
String values = msg.getSOAPBody().getTextContent();
System.out.println("Included values:" + values);
} catch (Exception e) {
e.printStackTrace();
Hope that helps
Regards,
sunil -
I need to secure SOAP message sent into SOAP adapter, how to?
Hi guys,
My scenario uses SOAP and I need to secure this SOAP message sent into SOAP adapter. As I have read in the documentation, HTTPS is possible only on the SOAP receiver adapter. But my is SENDER.
COuld you help me please, how to solve it? Or post some link? Or, if you have your own approach, to let me know?
Thanx, PeterHi,
you can use SSL with the sender adapter. Please see the extract of the SOAP Adapter FAQ (Note #856597) below:
<b>Q:</b> Can I use SSL for my sender adapter?
<b>A:</b> Yes. Normally, the SOAP adapter servlet runs on the engines HTTP port. But you can activate the engine's HTTPS port so that this servlet can receive messages sent to the HTTPS port. See the documentation about the J2EE engine's security configuration.
I am afraid, I haven't yet tried this myself, so you will need to consult the J2EE documentation.
Regards,
HC -
MessageContext.getMessage().toString() is not giving soap message
Hi,
I have implemented a handler for JAX-RPC web service on weblogic 10.3 and my code in handler is exactly same as below.
public boolean handleRequest(MessageContext context) {
SOAPMessageContext messageContext = (SOAPMessageContext) context;
System.out.println("** Request: "+messageContext.getMessage().toString());
log.info(messageContext.getMessage().toString());
return true;
and It is not printing complete SOAP message. Instead it is just printing something like .."weblogic.xml.saaj.SOAPMessageImpl@a050277". I feel this is some issue with classpath setting. can somebody please assist with this?Hi,
Can you try using ByteArrayOutputStream to print soap message
here is the snippet of code
=================
SOAPMessage soapMessage = messageContext.getMessage()
dumpSOAPMessage(soapMessage);
============================
private void dumpSOAPMessage(SOAPMessage msg) {
if (msg == null) {
System.out.println("SOAP Message is null");
return;
System.out.println("");
System.out.println("--------------------");
System.out.println("DUMP OF SOAP MESSAGE");
System.out.println("--------------------");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
msg.writeTo(baos);
System.out.println(baos.toString(getMessageEncoding(msg)));
// show included values
String values = msg.getSOAPBody().getTextContent();
System.out.println("Included values:" + values);
} catch (Exception e) {
e.printStackTrace();
Hope that helps
Regards,
sunil -
Can I create a SOAP message object from a string?
can i create a soap message object in saaj with a string containing soap xml?
I know messageFactory has a constructor that
public abstract SOAPMessage createMessage(MimeHeaders headers, InputStream in)
does anyone know how to use this? Specifically transform a SOAP message in string format to something i could pass this constructor.
Is there a better way to do this?
I'm not EVER going to use apache's tomcat or GLUE or anyting and need to send a soap message from a client to a server via SOAP. I need to be able to transfer a String SOAP document to something i can search for elements with.sorry for being critical but the tutorial you just linked to is for the most part USELESS. it doesnt deal with Java just what a SOAP message looks like. yeah, i get it, its like xml. now how do i do what i want to with saaj?
something like
String sm;
sm = in.readLine(); //gives me a whole SOAP document (pretend)
sm--->>>MAGIC------>>>>>MIMEHeaders headers & InputStream sm_in
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage(headers, sm_in);
SOAPBody soapBody = message.getSOAPBody();
Name bodyName = factory.createName("YUP","m","http://theinternet/YUP");
Iterator iterator = soapBody.getChildElements(bodyName);
SOAPBodyElement bodyElement = (SOAPBodyElement)iterator.next();
String yup = bodyElement.getValue();
System.out.println("YUP element of the SOAP document is " + yup);what is the MAGIC in the above code? -
How to intercept incoming SOAP messages?
I'm using weblogic workshop 8.1 for creating web services. I need to intercept incoming SOAP messages in order to do some processing before executing the required function (especially i would like to be able to know which function is to be executed and if required, execute an athorer one, according to the processing result)
I've tryed the tutorial given in the help, but i can't get it work. I'm using the example here after and i'm getting the following error: " the element '@jws:handler' is not allowed at this location".
package Handler;
* @jws:handler operation="handler.ConsoleLoggingHandler"
public class HandlerExample1 implements com.bea.jws.WebService
static final long serialVersionUID = 1L;
/** @common:operation */
public String echoString(String inputString)
return inputString;
I will apreciate if some one has a clue to resolve this problem.
Thank youHello,
From [1], Handlers on incoming messages are invoked before the message
is delivered to the web service operation, and handlers on outgoing
messages are invoked after the web service operation has completed. The
web service itself is unaware of the presence of handlers. SOAP message
handlers are sometimes referred to as interceptors. Also see [2][3].
Did you include the code for the handler
(handler.ConsoleLoggingHandler)? [4]
Here's a simple handler example [5]
Hope this is of some value,
Bruce
[1]
http://e-docs.bea.com/workshop/docs81/doc/en/workshop/guide/getstarted/conSOAPHandlers.html
[2]
http://e-docs.bea.com/workshop/docs81/doc/en/workshop/guide/getstarted/conSOAPHandlers.html?skipReload=true#WhereHandlersFit
[3]
http://edocs.beasys.com/wls/docs81/webserv/interceptors.html#1060763
[4]
http://e-docs.bea.com/workshop/docs81/doc/en/workshop/guide/getstarted/conSOAPHandlers.html?skipReload=true#HandlerExample
[5]
http://webservice.bea.com/log.zip
Fatna wrote:
>
I'm using weblogic workshop 8.1 for creating web services. I need to intercept incoming SOAP messages in order to do some processing before executing the required function (especially i would like to be able to know which function is to be executed and if required, execute an athorer one, according to the processing result)
I've tryed the tutorial given in the help, but i can't get it work. I'm using the example here after and i'm getting the following error: " the element '@jws:handler' is not allowed at this location".
package Handler;
* @jws:handler operation="handler.ConsoleLoggingHandler"
public class HandlerExample1 implements com.bea.jws.WebService
static final long serialVersionUID = 1L;
/** @common:operation */
public String echoString(String inputString)
return inputString;
I will apreciate if some one has a clue to resolve this problem.
Thank you -
How to create soap message through java using JAXM
Hi,
I'M REALLY NEW TO THIS JAVA WEB SERVICES. I need to send a soap messages from core java with using url and it goes to my servlet and able to retrieve the soap message and do the processing. I really don't the work flow too. I'm using JAXM for receiving and transfering message. Could anyone tell me how its going to work for core java. Actually i need to accept any incoming soap messages and according to the request i got , i do need to do the further processing and again send back response to the core java. I'm not sure what i'm telling is wright or wrong. I literally confused with whole java web services . Could anyone help me out please or suggest some other suggestions through which i can proceed further.
in advance thanks a lot.......File f = new File("c:\MyFolder");
f.mkdir(); -
Hi, i'm new in webservice and xml. I want to save the returned SOAP Message by webservice in the database (xmltype).
String inputLine;
String xmlDoc = "";
URL xml = new URL("http://sph001000-020:7777/i3sWebServices-FireWebService-context-root/FireWebService?invoke=lov_fritmtp");
InputStream input = xml.openStream();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
int cnt = 1;
while ((inputLine = in.readLine()) != null)
if (cnt == 1){
xmlDoc = xmlDoc + inputLine;
cnt = 0;
else cnt = 0;
System.out.println("xml " + xmlDoc);
in.close();
here is where i got stuck, can anyone help me save the string xmlDoc in database(xmlType)?
Thanks in advance!
Regards,
HardyHi,
I had a similar need to save a SOAP message for later processing, using NetBeans. I used a routine saveSOAPMessage (shown below) to write the SOAP message to a file as XML, and then processed the saved XML file. You might be able to do something like this to save the message in your database.
Good luck.
gordonwj
private boolean saveSOAPMessage(String path, SOAPMessage message)
boolean isValid = true;
try
FileOutputStream foutStr = new FileOutputStream(path);
message.writeTo(foutStr);
foutStr.close();
catch (Exception e)
String s = e.getMessage();
errorMessage = "Error writing SOAP message to file " + path;
isValid = false;
return(isValid);
} -
I have two programs, the Server.java and Client.java. The Client creates a simple SOAP message and send to the server. The server listens to the port and print out whatever it received from the port: // Server.java -----------------------------------------------------------------------
ServerSocket serverSocket = new ServerSocket(4444);
Socket socket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
// Client.java -----------------------------------------------------------------------
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPConnectionFactory connFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = connFactory.createConnection();
SOAPBody body = message.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName("GetLastTradePrice", "m", "http://wombat.ztrade.com");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
URL endpoint = new URL("http://localhost:4444/");
SOAPMessage response = connection.call(message, endpoint);
connection.close();Unfortunately, when I run the programs, the Server console prints only the following lines but there is no SOAP contents printed, what could be the problem? Is this normal? Output from Server console:
POST / HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: 246
SOAPAction: ""
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.4.2_03
Host: localhost:4444
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
// no more lines, waiting for next connectionfirst of all: to open a server socket it is not webservice technique !!!!!!!!!!!!!!
you have to use a servlet to accept SOAP call message.
public void doPost( HttpServletRequest req, HttpServletResponse res ) {
InputStream in = req.getInputStream() ;
SOAPMessage soapMessage =
messageFactory.createMessage(getHeaders(req), in) ;
// to print SOAP message to Console :
soapMessage.writeTo( System.out );
Thank you -
How to get full SOAP message sent from XI to web srvice
Hi guys!
In my scenario IDoc->XI->SOAP I need to see the SOAP message, which arrives into target web service. Where can I see it? I suppose in sxmb monitor, but which part? I can not find it...
Thanx, OlianIn MONi you will only be able to see the XML payload or rather the SOAP Body.
If you want to see the entire HTTP post message used by the SOAP adapter will the SOAP Enevlope you need to use either,
1. The TCP Gateway as shown in Stefan's Blog
or,
2. Follow the instructions in this thread. You would need to turn on Synch Logging in the Visual Admin for this though,
Monitoring SOAP Message Payload
I would suggest you follow Stefan's blog as it is quite simple rather than turning on Synch Logging in the Va.
Regards
Bhavesh -
Accepting a SOAP message that contains fault elements
Hi,
I am trying to create a webservice that will accept a valid soap messages that
contains faults. Actual functionality required is to accept a valid soap message
with or without faults. For this, I created separate methods in my java class
(one for normal flow and one that will handle fault elements) that implements
my web service. I need to manipulate the soap message for both cases. Hence, I
created separate handlers to do this task. I created two handler chains in my
web-services.xml one for handling soap messages that contains faults and one for
handling soap messages that doesn't contain faults. The web services was successfully
deployed and works fine for soap messages that doesn't contain fault. But, if
I send a soap message with faults the client (that calls my webservice) is not
even hitting my web service. It gets a HTTP
500. Can anybody help me on this ?
Thanks,
Ganesh BalachandranHi Ganesh,
Which version of weblogic server you are using? Can you turn on verbose in
client side? You can give a "-Dweblogic.webservice.verbose=true" to client
side JVM. We need to see what your soap message with fault looks like.
Thanks,
-Neal
"Ganesh" <[email protected]> wrote in message
news:[email protected]..
>
Hi,
I am trying to create a webservice that will accept a valid soap messagesthat
contains faults. Actual functionality required is to accept a valid soapmessage
with or without faults. For this, I created separate methods in my javaclass
(one for normal flow and one that will handle fault elements) thatimplements
my web service. I need to manipulate the soap message for both cases.Hence, I
created separate handlers to do this task. I created two handler chains inmy
web-services.xml one for handling soap messages that contains faults andone for
handling soap messages that doesn't contain faults. The web services wassuccessfully
deployed and works fine for soap messages that doesn't contain fault. But,if
I send a soap message with faults the client (that calls my webservice) isnot
even hitting my web service. It gets a HTTP
500. Can anybody help me on this ?
Thanks,
Ganesh Balachandran -
Traping the SOAP message before making the call.
We are using the axis for Web services, it works fine,
Here is my question, before the call go out to third party services, I need to log the SOAP message into our logging system. How would I trap the message?
Thanks in advance.
-APK.I tried to achieve that using the following:
http://e-docs.bea.com/wls/docs81/webserv/interceptors.html#1072668
But it doesn't seem to work. try it!!
-k -
Web service client needs to share data with a SOAP Message Handler
I have a web service client that is built using WebLogic 10 clientgen. I also have a Soap Message Handler configured that will create the required Soap Headers for the web service call.
Creating these Soap Headers works great as long as the header data is static but the problem comes up when I need to place some dynamic data in these headers. The web service client has this data and somehow needs to pass it to the Soap Message Handler. It looks like I need to somehow have the client place this data in the MessageContext before the call so the data can be accessed by the Soap Message Handler.
How do I get access to the MessageContext from the client or is there a better way to do this?
Thanks in advance for any help you can give.You may want to check the response to this previous post to see if it yields any ideas for you:
Not able to Pass header info to Microsoft MapPoint WebService using WLS10 -
Need Help Printing Text Messages From E71
I need to print some saved text messages that are on my e71 but cannot ge **bleep** to hook up to my bluetooth printer it just never finds it. Is there another way to print these messages fromt he phone i really need them
connect to pc and use ovi suite
If i have helped at all a click on the white star below would be nice thanks.
Now using the Lumia 1520
Maybe you are looking for
-
Hi all, I'm having an issue extracting the first 11 characters from a 14 character string (read in from a DB2 database) using the getChars method. Here's the code: String s = (rs.getString("partition_name")); System.out.println("original string: " +
-
Ok so I'm kinda broad looking for a brand new FPS game and I wranded into kill zone 3 and it looks amazing,should buy it yes or no
-
How to re-install my adobe CC again?
Yesterday I had a problem with my computer. It would noT open and windows made a verification of the problem but it uninstalled my Adobe InDesign CC, Photoshop and Illustrator. I went on the cloud to reinstall them but it looks like I can't. I have a
-
Regarding HCM Function Modules
Hi Friends I am new to ABAP-HR. Currently I was given some task to enhance MSS team viewer functionality so that "MSS team viewer need to be customized to read the custom evaluation path which incorporates relationship 210 created by UWLs substation
-
MacBook Pro 2011 not charging green light on charger
Bought my MacBook Pro early 2011, really took care of it, no problem till now. Was using it last night as usual and when plug in the charger this morning there's green light but not charging, usually when charging its orange, the battery level on the