All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.stub.ksoap.httptransportsewithzzip.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/generic.include.vm")
#parse("${include}/webclient.ksoap.include.vm")
#set ( $className                ="$C_GZIPHTTPTRANSPORT")
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
package $pkg;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.Proxy;
import java.util.zip.GZIPOutputStream;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.ksoap2.transport.ServiceConnection;

/**
 * 实现Gzip压缩发送请求
* {@link #compress}为true时发送数据前先压缩数据 * @author guyadong * */ public class HttpTransportSEWithGzip extends HttpTransportSE { /** * 是否启用GZIP压缩 */ public boolean compress=true; public HttpTransportSEWithGzip(String url) { super(url); } public HttpTransportSEWithGzip(Proxy proxy, String url) { super(proxy, url); } public HttpTransportSEWithGzip(String url, int timeout) { super(url, timeout); } public HttpTransportSEWithGzip(Proxy proxy, String url, int timeout) { super(proxy, url, timeout); } public HttpTransportSEWithGzip(String url, int timeout, int contentLength) { super(url, timeout, contentLength); } public HttpTransportSEWithGzip(Proxy proxy, String url, int timeout, int contentLength) { super(proxy, url, timeout, contentLength); } @Override protected void sendData(byte[] requestData, ServiceConnection connection, SoapEnvelope envelope) throws IOException { if (this.compress) { // 将数据压缩 ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(1024); GZIPOutputStream os = null; try { os = new GZIPOutputStream(arrayOutputStream); os.write(requestData, 0, requestData.length); os.finish(); } finally { if (null != os) os.close(); } connection.setRequestProperty("Content-Encoding", "gzip"); requestData = arrayOutputStream.toByteArray(); } super.sendData(requestData, connection, envelope); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy