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

你离开我真会死。 提交于 2019-12-22 06:57:24

问题


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?


回答1:


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")



回答2:


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) { }
}



回答3:


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.



来源:https://stackoverflow.com/questions/19508437/cxf-2-7-7-org-apache-cxf-interceptor-fault-unexpected-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!