AXIS2调用web service,返回结果用GZIP解压缩

时间:2024-05-02 12:38:02
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream; import javax.xml.namespace.QName; import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient; public class Test3 { public static void main(String[] args) throws IOException {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetRPR = new EndpointReference(
"http://..../LoginWebService.asmx");
options.setTo(targetRPR);
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
//参数
Object[] opArgs = new Object[]{"test", "123456"};
QName opEntry = new QName("http://tempuri.org/", "doctorLogin", "ns1");
byte[] gzpdata = (byte[])serviceClient.invokeBlocking(opEntry, opArgs, new Class[]{byte[].class})[0];//第三个参数为返回类型,保存为字节数组 GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(gzpdata));
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[256];
int n;
while ((n = gzip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
System.out.println(out.toString());
}
}