简体   繁体   中英

How to enable GZIP compression for SOAP responses?

I created a simple soap webservice using Spring and CXF . I'm now trying to enable GZIP compression for the xml requests. The following will accept compressed requests, but will response uncompressed. Why?

@Component
@WebService
public class SoapService {

}

@Autowired
private SpringBus bus;


EndpointImpl end = new EndpointImpl(bus, new SoapService());
end.getFeatures().add(config.gzipFeature());
ep.publish("/SoapService");

Request to this SoapService:

Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml;charset=UTF-8
Headers: {accept-encoding=[gzip,deflate], content-encoding=[gzip], connection=[Keep-Alive], content-type=[text/xml;charset=UTF-8], ...}

Response (empty headers!!):

Content-Type: text/xml
Headers:
Payload: ...

Why is the response not compressed with gzip?

You need to add the @GZIP annotation to your interface. Here's the documentation . If I remember correctly you need to have GZIPOutInterceptor declared in your spring config.

Alternatively, you could add the GZIPOutInterceptor to your endpoint manually.

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