rjsang
rjsang

Reputation: 1757

CXF 2.7.7 org.apache.cxf.interceptor.Fault: Unexpected element

I am experiencing an error I cannot understand since upgrading to CXF 2.7.7. When making a web service call CXF is reporting this exception:

org.apache.cxf.interceptor.Fault: 
Unexpected element {http://schema.myorg.com/GetReference/}ReferenceResponse found.
Expected {http://services.myorg.com/}getReferences

This makes no sense, because ReferenceResponse is exactly the response I expect. The name getReferences appears to refer to the name of the @WebMethod annotated method that is being called. The return type of this method is ReferenceResponse.

What am I missing?

Upvotes: 6

Views: 8880

Answers (3)

spy
spy

Reputation: 3258

I just had this happen by adding a custom http header in my app code, specifically http keep alive. The ws client http was reused and it looks like cxf was not reseting the soap action header on subsequent calls.

Upvotes: 0

Kirill
Kirill

Reputation: 6016

I have resolved the issue when found that my SOAPLoggingHandler by default returns false in its methods. It should be changed to true:

public class SOAPLoggingHandler implements SOAPHandler<SOAPMessageContext> {
    @Override
    public Set<QName> getHeaders() {
        return null;
    }

    @Override
    public boolean handleMessage(SOAPMessageContext context) {
        SOAPMessage message= context.getMessage();
        boolean isOutboundMessage = (Boolean)context.get (MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if(isOutboundMessage){
            System.out.println("OUTBOUND MESSAGE\n");

        }else{
            System.out.println("INBOUND MESSAGE\n");
        }
        try {
            message.writeTo(System.out);
        } catch (SOAPException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return true;

    }

    @Override
    public boolean handleFault(SOAPMessageContext context) {
        SOAPMessage message= context.getMessage();
        try {
            message.writeTo(System.out);
        } catch (SOAPException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    }

    @Override
    public void close(MessageContext context) { }
}

Upvotes: 1

rjsang
rjsang

Reputation: 1757

I never found a truly satisfactory answer to this, but, it was solved when I replaced the existing client interface with one generated by wsdl2cxf. This also involved migrating from Xbeans to JAXB for marshaling, which may have had something to do with it.

However, in the interim adding the following annotation to the interface prevented the error.

@EndpointProperty(key = "soap.no.validate.parts", value = "true")

Upvotes: 4

Related Questions