You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by cxf newbie <ca...@gmail.com> on 2013/10/23 11:39:15 UTC

CXF - SAAJInterceptor - SOAP envelope

Hi,

I need to have raw SOAP message envelope available in service implementation
class.
This SOAP envelope is then persisted in database.
At some time later there comes batch which process message by unmarshalling
it to objects using JiBX.
I know that I can intercept and persist SOAP message in some phase prior to
dispatch to implementation class. But I want CXF to do as most as possible
validations on incoming SOAP message because malformed messages need not be
persisted.

In implementation class I use:

@WebService(serviceName = "B2CDocumentWebService", endpointInterface="...)
@InInterceptors(interceptors = {"edoc.interceptors.ReadSOAPInInterceptor"})        
public class SendDocumentWSImpl extends SpringBeanAutowiringSupport...

@Resource
private WebServiceContext context;

...String someMethod() {...  
final MessageContext messageContext = context.getMessageContext();
final Message message = ((WrappedMessageContext)
messageContext).getWrappedMessage();
final SOAPMessageContextImpl smci = new SOAPMessageContextImpl(message);
final SOAPMessage sm = smci.getMessage();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
sm.writeTo(out);
return new String(out.toByteArray());
}...

Interceptor is:
public class ReadSOAPInInterceptor extends AbstractSoapInterceptor

private SAAJInInterceptor saajIn = new SAAJInInterceptor();

public ReadSOAPInInterceptor(){
    super(Phase.PRE_PROTOCOL);
    getAfter().add(SAAJInInterceptor.class.getName());
}
 
private SOAPMessage getSOAPMessage(SoapMessage smsg)
{
     SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);
     if (soapMessage == null) {
        saajIn.handleMessage(smsg);
        soapMessage = smsg.getContent(SOAPMessage.class);
     }
     return soapMessage;
}

WITHOUT interceptor engaged SOAP envelope only contains header and EMPTY
body tag.
Also, "message.getContentFormats()" returns only this:

[class org.apache.cxf.io.DelegatingInputStream, interface java.util.List,
interface javax.xml.stream.XMLStreamReader, class java.io.InputStream,
interface org.w3c.dom.Node]

WITH interceptor engaged, content formats list also includes "class
javax.xml.soap.SOAPMessage".

I suppose that SAAJInInterceptor somehow loads envelope and that is the
reason that I have envelope in implementation class.
 
Because I am newbie can you please explain me what happens and also what is
the right place to do business validations (eg. I have to validate supplier
by its ID).

Thank you. 
Sorry for my bad english.





--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-SAAJInterceptor-SOAP-envelope-tp5735434.html
Sent from the cxf-user mailing list archive at Nabble.com.