File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes How can i extract SOAP XML from java web services stub. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How can i extract SOAP XML from java web services stub." Watch "How can i extract SOAP XML from java web services stub." New topic
Author

How can i extract SOAP XML from java web services stub.

yashi jain
Greenhorn

Joined: Jun 28, 2013
Posts: 4
Hi All,

I am using SOAP web service and i have generated the java stubs through WSDL using JAX-WS. I want to print the request and response SOAP XML in log file as well as store them in the database.
This is really urgent if someone can help me quickly , it will be greatly appreciated.

Thanks for your help and guidance.
Yashi Jain
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41601
    
  55
Welcome to JavaRanch. All questions are always urgent to the person asking them, but with the impending weekend you may have to be patient for a few days.

Two approaches you may want to investigate:

1) SOAP stacks are generally implemented as servlets - so you can attach regular servlet filters and read the HTTP body.

2) Use JAX-WS handlers. If you want to capture the entire SOAP message, then it's a SOAP handler -not a logical handler- that you want. That article gives an example of a handler that captures and prints the SOAP.


Ping & DNS - my free Android networking tools app
yashi jain
Greenhorn

Joined: Jun 28, 2013
Posts: 4
Hi Ulf Dittmer,

Thanks a lot for your guidance.I really appreciate your help on this.

I've gone through the link provided in your reply(JAX-WS handlers), as well as before posting the query i went through the below SOAP handler tutorial from oracle :

http://docs.oracle.com/cd/E21764_01/web.1111/e13734/handlers.htm#

I tried to use 3 different approaches in order to implement the SOAP Handlers in my JWS, but i'm facing issues in all 3 of them and i'm sort of stuck with these issues.Please find the details below :

1) I added following annotation in my JWS file :

@WebService(serviceName = "EnterprisePatientService", targetNamespace = "http://www.rxconnect.cvs.com/resi", endpointInterface = "com.cvs.rxconnect.resi.EnterprisePatientServicePort")
@WLHttpTransport(contextPath = "RESI/PatientService", serviceUri = "EnterprisePatientService", portName = "EnterprisePatientServicePort")
@HandlerChain(file="SimpleChain.xml", name="SimpleChain")

Defined External Configuration file named(SimpleChain.xml) for handler chain :

<?xml version="1.0" encoding="UTF-8" ?>
<handler-chains xmlns="http://www.bea.com/xml/ns/jws">
<handler-chain>
<handler>
<handler-class>com.cvs.rxconnect.resi.Handler1</handler-class>
</handler>
</handler-chain>
</handler-chains>


Defined Handler Class(Handler1.java) as below to extract SOAP Message from request :

package com.cvs.rxconnect.resi;

