第一次玩AXIS2,试过2种方式,一种是普通调用,一种是RPC调用,结果都一样。看了下代码也没发现访问方法有什么错误。错误代码如下:
org.apache.axis2.AxisFault: Transport error: 405 Error: Method Not Allowed
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSendr.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)

解决方案 »

  1.   


    private static final String url = "接口地址";

    private static final String QNAME_URL = "命名空间";

    private static final String USER_NAME = "账号";

    private static final String USER_PWD = "密码";public static void ServiceClient(){
    try {
    ServiceClient client = new ServiceClient();

    client.setOptions(buildOptions()); OMElement element = client.sendReceive(buildParam());

    Iterator it = element.getChildElements();

    while(it.hasNext()){
    OMElement omElement = (OMElement) it.next();
    System.out.println(omElement.getText());
    } } catch (AxisFault e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }public static Options buildOptions(){
    Options options = new Options();

    options.setTo(new EndpointReference(url));

    options.setAction("GetJITOrderList");

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(USER_NAME);
    auth.setPassword(USER_PWD); options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);

    options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

    return options;
    }public static OMElement buildParam(){
    OMFactory factory = OMAbstractFactory.getOMFactory();

    OMNamespace namespace = factory.createOMNamespace(QNAME_URL, "tns");

    OMElement date = factory.createOMElement("MT_JITInfo_Request",namespace);

    OMElement input = factory.createOMElement("DATUM",namespace);
    input.addChild(factory.createOMText(input, "20130609"));

    OMElement input2 = factory.createOMElement("ORDER",namespace);
    input2.addChild(factory.createOMText(input2, "X"));

    OMElement input3 = factory.createOMElement("MATNR",namespace);
    input3.addChild(factory.createOMText(input3, "X"));

    OMElement input4 = factory.createOMElement("ZTBBJ",namespace);
    input4.addChild(factory.createOMText(input4, "X"));

    date.addChild(input);
    date.addChild(input2);
    date.addChild(input3);
    date.addChild(input4);

    return date;
    }
      

  2.   

    我玩的是axis1.4  wsdd形式发布服务。里面有一个allowedmethod节点,会列出所有允许的服务。不晓得Axis2有没有类似的东东
      

  3.   


    参数里面没有任何中文,全是数字和字母。为了确保不是参数问题我将所有参数置为空依然出现这个错误。不过刚刚意外的发现我写的权限验证并没有起作用,难道是这个引起的?HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();         
    auth.setUsername(USER_NAME);         
    auth.setPassword(USER_PWD);           
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
      

  4.   


    参数里面没有任何中文,全是数字和字母。为了确保不是参数问题我将所有参数置为空依然出现这个错误。不过刚刚意外的发现我写的权限验证并没有起作用,难道是这个引起的?HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();         
    auth.setUsername(USER_NAME);         
    auth.setPassword(USER_PWD);           
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
    应该有影响。
      

  5.   


    参数里面没有任何中文,全是数字和字母。为了确保不是参数问题我将所有参数置为空依然出现这个错误。不过刚刚意外的发现我写的权限验证并没有起作用,难道是这个引起的?HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();         
    auth.setUsername(USER_NAME);         
    auth.setPassword(USER_PWD);           
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
    应该有影响。这种写法是参照官网的API写的,刚刚试了直接写到header里传过去也无效。现在准备用CXF试试。
      

  6.   

    加上auth.setPreemptiveAuthentication(true);看下
      

  7.   


    加上这个还是不行,不过现在已经用CXF实现了。感谢帮助