trying to access SOAP Header in interceptor of cxfse

View: New views
4 Messages — Rating Filter:   Alert me  

trying to access SOAP Header in interceptor of cxfse

by Lowry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Originally posted to servicemix-dev, reposting here...

I've deployed a cxfbc/cxfse to handle incoming web service requests. I'd like to configure a CXF Interceptor to access the SOAP Header of the incoming request.
When configured as an inInterceptor on cxfse:endpoint and run inside servicemix, the header obtained from getHeaders() is null.
I've included source for interceptor along with cxf-se xbean.xml.
I have not specified anything inside WSDL to indicate a SOAP Header is required/optional. Is it required that i specify SOAP Header in WSDL?
Thanks,
-Lowry


// here is interceptor source

public class SoapHeaderAuthorizationHandler extends AbstractPhaseInterceptor<SoapMessage>{

        public SoapHeaderAuthorizationHandler(){
                super(Phase.PRE_PROTOCOL);
        }
       
        public void handleMessage(SoapMessage message) throws Fault {
                List<Header> headers = message.getHeaders();
                for(Header header : headers){
                        System.err.println("header : "+header.getName());
                }
        }
}


// Here is bean.xml from cxf-se

<beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0">

        <cxfse:endpoint useJBIWrapper="false">
                <cxfse:pojo>
                        <bean class="org.apache.servicemix.samples.wsdl_first.PersonImpl" />
                </cxfse:pojo>
                <cxfse:inInterceptors>
                        <bean class="org.apache.servicemix.samples.wsdl_first.interceptors.SoapHeaderAuthorizationHandler" />
                </cxfse:inInterceptors>
        </cxfse:endpoint>
</beans>
 

Re: trying to access SOAP Header in interceptor of cxfse

by Lowry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tried a few more things and found that if i add the inInterceptor to the cxfbc rather than to the cxfse then i can get values from SOAP header. The trip through the NMR between cxfbc<-->cxfse seems to remove the SOAP headers (or at least relocate them.) Anyone know where the SOAP header can be found in a cxfse inInterceptor, along with code for exctracting?
Thanks,
-Lowry


Lowry wrote:
Originally posted to servicemix-dev, reposting here...

I've deployed a cxfbc/cxfse to handle incoming web service requests. I'd like to configure a CXF Interceptor to access the SOAP Header of the incoming request.
When configured as an inInterceptor on cxfse:endpoint and run inside servicemix, the header obtained from getHeaders() is null.
I've included source for interceptor along with cxf-se xbean.xml.
I have not specified anything inside WSDL to indicate a SOAP Header is required/optional. Is it required that i specify SOAP Header in WSDL?
Thanks,
-Lowry


// here is interceptor source

public class SoapHeaderAuthorizationHandler extends AbstractPhaseInterceptor<SoapMessage>{

        public SoapHeaderAuthorizationHandler(){
                super(Phase.PRE_PROTOCOL);
        }
       
        public void handleMessage(SoapMessage message) throws Fault {
                List<Header> headers = message.getHeaders();
                for(Header header : headers){
                        System.err.println("header : "+header.getName());
                }
        }
}


// Here is bean.xml from cxf-se

<beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0">

        <cxfse:endpoint useJBIWrapper="false">
                <cxfse:pojo>
                        <bean class="org.apache.servicemix.samples.wsdl_first.PersonImpl" />
                </cxfse:pojo>
                <cxfse:inInterceptors>
                        <bean class="org.apache.servicemix.samples.wsdl_first.interceptors.SoapHeaderAuthorizationHandler" />
                </cxfse:inInterceptors>
        </cxfse:endpoint>
</beans>
 

Re: trying to access SOAP Header in interceptor of cxfse

by Lowry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks to some help from Freeman Fang, I was able to access the SOAP Header inside my CXF SE interceptor using the following interceptor code:

