Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use XStream in Mule?
    primarykey
    data
    text
    <p>I have written three classes implementing XStream. It marshalls/unmarshalls the following XML.</p> <pre><code>&lt;Message calledProgram="XXX" programName="YYY"&gt; &lt;Fields&gt; &lt;Field name="SupplierName" value="ABC"/&gt; &lt;Field name="SupplierNo" value="123456"/&gt; &lt;Field name="SupplierCountry" value="AA"/&gt; &lt;Field name="TermsOfDelivery" value="5"/&gt; &lt;Field name="PaymentTerms" value="90"/&gt; &lt;Field name="Currency" value="GBP"/&gt; &lt;/Fields&gt; &lt;/Message&gt; </code></pre> <p>How do I use these classes in Mule? It is one Class that uses the other two so it is just one class to use.</p> <p>I will be receiving an XML like above. I want to transform it to an Object.</p> <p>It works in plain Java, but how do I use it in a flow. Getting all possible Exceptions from Mule.</p> <pre><code>Exception in thread "main" org.mule.module.launcher.DeploymentInitException: InstantiationException: xxx.com.GenericClass at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:220) at org.mule.module.launcher.application.ApplicationWrapper.init(ApplicationWrapper.java:64) at org.mule.module.launcher.DefaultMuleDeployer.deploy(DefaultMuleDeployer.java:46) at org.mule.tooling.server.application.ApplicationDeployer.run(ApplicationDeployer.java:56) at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:88) Caused by: org.mule.api.config.ConfigurationException: Error creating bean with name 'MyB24Flow1': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: Unable to initialize XStream (org.mule.api.lifecycle.InitialisationException) (org.mule.api.config.ConfigurationException) at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:52) at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:78) at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:80) at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:208) ... 4 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyB24Flow1': Invocation of init method failed; nested exception is org.mule.api.lifecycle.InitialisationException: Unable to initialize XStream at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:89) at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:109) ... 14 more Caused by: org.mule.api.lifecycle.InitialisationException: Unable to initialize XStream at org.mule.module.xml.transformer.AbstractXStreamTransformer.initialise(AbstractXStreamTransformer.java:52) at org.mule.processor.chain.AbstractMessageProcessorChain.initialise(AbstractMessageProcessorChain.java:79) at org.mule.construct.AbstractFlowConstruct.initialiseIfInitialisable(AbstractFlowConstruct.java:309) at org.mule.construct.AbstractPipeline.doInitialise(AbstractPipeline.java:161) at org.mule.construct.AbstractFlowConstruct$1.onTransition(AbstractFlowConstruct.java:111) at org.mule.construct.AbstractFlowConstruct$1.onTransition(AbstractFlowConstruct.java:105) at org.mule.lifecycle.AbstractLifecycleManager.invokePhase(AbstractLifecycleManager.java:141) at org.mule.construct.FlowConstructLifecycleManager.fireInitialisePhase(FlowConstructLifecycleManager.java:81) at org.mule.construct.AbstractFlowConstruct.initialise(AbstractFlowConstruct.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ... 25 more </code></pre> <p><strong>Update:</strong></p> <p>Though this is not my real code. But how do you mean OOTB? This doesn't work either. Have tried without the File-2-String as well.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "&gt; &lt;flow name="MyXStreamFlow1" doc:name="MyXStreamFlow1"&gt; &lt;file:inbound-endpoint path="E:\JavaDev\Test" responseTimeout="10000" doc:name="File"/&gt; &lt;logger level="INFO" doc:name="Logger"/&gt; &lt;file:file-to-string-transformer doc:name="File to String"/&gt; &lt;logger message="WTF" level="INFO" doc:name="Logger"/&gt; &lt;mulexml:xml-to-object-transformer doc:name="XML to Object"/&gt; &lt;logger level="INFO" doc:name="Logger"/&gt; &lt;mulexml:object-to-xml-transformer doc:name="Object to XML"/&gt; &lt;logger level="INFO" doc:name="Logger"/&gt; &lt;/flow&gt; </code></pre> <p></p> <p>Here's my main Java Class.</p> <pre><code>package test; import java.io.FileInputStream; import java.io.FileNotFoundException; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; import com.thoughtworks.xstream.io.xml.DomDriver; @XStreamAlias("Message") public class GenericClass { @XStreamAlias("calledProgram") @XStreamAsAttribute private String calledProgram; @XStreamAlias("programName") @XStreamAsAttribute private String programName; @XStreamAlias("Fields") private Fields flds = new Fields( new Field("nameValue1", "valueValue1"), new Field("nameValue2", "valueValue2"), new Field("nameValue3", "valueValue2")); private static XStream xstream; public GenericClass() { new GenericClass("calledProgram", "programName"); } public GenericClass(String calledProgram, String programName) { xstream = new XStream(new DomDriver()); xstream.processAnnotations(GenericClass.class); this.calledProgram = calledProgram; this.programName = programName; } public static void main(String[] args) { GenericClass msg = new GenericClass(); // Unmarshall FileInputStream file = null; try { file = new FileInputStream( "E:\\JavaDev\\JRecordFiles\\Samples\\LevisTest.xml"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } msg = (GenericClass) xstream.fromXML(file); System.out.println("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n" + xstream.toXML(msg)); } } </code></pre> <p>-</p> <pre><code>package test; import com.thoughtworks.xstream.annotations.XStreamAsAttribute; public class Field { private String field; @XStreamAsAttribute private String name; @XStreamAsAttribute private String value; /** * @param field */ public Field(String name, String value) { this.name = name; this.value = value; } /** * @return the field */ public String getField() { return field; } /** * @param field * the field to set */ public void setField(String field) { this.field = field; } /** * @return the name */ public String getName() { return name; } /** * @param name * the name to set */ public void setName(String name) { this.name = name; } /** * @return the value */ public String getValue() { return value; } /** * @param value * the value to set */ public void setValue(String value) { this.value = value; } } </code></pre> <p>-</p> <pre><code>package test; import java.util.Arrays; import java.util.List; import com.thoughtworks.xstream.annotations.XStreamImplicit; public class Fields { @XStreamImplicit(itemFieldName = "Field") private List&lt;Field&gt; fields; public Fields(Field... field) { this.fields = Arrays.asList(field); } /** * @return the fields */ public List&lt;Field&gt; getFields() { return fields; } /** * @param fields * the fields to set */ public void setFields(List&lt;Field&gt; fields) { this.fields = fields; } } </code></pre> <p>How do I use XStream in Mule?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload