Home > Mobile >  CXF Enabling GZIP failed at the WSDL loading
CXF Enabling GZIP failed at the WSDL loading

Time:02-11

I currently have a problem when trying to enable GZIP compression for CXF : the WSDL loading failed because it is compressed and the client part isn't decompressing it.

That means than when I'm doing the following :

persistenceService = Service.create(
                                new URL(replaceHostAndPort(
                                        getClientServiceConfiguration().getWsMetadataPersistenceService())),
                                new QName("http://metadata.ws.com", "WsMetadataPersistenceService"), gzipFeature);
                        mDefaultMetadataPersistence = persistenceService.getPort(IWsMetadataPersistence.class);

The code fail on the Service.create(), so it is not about configuring the ClientProxy.

As far as I could tell in the source code of CFX, the loading of the WSDL doesn't use the feature that I passed on in paramters, neither those that i passed on the default bus using the following configuration :

<bean id="compressGZIPFeature" /> 
<cxf:bus>
    <cxf:features>
         <ref bean="compressGZIPFeature"/>        
    </cxf:features>
</cxf:bus> 

Note : I can see in the instance of bus used by the CXF internal classes that use the bus element, that my feature is there and was propertly initialized (adding in/out interceptors), however I never pass with them when trying to load the WSDL file.

Now I'am a bit stuck : is the WSDL supposed to not be gzipped in the first place ? Then how come it was, or is my problem on the client side ?

On the server side I tried various combinaison of what I could find hoping to only compressed the content of request and not the WSDL to no avail :

  • @GZIP
  • XML Bus configuration
  • @In/OutInterceptors

Form what I understood on the client code of CXF, the InputStream from the HttpUrlConnection is directly handed to the XMLReader to read the WSDL, without using the interceptors (also, the GZIPInterceptor ignore message coming from a GET requests so it should ignore the GET [...]?wsdl aniway. See WSDLManagerImpl.loadDefinition() if you want to check the code.

I'am not sure if it is relevant, I'm under adopte-openjdk 8 and cxf 3.1.7.

CodePudding user response:

I found the solution : I added the compression on the HTTP Conduit, which would make even wsdl request request for GZIP version. The problem is that the WSDL reader doesn't handle the GZIP stream received.

So I had to remove the compression configuration on the client side and use the following code to make sure only SOAP request would be compressed :

public <T> T createAndConfigureService(Class<? extends T> theServiceClass, Service service){
    T theWebService = service.getPort(theServiceClass);
    Map<String, Object> requestHeaders = new HashMap<>();
    requestHeaders.put("Accept-Encoding", new ArrayList<>(Arrays.asList("gzip")));
    ((BindingProvider)theWebService).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
    Client client = ClientProxy.getClient(theWebService); 
    client.getInInterceptors().add(new GZIPInInterceptor());
    return theWebService;
}
  • Related