public void handleMessage(Message message) throws Fault {

   System.out.println("Entered SoapHeaderAuthorizationHandler.");
   Map<String, Object> headers = new HashMap<String, Object>();
   headers = (Map<String, Object>)message.get("javax.jbi.messaging.protocol.headers");

        for(String key : headers.keySet()){
                System.err.println("header : " + headers.get(key) + "with key : " + key);
                Element domElement = (Element)headers.get(key);
                System.err.println("node value = " + domElement.getFirstChild().getNodeValue());
        }
}


Notice how the above code assumes SOAP header has been copied into message exchange header by servicemix. Would prefer a more generic interceptor code that is not tied to JBI and uses SoapMessage.
Here is the configuration for my cxf se in xbean.xml (Note no use of useJBIWrapper="false"):
     
<cxfbc:consumer wsdl="samples/wsdl_first/interceptors/person.wsdl"
                      targetService="person:PersonService"
                      targetInterface="person:Person">
                <cxfbc:inInterceptors>
  <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
 
  </cxfbc:inInterceptors>
      </cxfbc:consumer>
 
Thanks,
-Lowry

Tried a few more things and found that if i add the inInterceptor to the cxfbc rather than to the cxfse then i can get values from SOAP header. The trip through the NMR between cxfbc<-->cxfse seems to remove the SOAP headers (or at least relocate them.) Anyone know where the SOAP header can be found in a cxfse inInterceptor, along with code for exctracting?
Thanks,
-Lowry


Lowry wrote:
Originally posted to servicemix-dev, reposting here...

I've deployed a cxfbc/cxfse to handle incoming web service requests. I'd like to configure a CXF Interceptor to access the SOAP Header of the incoming request.
When configured as an inInterceptor on cxfse:endpoint and run inside servicemix, the header obtained from getHeaders() is null.
I've included source for interceptor along with cxf-se xbean.xml.
I have not specified anything inside WSDL to indicate a SOAP Header is required/optional. Is it required that i specify SOAP Header in WSDL?
Thanks,
-Lowry


// here is interceptor source

public class SoapHeaderAuthorizationHandler extends AbstractPhaseInterceptor<SoapMessage>{

        public SoapHeaderAuthorizationHandler(){
                super(Phase.PRE_PROTOCOL);
        }
       
        public void handleMessage(SoapMessage message) throws Fault {
                List<Header> headers = message.getHeaders();
                for(Header header : headers){
                        System.err.println("header : "+header.getName());
                }
        }
}


// Here is bean.xml from cxf-se

<beans xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0">

        <cxfse:endpoint useJBIWrapper="false">
                <cxfse:pojo>
                        <bean class="org.apache.servicemix.samples.wsdl_first.PersonImpl" />
                </cxfse:pojo>
                <cxfse:inInterceptors>
                        <bean class="org.apache.servicemix.samples.wsdl_first.interceptors.SoapHeaderAuthorizationHandler" />
                </cxfse:inInterceptors>
        </cxfse:endpoint>
</beans>
 


Re: trying to access SOAP Header in interceptor of cxfse

by Lowry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Further feedback from Freeman..

>>
>> Hi Lowry,
>>
>> Inside JBI container, the message must follow the JBI style, so there's
>> no way you can access the header using SoapMessage style, even you add
>> useJBIWrapper="false", the message is not SoapMessage, it's still JBI
>> style message, just the payload has soap envelope, you have to use the
>> way I show to access the header.

[lowry] In cxf-se, if soap envelope is in payload of jbi exchange, will it not contain the SOAP Header? We could then parse this payload to get the header value. Seems however, the SOAP Header is not included in the soap envelope inside the payload at the cxf SE. Therefore using the property of exchange is the only option. Is the correct?

[freeman] Yeah, the SOAP Header is not included in the soap envelope inside the payload, using the property of exchange is the only option. As we already process and save the soap headers as property and we don't want to the payload to carry duplicated infos here.
IMHO, get soap headers from property is more easy than parse it from the payload.