Access to web method parameters in JAX-WS SOAP handler? - java

I've developed a SOAP web service with Java7 and JAX-WS. This is an excerpt of the interface:
#WebService(name = "MyWebService",
targetNamespace = "http://www.something.com")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface MyWebServiceInterface
{
#WebMethod(operationName = "handleMsg",
action = "handleMsg")
#Oneway
void handleMsg(#WebParam(name = "MessageHeader",
targetNamespace = "http://www.something.com",
header = true,
partName = "header")
MessageHeader header,
#WebParam(name = "MessageBody",
targetNamespace = "http://www.soemthing.com",
partName = "body")
MessageType body);
}
I've implemented a custom SOAP handler for this web service (it work's fine) to do some additional stuff. In the method handleFault(..) I need to access the original MessageHeader of the web method (see interface above). How can this be done?
public class MyHandler implements SOAPHandler<SOAPMessageContext>
{
// ...
#Override
public boolean handleFault(final SOAPMessageContext context)
{
final Boolean outbound =
( Boolean ) context.get( MessageContext.MESSAGE_OUTBOUND_PROPERTY );
// handle only incoming message which do have a message set
if ( outbound != null && !outbound.booleanValue() && context.getMessage() != null )
{
MessageHeader header =
getOriginalHeaderOfFautlyMessage(); // <-- how can this be done?
}
}
}

SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
Then you will have to extract your header node and unmarshall it.

Related

WSDL Client Calling Failed

First time working on SOAP services. I need to call this web service. http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL
Here are the 2 out of 11 of the stubs that i have generated using wsimport
I tried for the whole day, but I keep getting this error message. Why? I suspect because i did not pass in the authentication header correctly. But at the same time i'm wondering how come the generated stub does not comes with Authentication header as a method param? is that normal? Need help. I'm so confusing.
Exception in thread "main"
com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client
received SOAP Fault from server: Server was unable to process request.
---> Object reference not set to an instance of an object. Please see the server log to find more detail regarding exact cause of the
failure.
WebLITETSServicesSoap.java
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
#WebService(name = "WebLITE_TSServicesSoap", targetNamespace = "TransactionalSubmissionsSvcs")
#XmlSeeAlso({
ObjectFactory.class
})
public interface WebLITETSServicesSoap {
#WebMethod(operationName = "GetTemplateList", action = "TransactionalSubmissionsSvcs/GetTemplateList")
#WebResult(name = "GetTemplateListResult", targetNamespace = "TransactionalSubmissionsSvcs")
#RequestWrapper(localName = "GetTemplateList", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateList")
#ResponseWrapper(localName = "GetTemplateListResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateListResponse")
public String getTemplateList();
#WebMethod(operationName = "SendWithXML", action = "TransactionalSubmissionsSvcs/SendWithXML")
#WebResult(name = "SendWithXMLResult", targetNamespace = "TransactionalSubmissionsSvcs")
#RequestWrapper(localName = "SendWithXML", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXML")
#ResponseWrapper(localName = "SendWithXMLResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXMLResponse")
public String sendWithXML(
#WebParam(name = "xmldoc", targetNamespace = "TransactionalSubmissionsSvcs")
SendWithXML.Xmldoc xmldoc);
#WebMethod(operationName = "SendWithJSON", action = "TransactionalSubmissionsSvcs/SendWithJSON")
#WebResult(name = "SendWithJSONResult", targetNamespace = "TransactionalSubmissionsSvcs")
#RequestWrapper(localName = "SendWithJSON", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSON")
#ResponseWrapper(localName = "SendWithJSONResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSONResponse")
public String sendWithJSON(
#WebParam(name = "emaillist", targetNamespace = "TransactionalSubmissionsSvcs")
String emaillist,
#WebParam(name = "params", targetNamespace = "TransactionalSubmissionsSvcs")
String params);
}
WebLITETSServices.java
import javax.xml.namespace.QName;
import javax.xml.ws.*;
import java.net.MalformedURLException;
import java.net.URL;
#WebServiceClient(name = "WebLITE_TSServices", targetNamespace = "TransactionalSubmissionsSvcs", wsdlLocation = "http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL")
public class WebLITETSServices
extends Service
{
private final static URL WEBLITETSSERVICES_WSDL_LOCATION;
private final static WebServiceException WEBLITETSSERVICES_EXCEPTION;
private final static QName WEBLITETSSERVICES_QNAME = new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServices");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
WEBLITETSSERVICES_WSDL_LOCATION = url;
WEBLITETSSERVICES_EXCEPTION = e;
}
public WebLITETSServices() {
super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME);
}
public WebLITETSServices(WebServiceFeature... features) {
super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME, features);
}
public WebLITETSServices(URL wsdlLocation) {
super(wsdlLocation, WEBLITETSSERVICES_QNAME);
}
public WebLITETSServices(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, WEBLITETSSERVICES_QNAME, features);
}
public WebLITETSServices(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public WebLITETSServices(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
#WebEndpoint(name = "WebLITE_TSServicesSoap")
public WebLITETSServicesSoap getWebLITETSServicesSoap() {
return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class);
}
#WebEndpoint(name = "WebLITE_TSServicesSoap")
public WebLITETSServicesSoap getWebLITETSServicesSoap(WebServiceFeature... features) {
return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class, features);
}
private static URL __getWsdlLocation() {
if (WEBLITETSSERVICES_EXCEPTION!= null) {
throw WEBLITETSSERVICES_EXCEPTION;
}
return WEBLITETSSERVICES_WSDL_LOCATION;
}
}
I tried running with TestApplication
public class TestApplication {
public static void main(String[] args) throws MalformedURLException {
MailAdapterApplication adapterApplication = new MailAdapterApplication();
adapterApplication.run();
}
public void run() throws MalformedURLException {
WebLITETSServices services = new WebLITETSServices();
WebLITETSServicesSoap servicesSoap = services.getPort(WebLITETSServicesSoap.class);
Map<String, Object> req_ctx =((BindingProvider)servicesSoap).getRequestContext();
Map<String, List<String>> headers = new HashMap<>();
headers.put("Username",Collections.singletonList("sansun#weblite.com.my"));
headers.put("Password", Collections.singletonList("P#ssW0rd32!"));
headers.put("APIKey", Collections.singletonList("QdrLKxog"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
System.out.println(servicesSoap.getTemplateList());
}
}
Client received SOAP Fault from server: Server was unable to process request.
Object reference not set to an instance of an object.
I keep getting this error message. Why?
Indeed you did call the service, but the server returned an error code with error message, where the returned payload has no mapping to any expected return type or soap fault exception. There is no more information in the in the text you've provided.
It would be really usefull to check the response status code and payload which was really returned. How to log the respone payload depends on the webservice library you use (cxf, axis2, ??)
I suspect because i did not pass in the authentication header correctly.
You should confirm that suspission, from the information provided it is not possible to tell. Though if you did not provide any authentication information, it is very possible
But at the same time i'm wondering how come the generated stub does not comes with Authentication header as a method param? is that normal? Need help. I'm so confusing.
I assume under the "Authentication header" you mean AuthHeader header. You may need to enable header generation when invoking the wsimport, as well depends in th framework used. When using wsimport from the default JDK, try to use -XadditionalHeaders parameter

Reverse engineering: How to generate SOAP Request XML in the backend?

I have the following classes:
WS Interface:
package com.mypackage;
import javax.ejb.Remote;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
#Remote
#SOAPBinding(style = Style.DOCUMENT)
#WebService(name = "MathService", targetNamespace = "http://mypackage.com/")
public interface MathServiceWS {
#WebResult(name = "result", targetNamespace = "http://mypackage.com/")
#RequestWrapper(localName = "addRequest", className = "AddRequest", targetNamespace = "http://mypackage.com/")
#WebMethod(action = "http://mypackage.com/add", operationName = "add")
#ResponseWrapper(localName = "addResponse", className = "AddResponse", targetNamespace = "http://mypackage.com/")
Long add(#WebParam(name = "add", targetNamespace = "http://mypackage.com/") AddBean add);
}
WS Implementation:
package com.mypackage;
import javax.ejb.Stateless;
import javax.jws.WebService;
#Stateless(mappedName = "MathService")
#WebService(serviceName = "MathService", endpointInterface = "com.mypackage.MathServiceWS", portName = "MathServicePort", targetNamespace = "http://mypackage.com/")
public class MathService implements MathServiceWS {
#Override
public Long add(AddBean add) {
Long first = new Long(add.getFirst().intValue());
Long second = new Long(add.getSecond().intValue());
return Long.valueOf(Math.addExact(first.longValue(), second.longValue()));
}
}
The bean:
package com.mypackage;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(
name = "Add",
namespace = "http://mypackage.com/",
propOrder = {
"first",
"second"
}
)
public class AddBean implements Serializable {
private static final long serialVersionUID = -7727938355039425419L;
#XmlElement(required = true)
private Integer first;
#XmlElement(required = true)
private Integer second;
public AddBean() {
}
public Integer getFirst() {
return first;
}
public void setFirst(Integer first) {
this.first = first;
}
public Integer getSecond() {
return second;
}
public void setSecond(Integer second) {
this.second = second;
}
}
After deploying this WS, when I'm adding the WSDL in SoapUI, the add method request is as follows after giving the user input:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:myp="http://mypackage.com/">
<soapenv:Header/>
<soapenv:Body>
<myp:addRequest>
<myp:add>
<first>1</first>
<second>2</second>
</myp:add>
</myp:addRequest>
</soapenv:Body>
</soapenv:Envelope>
Now I want to have the above SOAP request XML in my com.mypackage.MathService.add(AddBean) method with the given user input.
Using JAXB on com.mypackage.AddBean only generates partial request
The WebService Handlers is not useful to fulfill my requirement
Any pointer would be very helpful.
You may create an custom SOAPHandler object and can read the request payload and set it to SOAPMessageContext via custom property. Make sure you set the scope as application.
In your service class, inject the javax.xml.ws.WebServiceContext using #javax.annotation.Resource and access payload set via your custom property.
For example:
1. Create Handler and register it.
public class PopulateSOAPMessagePayloadHandler implements SOAPHandler<SOAPMessageContext> {
public static final String SOAP_MESSAGE_PAYLOAD = "__soap_message_payload";
#Override
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outboundProperty.booleanValue()) {
// for incoming:
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
try {
smc.getMessage().writeTo(bout);
String payload = bout.toString(StandardCharsets.UTF_8.name());
smc.put(SOAP_MESSAGE_PAYLOAD, payload); //Set payload
smc.setScope(SOAP_MESSAGE_PAYLOAD, MessageContext.Scope.APPLICATION); //make it application scope
} catch (SOAPException | IOException e) {
e.printStackTrace();
// handle exception if needed
throw new WebServiceException(e);
}
}
return true;
}
// Other method (no-op) omitted
}
2. Get the payload
public class MathService implements MathServiceWS {
#Resource
private WebServiceContext context;
#Override
public Long add(AddBean add) {
String payload = (String) context.getMessageContext().get(SOAP_MESSAGE_PAYLOAD);
Long first = new Long(add.getFirst().intValue());
Long second = new Long(add.getSecond().intValue());
return Long.valueOf(Math.addExact(first.longValue(), second.longValue()));
}
}
Hope it helps.
You can get full control of the document easily. First lets setup the bean:
#XmlRootElement(name="addRequest")
#XmlAccessorType(XmlAccessType.FIELD) //Probably you don't need this line. it is by default field accessible.
public class AddBean implements Serializable {
private static final long serialVersionUID = -7727938355039425419L;
#XmlElement(name="first",required = true) //you don't need name attribute as field is already exactly the same as soap element
private Integer first;
#XmlElement(name="second",required = true) //you don't need name attribute as field is already exactly the same as soap element
private Integer second;
public AddBean() { }
//Getters and Setters
}
Now, I think this is the part you are looking for. To add custom namespace declarations and set prefix etc. If you are using org.springframework.ws.client.core.support.WebServiceGatewaySupport.getWebServiceTemplate to make SOAP request, then you can do the following:
public class WSCastorClient extends WebServiceGatewaySupport {
public CustomResponseObject callWebService(Addbean add) {
WebServiceTemplate wst = getWebServiceTemplate();
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.afterPropertiesSet();
wst.setMarshaller(marshaller);
wst.setUnmarshaller(marshaller);
wst.afterPropertiesSet();
CustomResponseObject response = (CustomResponseObject)
wst.marshallSendAndReceive(add, new
WebServiceMessageCallback() {
public void doWithMessage(WebServiceMessage message) {
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
SOAPMesage soapMEssage = saajSoapMessage.getSaajMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPHeader head = soapMessage.getSOAPHeader();
SOAPBody soapBody = soapMessage.getSOAPBody();
//Now you have full control of the soap header, body, envelope. You can add any namespace declaration, prefix, add header element, etc. You can add remove whatever you want.
soapEnvelope.removeNamespaceDeclaration(soapEnvelope.getPrefix()); //clear whatever namespace is there
soapEnvelope.addNamespaceDeclaration("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
soapEnvelope.addNamespaceDeclaration("myp", "http://mypackage.com/");
soapEnvelope.setPrefix("soapenv");
soapHeader.setPrefix("soapenv");
soapBody.setPrefix("soapenv");
Document doc = saajSoapMessage.getDocument();
StringWriter sw = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult(sw));
}
});
return response;
}
//close off other brackets if I forgot any.

remove a tag in soap response using CXF

I am new to CXF. I am using CXF component in mulesoft to create Webservice. WebService is running successfully. But, I want to remove a tag from response.
I have used #ResponseWrapper, #SoapBinding(ParameterStyle=ParameterStyle.BARE). but, these are not resolved my issue.
I have heared that, we can modify soap response(i.e remove tag) by using Outintercepters. If it is can anybody help me to how to use interceptors and what phase we can modify the soap response to remove tag..
Actual Soap Response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<soap:Body>
<ns2:getMyresponse xmlns:ns2="http://myschema.com">
<return>
<errorcode>1</errorcode>
<errormsg>notsuccesful</errorms>
</return>
</ns2:getMyresponse>
</soap:Body>
</soap:Evelope>
Expected Response
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<soap:Body>
<ns2:getMyresponse xmlns:ns2="http://myschema.com">
<errorcode>1</errorcode>
<errormsg>notsuccesful</errorms>
</ns2:getMyresponse>
</soap:Body>
</soap:Evelope>
SEI class is:
#WebService(targetNamespace = "urn:com.test", name = "GetActivityListInterface")
public interface GetActivityListInterface {
#SOAPBinding(parameterStyle = ParameterStyle.BARE)
#RequestWrapper(localName = "GetMyActivities", targetNamespace = "urn:com.test", className = "com.test.beans.MyActivities")
#WebMethod(operationName = "GetMyActivities", action = "urn:com.test/GetMyActivities")
#ResponseWrapper(localName = "GetMyResponse", targetNamespace = "urn:com.test", className = "com.test.beans.GetMyResponse")
public GetMyActivitiesResponse getMyActivities(
#WebParam(name = "id", partName="id")
java.lang.String id,
#WebParam(name = "date", partName="date")
java.lang.String date);
}
Use an XSL-T to remove the tags that you want to remove from response xml.
Cheers!
Remove the #ResponseWrapper and use #WebResult. Like this
#WebService(targetNamespace = "urn:com.test", name = "GetActivityListInterface")
public interface GetActivityListInterface {
#SOAPBinding(parameterStyle = ParameterStyle.BARE)
#RequestWrapper(localName = "GetMyActivities", targetNamespace = "urn:com.test", className = "com.test.beans.MyActivities")
#WebMethod(operationName = "GetMyActivities", action = "urn:com.test/GetMyActivities")
#WebResult(name = "GetMyResponse", partName="GetMyResponse", targetNamespace = "urn:com.test")
public GetMyActivitiesResponse getMyActivities(
#WebParam(name = "id", partName="id")
java.lang.String id,
#WebParam(name = "date", partName="date")
java.lang.String date);
}

Registering soap handler at client side using java

public class MySoapHandler implements SOAPHandler<SOAPMessageContext> {
#Override
public boolean handleMessage(SOAPMessageContext context) {
Map<String, String> prop = Client.getProperties();
System.out.println("Client : handleMessage()......");
Boolean isRequest = (Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage message = context.getMessage();
// if this is a request, true for outbound messages, false for inbound
if (isRequest) {
try {
}
}
}
...
...
}
in my main class , from where i send soap request contains code to register the handler:
QName portName = new QName("MySoapHandler");
HandlerRegistry registry =
service.getHandlerRegistry(); List handlerList = new ArrayList();
handlerList.add(new HandlerInfo(MySoapHandler.class, null,
null)); registry.setHandlerChain(portName, handlerList);
It is not working . What should i do? I have got a legacy code to work upon. I am unable to understand how to do it.
I'll suggest to use WebServiceInterface.
Please refer this link for more detail : http://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-soap-handler-example/
I was able to register my client-side handler programmically using this code:
MyWebServicePortType myWebServicePortType
= service.getPort(MyWebServicePortType.class);
Binding binding = ((BindingProvider)myWebServicePortType).getBinding();
List<Handler> handlerList = binding.getHandlerChain();
handlerList.add(new MySoapHandler());
binding.setHandlerChain(handlerList);
I found this method at
https://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv/handlers.html#wp267318

How to get SOAP headers

Here is the request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://soap.ws.server.wst.fit.cvut.cz/">
<soapenv:Header>
<userId>someId</userId>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
and I want to get that userId.
I tried this
private List<Header> getHeaders() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
return CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
}
private String getHeader(String name) {
List<Header> headers = getHeaders();
if (headers != null) {
for (Header header : headers) {
logger.debug(header.getObject());
// return header by the given name
}
}
return null;
}
And it logs [userId : null]. How can I get the value and why is null there?
"[userId : null]" is generally the "toString" printout of a DOM element. Most likely if you do something like
logger.debug(header.getObject().getClass())
you will see that it is a DOM Element subclass of somesort. Thus, something like:
logger.debug(((Element)header.getObject()).getTextContent())
might print the text node.
import javax.xml.soap.*;
SOAPPart part = request.getSOAPPart();
SOAPEnvelope env = part.getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
// Throw an exception
}
NodeList userIdNode = header.getElementsByTagNameNS("*", "userId");
String userId = userIdNode.item(0).getChildNodes().item(0).getNodeValue();
You can get soap headers without Interceptors and without JAXB.
In your service_impl class add :
public class YourFunctionNameImpl implements YourFunctionName{
#Resource
private WebServiceContext context;
private List<Header> getHeaders() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
return headers;
}
...
Then in your function you can use:
List<Header> headers = getHeaders();
for(Iterator<Header> i = headers.iterator(); i.hasNext();) {
Header h = i.next();
Element n = (Element)h.getObject();
System.out.println("header name="+n.getLocalName());
System.out.println("header content="+n.getTextContent());
}
We can get SOAP header in server side by adding following code in CXF interceptor.
Create a class like
public class ServerCustomHeaderInterceptor extends AbstractSoapInterceptor {
#Resource
private WebServiceContext context;
public ServerCustomHeaderInterceptor() {
super(Phase.INVOKE);
}
#Override
public void handleMessage(SoapMessage message) throws Fault,JAXBException {
System.out.println("ServerCustomHeaderInterceptor handleMessage");
JAXBContext jc=null;
Unmarshaller unmarshaller=null;
try {
jc = JAXBContext.newInstance("org.example.hello_ws");
unmarshaller = jc.createUnmarshaller();
} catch (JAXBException e) {
e.printStackTrace();
}
List<Header> list = message.getHeaders();
for (Header header : list) {
ElementNSImpl el = (ElementNSImpl) header.getObject();
ParentNode pn= (ParentNode) el.getFirstChild();
//Node n1= (Node) pn;
//Node n1= (Node) el.getFirstChild();
CustomHeader customHeader=(CustomHeader) unmarshaller.unmarshal(el.getFirstChild());
}
}
After this we need to inject this as a interceptor like
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<bean class="org.example.hellows.soap12.ServerCustomHeaderInterceptor" />
</jaxws:inInterceptors>
in your server context xml.
We may need to change few lines as per your requirements. Basic flow will work like this.
Having a MessageContext messageContext, you can use this code:
HeaderList hl = (HeaderList) messageContext.get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
which gives you access to all SOAP headers.

Categories