简体   繁体   中英

Disable FastInfoset (force XML) on Apache CXF when using the client

I need to force Apache CXF to send XML requests and handle only XML responses when I'm client and I have no control over the server or the configuration (I saw this but it only apply to the server). Right now it's always using FastInfoset which is great for performances but is causing some issue and I would like to be able to disable it but I didn't find much information on FastInfoset on the Internet and how should go about disabling it. Do you have any clues?

Thank you in advance for any help.

This is only possible if the remote server supports pure XML responses. Most of the servers which do support both Fastinfoset and pure XML are looking into Accept header from the request to decide in which format to return the response. So you can try to force the XML response by sending the Accept: application/xml header with each of your requests. For that you will need to create a CXF out interceptor and register it with your application.

Following Interceptor will always set Accept: application/xml

public class HttpHeaderInterceptor extends AbstractPhaseInterceptor<Message>{
    public XmlOnlyInterceptor() {
        super(Phase.POST_PROTOCOL);
    }
    @Override
    public void handleMessage(Message message) throws Fault {
        Map<String, List> headers = (Map<String, List>)message.get(Message.PROTOCOL_HEADERS);
        headers.put("Accept", Collections.singletonList("application/xml"));
    }
}

To register it use follwoing configuration

<jaxws:client id="clientBean" serviceClass="org.example.service.ServicePortType"
          address="example.org/src/service/ServicePort">
    <jaxws:outInterceptors>
        <bean class="org.example.interceptor.HttpHeaderInterceptor"/>
    </jaxws:outInterceptors>
</jaxws:client>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM