使用mule消费一个简单的Web服务

时间:2014-01-15 19:45:07

标签: web-services mule

我正在尝试使用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;
}

}

一旦我开始骡子,我收到错误。不确定我做错了什么。

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)

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

这篇文章帮助我解决了这个问题

Mule SOAP client wrapper as parameter instead of object array

通过使用建议的JAXB绑定,CXF将生成包装器对象。