欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

org.apache.axis2.AxisFault: Transport error: 411 Error: Leng

程序员文章站 2022-05-16 20:38:53
...

package axiom; import java.util.Date; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; import org.apache.axiom.soap.SOAP11Cons

package axiom;

import java.util.Date;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;

public class WeatherAxiomClient {

private static EndpointReference targetEPR =
new EndpointReference(
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");

private static OMFactory fac = OMAbstractFactory.getOMFactory();

public static void main(String args[]) throws AxisFault{
Date start=new Date();
System.out.println("start:"+start);
ServiceClient sender = new ServiceClient();
sender.setOptions(buildOptions());
OMElement result = sender.sendReceive(buildParam());
System.out.println(result);
Date end=new Date();
System.out.println("end:"+end);
System.out.println("between:"+(end.getTime()-start.getTime()));
}
public static OMElement buildParam() {
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "tns");
OMElement data = fac.createOMElement("getSupportCity", omNs);
OMElement inner = fac.createOMElement("byProvinceName", omNs);
inner.setText("All");
data.addChild(inner);
return data;

}

public static Options buildOptions(){
Options options = new Options();
options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setAction("http://WebXml.com.cn/getSupportCity");
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
// options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
options.setProperty(HTTPConstants.PROXY, buildProxy());
return options;

}
public static ProxyProperties buildProxy(){
ProxyProperties proxyProperties=new ProxyProperties();
proxyProperties.setProxyName("172.19.18.22");
proxyProperties.setProxyPort(8080);
return proxyProperties;
}


}
点评:这里有一点要注意的是,当采用axiom进行服务端webservice调用时,http会受限制,所以以上注释的地方必需加上,就可以访问了