import java.util.Collections;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class Handler1 implements SOAPHandler<SOAPMessageContext> {

public Set<QName> getHeaders() {
return Collections.emptySet();
}

public void close(MessageContext arg0) {
// TODO Auto-generated method stub

}

public boolean handleFault(SOAPMessageContext arg0) {
// TODO Auto-generated method stub
return true;
}

public boolean handleMessage(SOAPMessageContext messageContext)
throws java.lang.RuntimeException {
Boolean outboundProperty = (Boolean) messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if (!outboundProperty.booleanValue()) {
System.out.println("\n Inbound Message:");
SOAPMessage soapMessage = messageContext.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
try {
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
System.out.println("Values in soapEnvelope are :" + soapEnvelope);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}

}

I'm using Weblogic as Application Server.When i'm trying to build this project using JWSC ant task it gives following error:

[jwsc] [ERROR] - javax.jws.WebService.endpointInterface com.cvs.rxconnect.r
esi.EnterprisePatientServicePort is invalid.
[jwsc] C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServic
eGateway\src\com\cvs\rxconnect\resi\EnterprisePatientServicePortImpl.java 60:8
[jwsc] [ERROR] - Handler chain file validation error for file: file:/C:/Doc
uments and Settings/njain2/Release10_Handlers_POC/RxCWebServiceGateway/src/com/c
vs/rxconnect/resi/SimpleChain.xml. C:\Documents and Settings\njain2\Release10_Ha
ndlers_POC\RxCWebServiceGateway\file:\C:\Documents and Settings\njain2\Release10
_Handlers_POC\RxCWebServiceGateway\src\com\cvs\rxconnect\resi\SimpleChain.xml:0:
error: The document is not a handler-config@http://www.bea.com/xml/ns/jws: docu
ment element local name mismatch expected handler-config got handler-chains
[AntUtil.deleteDir] Deleting directory C:\DOCUME~1\njain2\LOCALS~1\Temp\_ha4pt

BUILD FAILED
C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServiceGateway\bui
ld.xml:160: weblogic.wsee.tools.WsBuildException: JWS Validation failed.

Total time: 21 seconds

2) Declared below annotation in my JWS file :

@WebService(serviceName = "EnterprisePatientService", targetNamespace = "http://www.rxconnect.cvs.com/resi", endpointInterface = "com.cvs.rxconnect.resi.EnterprisePatientServicePort")
@WLHttpTransport(contextPath = "RESI/PatientService", serviceUri = "EnterprisePatientService", portName = "EnterprisePatientServicePort")
@HandlerChain(file="SimpleChain.xml", name="SimpleChain")


SimpleChain.xml

<jwshc:handler-config xmlns:jwshc="http://www.bea.com/xml/ns/jws"
xmlns:soap1="http://HandlerInfo.org/Server1"
xmlns:soap2="http://HandlerInfo.org/Server2"
xmlns="http://java.sun.com/xml/ns/j2ee" >
<jwshc:handler-chain>
<jwshc:handler-chain-name>SimpleChain</jwshc:handler-chain-name>
<jwshc:handler>
<handler-name>handler1</handler-name>
<handler-class>com.cvs.rxconnect.resi.Handler1</handler-class>
</jwshc:handler>
</jwshc:handler-chain>
</jwshc:handler-config>


Handler1.java

package com.cvs.rxconnect.resi;

import java.util.Collections;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class Handler1 implements SOAPHandler<SOAPMessageContext> {

public Set<QName> getHeaders() {
return Collections.emptySet();
}

public void close(MessageContext arg0) {
// TODO Auto-generated method stub

}

public boolean handleFault(SOAPMessageContext arg0) {
// TODO Auto-generated method stub
return true;
}

public boolean handleMessage(SOAPMessageContext messageContext)
throws java.lang.RuntimeException {
Boolean outboundProperty = (Boolean) messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if (!outboundProperty.booleanValue()) {
System.out.println("\n Inbound Message:");
SOAPMessage soapMessage = messageContext.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
try {
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
System.out.println("Values in soapEnvelope are :" + soapEnvelope);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}

}


Error received while deploying tihs Webservice in Weblogic is attached in an attachment(Exception.bmp).

3) added below annotation in JWS file :

@WebService(serviceName = "EnterprisePatientService", targetNamespace = "http://www.rxconnect.cvs.com/resi", endpointInterface = "com.cvs.rxconnect.resi.EnterprisePatientServicePort")
@WLHttpTransport(contextPath = "RESI/PatientService", serviceUri = "EnterprisePatientService", portName = "EnterprisePatientServicePort")
@SOAPMessageHandlers ( {
@SOAPMessageHandler (
className="com.cvs.rxconnect.resi.Handler1")} )


Handler1.java code is :

package com.cvs.rxconnect.resi;

import java.util.Collections;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class Handler1 implements SOAPHandler<SOAPMessageContext> {

public Set<QName> getHeaders() {
return Collections.emptySet();
}

public void close(MessageContext arg0) {
// TODO Auto-generated method stub

}

public boolean handleFault(SOAPMessageContext arg0) {
// TODO Auto-generated method stub
return true;
}

public boolean handleMessage(SOAPMessageContext messageContext)
throws java.lang.RuntimeException {
Boolean outboundProperty = (Boolean) messageContext.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);

if (!outboundProperty.booleanValue()) {
System.out.println("\n Inbound Message:");
SOAPMessage soapMessage = messageContext.getMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
try {
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
System.out.println("Values in soapEnvelope are :" + soapEnvelope);
} catch (SOAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}

}


When i ran build.xml it gives below mentioned error:
[jwsc] C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServic
eGateway\src\com\cvs\rxconnect\resi\EnterprisePatientServicePortImpl.java 62:8
[jwsc] [ERROR] - The annotation javax.jws.soap.SOAPMessageHandlers is not a
llowed on com.cvs.rxconnect.resi.EnterprisePatientServicePortImpl when a javax.j
ws.WebService.endpointInterface is used.
[AntUtil.deleteDir] Deleting directory C:\DOCUME~1\njain2\LOCALS~1\Temp\_ha4pt

BUILD FAILED
C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServiceGateway\bui
ld.xml:160: weblogic.wsee.tools.WsBuildException: JWS Validation failed.

Total time: 1 minute 47 seconds

If you can provide me any further guidance on this, it will be really helpful.














[Thumbnail for Exception.JPG]

Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
You're #1 approach is similar to what I do at work except for the part where you use

'<handler-chains xmlns="http://www.bea.com/xml/ns/jws">' from your SimpleChain.xml. I'm not sure if that is a requirement for you because you are using Oracle/BEA server? But that seems to be where the validation error is coming from (quoted below and in bold). Can you try changing this to '<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">' and see if that works?

yashi jain wrote:
[jwsc] [ERROR] - Handler chain file validation error for file: file:/C:/Doc
uments and Settings/njain2/Release10_Handlers_POC/RxCWebServiceGateway/src/com/c
vs/rxconnect/resi/SimpleChain.xml. C:\Documents and Settings\njain2\Release10_Ha
ndlers_POC\RxCWebServiceGateway\file:\C:\Documents and Settings\njain2\Release10
_Handlers_POC\RxCWebServiceGateway\src\com\cvs\rxconnect\resi\SimpleChain.xml:0:
error: The document is not a handler-config@http://www.bea.com/xml/ns/jws: docu
ment element local name mismatch expected handler-config got handler-chains


yashi jain
Greenhorn

Joined: Jun 28, 2013
Posts: 4
Hi Dennis,

Thanks a lot for your help.I tried your suggestion (You're #1 approach is similar to what I do at work except for the part where you use
'<handler-chains xmlns="http://www.bea.com/xml/ns/jws">' from your SimpleChain.xml. I'm not sure if that is a requirement for you because you are using Oracle/BEA server? But that seems to be where the validation error is coming from (quoted below and in bold). Can you try changing this to '<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">' and see if that works? )

But it is still giving me below error:

[jwsc] C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServic
eGateway\src\com\cvs\rxconnect\resi\EnterprisePatientServicePortImpl.java 60:8
[jwsc] [ERROR] - javax.jws.WebService.endpointInterface com.cvs.rxconnect.r
esi.EnterprisePatientServicePort is invalid.
[jwsc] C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServic
eGateway\src\com\cvs\rxconnect\resi\EnterprisePatientServicePortImpl.java 60:8
[jwsc] [ERROR] - Handler chain file validation error for file: file:/C:/Doc
uments and Settings/njain2/Release10_Handlers_POC/RxCWebServiceGateway/src/com/c
vs/rxconnect/resi/SimpleChain.xml. C:\Documents and Settings\njain2\Release10_Ha
ndlers_POC\RxCWebServiceGateway\file:\C:\Documents and Settings\njain2\Release10
_Handlers_POC\RxCWebServiceGateway\src\com\cvs\rxconnect\resi\SimpleChain.xml:0:
error: The document is not a handler-config@http://www.bea.com/xml/ns/jws: docu
ment element mismatch got handler-chains@http://java.sun.com/xml/ns/javaee

[AntUtil.deleteDir] Deleting directory C:\DOCUME~1\njain2\LOCALS~1\Temp\_ha4pt

BUILD FAILED
C:\Documents and Settings\njain2\Release10_Handlers_POC\RxCWebServiceGateway\bui
ld.xml:160: weblogic.wsee.tools.WsBuildException: JWS Validation failed.

Total time: 28 seconds
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
Sorry, I'm running out of ideas. I did ask my friend google and the very first that came up that may possibly be related to your issue is this: https://forums.oracle.com/thread/902618

Good luck. I'd be interested to learn what you come up with as a fix.
Alna Jingan
Greenhorn

Joined: Jun 24, 2013
Posts: 19
Basic clustering with Weblogic 12c and Apache Web Server
http://blog.c2b2.co.uk/2012/10/basic-clustering-with-weblogic-12c-and.html
yashi jain
Greenhorn

Joined: Jun 28, 2013
Posts: 4
Hi Alna,

I've to implement this on weblogic server 9.2. anyways how is your suggestion help to resolve this validation error. How is clustering even related to this issue .

Thanks,
Yashi
Dennis Labajo
Greenhorn

Joined: Dec 12, 2009
Posts: 27
Alna Jingan wrote:Basic clustering with Weblogic 12c and Apache Web Server
http://blog.c2b2.co.uk/2012/10/basic-clustering-with-weblogic-12c-and.html


Hmmm, just curious... how does clustering solve the validation error? Or maybe, how is clustering even related to the issue at hand?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How can i extract SOAP XML from java web services stub.