org.apache.axis2.AxisFault: Transport error: 411 Error: Length Required

本文介绍了一个Java客户端示例,该客户端使用Apache Axiom库来调用WebService服务。示例展示了如何构建请求参数、设置选项以及发送请求接收响应的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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会受限制,所以以上注释的地方必需加上,就可以访问了

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值