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>
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>
My custom transformer
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.
First, I would not create a
custom-transformer
for simply instantiating a class, I would just use an expression:Second, the exception you're getting comes from the inability of
mulexml:object-to-xml-transformer
to transform aSoapMessage
object to XML using XStream (which is kind of expected). It is the responsibility ofcxf:jaxws-client
to do this unmarshalling in the response phase of the flow.So you need to the
mulexml:object-to-xml-transformer
and thefile:outbound-endpoint
elements in aresponse
element above thecxf:jaxws-client
so they are processed after CXF has unmarshalled the response to the right object.xml to object error comes because of SOAP component, in your case, you may avoid it,, and just use and expression tranformer