Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapAction header missing when using CXF

I have a WSDL file from outside WS that i'm connecting to. And I'm trying to get it working with CXF (works fine with JAX-WS). But I'm getting error from other system. So I decided to take a look at data we're sending to that system and only diffrence is that CXF sets empty SOAPAction http header.

I took some reading and looks like only known solutions is pointing to WSDL directly. But I already did that.

Anyone has a clue about this?

<bean id="object" class="xxx.XxxObject" factory-bean="objectFActory"
      factory-method="create"/>

<bean id="objectFActory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
    <property name="serviceClass" value="xxx.XxxObject"/>
    <property name="wsdlLocation" value="http://blebleble"/>
    <property name="address" value="http://blebleble"/>
    <property name="username" value="user"/>
    <property name="password" value="password"/>
    <property name="properties">
        <map>
            <entry key="javax.xml.ws.session.maintain" value-type="java.lang.Boolean" value="true"/>
        </map>
    </property>
</bean>

Headers:

POST /somepath HTTP/1.1
Content-Type: text/xml; charset=UTF-8
Accept: */*
Authorization: Basic <randomhex>
SOAPAction: ""
User-Agent: Apache CXF 2.7.6
Cache-Control: no-cache
Pragma: no-cache
Host: somehost:8080
Connection: keep-alive
Content-Length: 2791
like image 404
mihn Avatar asked Aug 01 '13 07:08

mihn


2 Answers

None of this is CXF specific. It is all standard JAX-WS.

You can use the action property of the @WebMethod annotation to set a SOAP action. For example

@WebMethod(operationName = "TestOperation", action="http://example.org/TestOperation")

If you are using wsimport to generate artifacts from the WSDL, you should already have this set in your @WebService annotated interface.

like image 191
Patrick Avatar answered Oct 07 '22 08:10

Patrick


I was able to replicate the behavior you described (SOAPAction header is "") using an invocation like this:

MyPortService service = new MyPortService();
MyPort port = service.getMyPortSoap11();
MyRequest request = new MyRequest();
MyResponse response = port.subscription( request );

Here are the HTTP Headers from TCP Dump using this invocation:

POST /MyService/services HTTP/1.1
Content-Type: text/xml; charset=UTF-8
Accept: */*
SOAPAction: ""
User-Agent: Apache CXF 2.7.6
Cache-Control: no-cache
Pragma: no-cache
Host: redacted
Connection: keep-alive
Content-Length: 377

I tried adding an out interceptor and ensuring that the SOAPAction was set as a header, but no matter what I tried that did not cause the SOAPAction to be sent as part of the HTTP request.

I then found a lead in this thread and reformatted my invocation:

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass( MyPort.class );
factory.setAddress( "http://www.host.com/service" );
factory.setServiceName( new QName( targetNamespace, wsdlBindingName ) );
Object myService = factory.create();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient( myService );
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("SOAPAction", Arrays.asList("mySoapAction"));
client.getRequestContext().put(Message.PROTOCOL_HEADERS, headers);
client.invoke( operationName, request );

Here are the HTTP Headers from TCP Dump of an invocation in this style:

POST /MyService/services HTTP/1.1
Content-Type: text/xml; charset=UTF-8
Accept: */*
SOAPAction: mySoapAction
User-Agent: Apache CXF 2.7.6
Cache-Control: no-cache
Pragma: no-cache
Host: redacted
Connection: keep-alive
Content-Length: 377

Hope this helps.

like image 34
Alex Avatar answered Oct 07 '22 10:10

Alex