0

您好,我想申请的似乎很简单,但我不知道如何,需要一些说明。下面是场景:我想调用一个 Web 服务方法,这个方法名称是 find() 并接受一个对象作为参数,该对象表示一个组合主键,由两个字符串组成,一个 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 请求中读取两个参数(id 和类型),以使用调用主键类构造函数的 java 转换器创建所需的主键对象,然后将创建的对象传递给肥皂组件根据对象创建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)
********************************************************************************

我不知道我的逻辑是否错误,或者是否有一种简单的方法可以完成工作??谢谢你的帮助。

4

2 回答 2

1

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

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

其次,您遇到的异常来自无法使用 XStreammulexml:object-to-xml-transformerSoapMessage对象转换为 XML(这是意料之中的)。有责任cxf:jaxws-client在流的响应阶段执行此解组。

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

于 2013-05-17T18:20:33.850 回答
0

xml to object 错误是由于 SOAP 组件而出现的,在您的情况下,您可以避免它,而只需使用和表达式转换器

于 2015-08-26T07:54:39.420 回答