在Mule esb中使用具有多个参数的Web服务方法 [英] Consume a web service method with multiple args in Mule esb

查看:71
本文介绍了在Mule esb中使用具有多个参数的Web服务方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想应用的内容看起来很简单,但我不知道如何,需要澄清一下. 这是场景: 我想调用一个Web服务方法,此方法的名称为find()并接受一个对象作为参数,该对象表示一个组合的主键,由两个字符串组成,一个id和一个类型. 肥皂中的主键表示形式的对象是:

Hello what I want to apply seems very simple but I don't know how, need some clarifications. here is the scenario: I want to call a web service method, this method name is find() and accept as argument an object, the object represent a composed primary key, composed by two strings an id and a type. the object -which is the primary key- representation in soap is :

<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发布请求中读取两个args(id和type),以使用java转换器创建所需的主键对象,该转换器调用主键类构造函数,然后将创建的对象传递给soap组件基于该对象创建soap请求,然后使用http组件调用Web服务,最后将响应写入文件中. 这就是结果流:

my first idea was about reading the two args (the id and the type)from an http post request to create the wanted primary key object with a java transformer which call the primary key class constructor , then pass the created object to a soap component to creat the soap request based on the object, then call the web service with an http component and finally write the response into a file. this the resulting flow:

<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;
    }

}

我在运行项目时收到错误消息

when I run the project I get the error

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)
********************************************************************************

我不知道我的逻辑是否错误,或者是否有简单的方法来完成这项工作? 谢谢您的帮助.

I dont know if my logic is wrong or if there is a simple way to get the job done ?? thak you for your help.

推荐答案

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

First, I would not create a custom-transformer for simply instantiating a class, I would just use an expression:

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

第二,您得到的异常来自mulexml:object-to-xml-transformer无法使用XStream将SoapMessage对象转换为XML(这是预料之中的). cxf:jaxws-client的责任是在流程的响应阶段取消编组.

Second, the exception you're getting comes from the inability of mulexml:object-to-xml-transformer to transform a SoapMessage object to XML using XStream (which is kind of expected). It is the responsibility of cxf:jaxws-client to do this unmarshalling in the response phase of the flow.

因此,您需要将mulexml:object-to-xml-transformerfile:outbound-endpoint元素放在cxf:jaxws-client上方的response元素中,以便在CXF解组对正确对象的响应之后对其进行处理.

So you need to the mulexml:object-to-xml-transformer and the file:outbound-endpoint elements in a response element above the cxf:jaxws-client so they are processed after CXF has unmarshalled the response to the right object.

这篇关于在Mule esb中使用具有多个参数的Web服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