消费与骡子ESB多个ARGS Web服务方法(Consume a web service metho

2019-09-03 14:09发布

你好我想申请似乎很简单,但我不知道怎么了,需要一些澄清。 这里是情景:我想调用Web服务方法,这个方法的名字是找到(),并接受作为参数的对象,该对象代表组成的主键,由两个字符串ID和类型组成。 对象 - 其在肥皂主密钥 - 表示为:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsd="http://wsdouane/">
   <soapenv:Header/>
   <soapenv:Body>
      <wsd:find>
         <entity>
            <id>string_1</id>
            <type>string_2</type>
         </entity>
      </wsd:find>
   </soapenv:Body>
</soapenv:Envelope>

我的第一个想法是约从HTTP POST请求来创建一个java变压器,其调用主键类构造想主键对象中读取两个ARGS(id和类型),则所创建的对象传递给皂组分,以穿心莲基于对象上的SOAP请求,然后调用与HTTP组件web服务和最后写入的响应到文件中。 此产生的流量:

<flow name="testObjetFlow1" doc:name="testObjetFlow1">
    <http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8088" doc:name="HTTP"/>
    <custom-transformer class="com.test.transformer.HttpRequestToPrimaryKeyObject" doc:name="PK Object Transformer"/>
    <cxf:jaxws-client operation="find" serviceClass="douane.Douane" port="douanePort"  doc:name="SOAP"/>
    <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8080/ClientsDB/douane" doc:name="douaneWS"/>
    <mulexml:object-to-xml-transformer doc:name="Object to XML"/>
    <file:outbound-endpoint path="C:\MuleStudio\SandBox\output" outputPattern="#[function:datestamp:dd-MM-yy]_#[function:systime].xml " responseTimeout="10000" doc:name="Outgoing File"/>
</flow>

我的定制变压器

package com.test.transformer;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
import douane.DouanePK;
public class HttpRequestToPrimaryKeyObject extends AbstractMessageTransformer {

    @Override
    //DouanePK represent the primary key entity
    public DouanePK transformMessage(MuleMessage message, String outputEncoding)
            throws TransformerException {
        // TODO Auto-generated method stub
        String id = message.getInboundProperty("id");
        String type = message.getInboundProperty("type");

        DouanePK primKey = new DouanePK();
        dp.setId(id);
        dp.setType(type);

        return primKey;
    }

}

当我运行该项目,我得到的错误

ERROR 2013-05-16 09:44:13,191 [[mediation_mod].testObjetFlow1.stage1.03] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException). Message payload is of type: byte[]
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot marshal the XStream instance in action
---- Debugging information ----
------------------------------- (com.thoughtworks.xstream.converters.ConversionException)
  com.thoughtworks.xstream.converters.reflection.SelfStreamingInstanceChecker:44 (null)
2. Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException)
  com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker:140 (null)
3. Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException). Message payload is of type: byte[] (org.mule.api.transformer.TransformerMessagingException)
  org.mule.transformer.AbstractTransformer:139 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.converters.ConversionException: Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
    at com.thoughtworks.xstream.converters.reflection.SelfStreamingInstanceChecker.marshal(SelfStreamingInstanceChecker.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

ERROR 2013-05-16 09:44:13,182 [[mediation_mod].testObjetFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException). Message payload is of type: byte[]
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot marshal the XStream instance in action
---- Debugging information ----
------------------------------- (com.thoughtworks.xstream.converters.ConversionException)
  com.thoughtworks.xstream.converters.reflection.SelfStreamingInstanceChecker:44 (null)
2. Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException)
  com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker:140 (null)
3. Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject() : Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
message             : Could not call org.apache.cxf.binding.soap.SoapMessage.writeObject()
cause-exception     : com.thoughtworks.xstream.converters.ConversionException
cause-message       : Cannot marshal the XStream instance in action
------------------------------- (com.thoughtworks.xstream.converters.ConversionException). Message payload is of type: byte[] (org.mule.api.transformer.TransformerMessagingException)
  org.mule.transformer.AbstractTransformer:139 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerMessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
com.thoughtworks.xstream.converters.ConversionException: Cannot marshal the XStream instance in action
---- Debugging information ----
-------------------------------
    at com.thoughtworks.xstream.converters.reflection.SelfStreamingInstanceChecker.marshal(SelfStreamingInstanceChecker.java:44)
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

我不知道如果我的逻辑是错误的,或者如果有,把工作做了一个简单的方法? thak你的帮助。

Answer 1:

首先,我不会创建一个custom-transformer的简单实例化一个类,我只想用一个表达式:

<expression-transformer
    expression="#[new douane.DouanePK(message.inboundProperties.id,message.inboundProperties.type)]" />

其次,你得到的例外来自无力mulexml:object-to-xml-transformer来变换SoapMessage使用XStream的(这是一种预期)对象到XML。 它是有责任cxf:jaxws-client做这个解组在流动的响应阶段。

所以,你需要的mulexml:object-to-xml-transformerfile:outbound-endpoint的元素response上述元素cxf:jaxws-client ,以便CXF已解组到合适的对象的响应后,他们被处理。



Answer 2:

XML反对错误出现,因为SOAP组件的,你的情况,你可以避开它,,而只使用和表达变压



文章来源: Consume a web service method with multiple args in Mule esb