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

Lowry wrote:
> 
> 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> 
>>   
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/trying-to-access-SOAP-Header-in-interceptor-of-cxfse-tp25982977p26079385.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to