SOAPMessage - SOAPConnection - gzip - how to

2019-06-09 22:26发布

I need to use compression when sending SOAP requests and receiving responses from the WebService. Unfortunately I didn't find any references on how to enable GZIP compression. Here is the simple code I use to send the soap request:

SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

SOAPConnection sc = scf.createConnection();

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage message = mf.createMessage();

/*
.... some code
*/

URL url = new URL("https://blahblah/service/ws/Someservice");

SOAPMessage reply = sc.call(message, url);

Is there any way to enable the compression on the API level or will I have to wrap the SOAPMessage to implement compression myself?

标签: soap gzip
1条回答
冷血范
2楼-- · 2019-06-09 23:09
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();

SOAPConnection sc = scf.createConnection();

MessageFactory mf = MessageFactory.newInstance();

SOAPMessage message = mf.createMessage();

//************** HERE YOU DO THE GZIP********************************

MimeHeaders hd = message .getMimeHeaders();
hd.addHeader("Accept-Encoding", "gzip,deflate,sdch");

/*
.... some code
*/

URL url = new URL("https://blahblah/service/ws/Someservice");

SOAPMessage reply = sc.call(message, url);
查看更多
登录 后发表回答