【问题标题】:Consume a simple web service using mule使用 mule 使用简单的 Web 服务
【发布时间】:2014-02-04 11:22:30
【问题描述】:

我正在尝试使用 Mule + apache cxf 使用公共服务。该服务在http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?WSDL提供服务

这是一个非常简单的服务,它执行基本的算术运算。我试图在这里调用操作“添加”。我的骡子配置如下

<flow name="calculator" doc:name="calculator">

<stdio:inbound-endpoint system="IN" doc:name="STDIO"/>
<custom-transformer class="com.calculator.transformer.CalculatorClient" doc:name="Java"/>

<outbound-endpoint address="http://localhost:28081/service/Calculator?WSDL" exchange-pattern="request-response" doc:name="HTTP">

  <cxf:jaxws-client clientClass="com.calculator.wsdl.Calculator" enableMuleSoapHeaders="true" port="CalculatorHttpPost" wsdlLocation="classpath:/wsdl/Calculator.wsdl" operation="Add">
      <cxf:inInterceptors>
    <spring:bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
    </cxf:inInterceptors>
    <cxf:outInterceptors>
      <spring:bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
    </cxf:outInterceptors>
  </cxf:jaxws-client>

</outbound-endpoint>

 <transformer ref="CalculatorResponse" doc:name="Transformer Reference"/>

 <mulexml:jaxb-object-to-xml-transformer name="CalculatortoXML" jaxbContext-ref="myJaxbCal" />



<stdio:outbound-endpoint system="OUT" doc:name="STDIO"/>


</flow>

在调用客户端类之前,我添加了一个转换器,如下所示。这只是设置要添加的 2 个数字。

代码

package com.calculator.transformer;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;

import com.calculator.wsdl.Add;

public class CalculatorClient extends AbstractMessageTransformer {

@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
        throws TransformerException {
    Add add= new Add();
    add.setA(3);
    add.setB(3);

    return add;
}

}

一旦我启动 mule,我就会收到错误消息。不确定我做错了什么。

ERROR 2014-01-16 01:09:46,237 [[weatherproject].calculator.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
Message               : wrong number of arguments. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: Add
Code                  : MULE_ERROR--2
Exception stack is:
1. wrong number of arguments (java.lang.IllegalArgumentException)
  sun.reflect.NativeMethodAccessorImpl:-2 (null)
2. wrong number of arguments. Failed to route event via endpoint: org.mule.module.cxf.CxfOutboundMessageProcessor. Message payload is of type: Add (org.mule.api.transport.DispatchException)
  org.mule.module.cxf.CxfOutboundMessageProcessor:148 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
Root Exception stack trace:
java.lang.IllegalArgumentException: wrong number of arguments
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

【问题讨论】:

    标签: web-services mule


    【解决方案1】:

    您提到了http://localhost:28081/service/Calculator?WSDL 作为您的地址,我想应该是http://localhost:28081/service/Calculator

    【讨论】:

    • 是的,我得到的错误是参数数量错误。我不确定我这样做是否正确
    • 替换 java.lang.IllegalArgumentException 后遇到同样的问题:参数数量错误
    【解决方案2】:

    这篇文章帮我解决了问题

    Mule SOAP client wrapper as parameter instead of object array

    按照建议使用 JAXB 绑定,CXF 将生成包装对象。

    【讨论】:

      猜你喜欢
      • 2013-10-31
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多