【问题标题】:running an axis2 client version 1.5运行axis2客户端1.5版
【发布时间】:2011-02-26 13:39:09
【问题描述】:

所以我没有办法尝试让客户端连接到我通过axis2运行的SOAP服务。

我尝试了两种方法,一种是使用 wsdl2java 构建存根和相关的客户端类,然后编写一个客户端类来构建请求消息并通过存根发送它们。另一种方法是使用ServiceClient连接..

两者都以自己的方式失败..

选项 #1,每次通过存根发送消息时,我都会返回:

org.apache.axis2.AxisFault: The input stream for an incoming message is null.
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:87)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

选项#2,每次我运行它我都会得到这个异常:

org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.local.LocalTransportSender

选项 #2 来源:

import javax.xml.stream.XMLStreamException;
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.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.Constants;
import org.apache.axis2.client.ServiceClient;

public class loyaltyClient {

    private static EndpointReference targetEPR = 
         new EndpointReference(
           "http://localhost:8080/axis2/services/service");

    public static OMElement verifyCustomer(String customer_id) {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(
                "http://localhost/", "service");
        OMElement method = fac.createOMElement("VerifyCustomer", omNs);
        OMElement value1 = fac.createOMElement("customer_id",omNs);
        OMElement value2 = fac.createOMElement("source_id",omNs);
        OMElement value3 = fac.createOMElement("source_password",omNs);
        OMElement value4 = fac.createOMElement("source_txnid",omNs);
        OMElement value5 = fac.createOMElement("timestamp",omNs);

value1.addChild(fac.createOMText(value1, customer_id));
value2.addChild(fac.createOMText(value2, "source"));
value3.addChild(fac.createOMText(value3, "1234"));
value4.addChild(fac.createOMText(value4, "123"));
value5.addChild(fac.createOMText(value5, "06-01-2010 12:01:01"));
        method.addChild(value1);
        method.addChild(value2);
        method.addChild(value3);
        method.addChild(value4);
        method.addChild(value5);
        return method;
    }

    public static void main(String[] args) {
        try {
            OMElement vctest = loyaltyClient.verifyCustomer("6177740603");
            Options options = new Options();
            options.setTo(targetEPR);

options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

            ServiceClient sender = new ServiceClient();
            sender.setOptions(options);
            OMElement result = sender.sendReceive(vctest);

            String response = result.getFirstElement().getText();
            System.out.println(response);

        } catch (Exception e) { //(XMLStreamException e) {
            System.out.println(e.toString());
        }
    }

}

【问题讨论】:

  • 你发现选项#1的问题了吗,我也有同样的问题。

标签: java exception soap client axis2


【解决方案1】:

在使用 Axis 连接到 .Net 服务提供商时,我还遇到了错误“传入消息的输入流为空”。

问题在于 .Net 不支持称为“分块编码”的功能,默认情况下,Axis 会将其请求标头分块分解,这应该是符合 HTTP 1.1 的东西。

无论如何,您可以通过执行以下操作在 Axis 中关闭此功能:

// Turn off the Axsis Chunked feature, some service providers (like .Net) don't support chunked headers.
Options options = serviceClient.getOptions();
options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
serviceClient.setOptions(options);            

这对我有用。处理 .Net 服务时要确保的另一件事是能够指定端口名称并确保您的消息负载具有每个元素的命名空间前缀。

希望此信息对某人有所帮助。

干杯, 直流

【讨论】:

    【解决方案2】:

    注意 Axis2 是 buggy pile of crap,我最近不得不编写一个 Axis2 客户端,发现使用默认的 ServiceClient() 构造函数效果不佳——我不得不手动创建 ConfigurationContext 等。我发现使用 ServiceClient.getOptions() 而不是创建 new Options() 保留了一些默认数据。我还建议放弃options.setTransportInProtocol(...),除非你真的需要它——没有这个,一切都应该通过HTTP正常工作。此外,您可能需要设置 options.setAction(...) 以与 WSDL 中的“操作”相对应。

    我已经包含了我的大部分客户(删除了敏感信息),希望它会有所帮助。除非您打算使用 WS-Addressing,否则您可以放心地忽略有关寻址的部分。

    ConfigurationContext cfgCtx = null;
    
    try {
        /* Passing null to both params causes an AxisConfiguration to be created that uses
         * the default axis2.xml file, which is included in the axis2 distribution jar.
         * This is ideal for our case, since we cannot pass a full file path (relative
         * paths are not allowed) because we do not know where the customer will deploy
         * the application. This also allows engaging modules from the classpath. */
        cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null , null);
    } catch (AxisFault e) {
        // Bubble up the error
    }
    
    ServiceClient svcClient = null;
    try {
        svcClient = new ServiceClient(cfgCtx, null);
    } catch (AxisFault e) {
        // Bubble up the error
    }
    
    try {
        /* This will work with the above ConfigurationContext as long as the module
         * (addressing-1.5.1.mar) is on the classpath, e.g. in shared/lib. */
        svcClient.engageModule("addressing");
    } catch (AxisFault e) {
        // Bubble up the error
    }
    
    Options opts = svcClient.getOptions();
    opts.setTo(new EndpointReference("http://myservername:8080/axis2/services/MyService"));
    opts.setAction("urn:doSomething"); // Corresponds to the "operation" in MyService's WSDL
    opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); // Set output to SOAP 1.2
    
    SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
    svcClient.addHeader(createSOAPSecurityHeader(factory, response)); // CreateSOAPHeader just creates an OMElement
    
    try {
        svcClient.sendReceive(createSOAPBody(factory, response)); // CreateSOAPBody just creates an OMElement
    } catch (AxisFault e) {
        throw new ResponseDeliveryException(1, "Error sending SOAP payload.", e);
    }
    

    【讨论】:

    • 也支持这种说法。显然,人们已经通过它取得了成功,但我个人在遇到上述问题时转向了 Apache CXF,并且没有理由回头。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2012-04-01
    • 2014-01-18
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    相关资源
    最近更新 更多