|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Jaxb TransformersNot sure if these already exist, but might be useful to somebody....
Configure like this: <transformer name="JaxbXmlToObject" className="JaxbXmlToObject"> <properties> <property name="jaxbContextFactoryClass" value="YourJaxbContextFactory "/> </properties> </transformer> public class YourJaxbContextFactory { public static JAXBContext getJaxbContext() throws JAXBException { return JAXBContext.newInstance(SomeJaxb.class,AnotherJaxb.class); } } Best Regards, James public abstract class AbstractJaxbTransformer extends AbstractEventAwareTransformer { private String jaxbContextFactoryClass; protected JAXBContext jaxbContext; @Override public void initialise() throws InitialisationException { try { Class clazz = Class.forName(jaxbContextFactoryClass); Method method = clazz.getMethod("getJaxbContext"); jaxbContext = (JAXBContext) method.invoke(clazz); } catch (ClassNotFoundException e) { throw new InitialisationException(e, this); } catch (NoSuchMethodException e) { throw new InitialisationException(e, this); } catch (IllegalAccessException e) { throw new InitialisationException(e, this); } catch (InvocationTargetException e) { throw new InitialisationException(e, this); } } public String getJaxbContextFactoryClass() { return jaxbContextFactoryClass; } public void setJaxbContextFactoryClass(String jaxbContextFactoryClass) { this.jaxbContextFactoryClass = jaxbContextFactoryClass; } public JAXBContext getJaxbContext() { return jaxbContext; } public void setJaxbContext(JAXBContext jaxbContext) { this.jaxbContext = jaxbContext; } } import org.mule.umo.UMOEventContext; import org.mule.umo.transformer.TransformerException; import javax.xml.bind.Unmarshaller; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.StringReader; import java.io.StringWriter; public class JaxbObjectToXml extends AbstractJaxbTransformer { public JaxbObjectToXml() { registerSourceType(Object.class); setReturnClass(String.class); } public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException { try { Marshaller unmarshaller = jaxbContext.createMarshaller(); StringWriter writer = new StringWriter(); unmarshaller.marshal(src,writer); return writer.toString(); } catch (JAXBException e) { throw new TransformerException(this, e); } } } import org.mule.umo.UMOEventContext; import org.mule.umo.transformer.TransformerException; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.StringReader; public class JaxbXmlToObject extends AbstractJaxbTransformer { public JaxbXmlToObject() { registerSourceType(String.class); setReturnClass(Object.class); } public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException { try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StringReader((String) src)); } catch (JAXBException e) { throw new TransformerException(this, e); } } } --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Jaxb TransformersJames Richardson wrote:
> Not sure if these already exist, but might be useful to somebody.... They did not - thanks! Archived for now as http://mule.mulesource.org/jira/browse/MULE-1208 thanks Holger --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Jaxb TransformersHi,
since JAXB-based unmarshalling of XML messages received via XML is one of the first requirements for my mule prototype / showcase, I would like to follow up on the JIRA that has been created for this work in the meantime: http://mule.mulesource.org/jira/browse/MULE-1208 As far as my understanding reaches JAXB unmarshalling is not yet available as part of mule's XML modules? In order to get something like the custom transformer workaround working (see below) it looks like one has to include some special mule module in one's maven config / pom.xml config file in order to (indirectly) have JAXB jars available as part of one's project (this is what comments on the JIRA ticket say). ==> Could somebody advise on how exactly I can get the custom transformer / the previously posted codebase to work? How can I ensure that I have JAXB jars available + that there are no JAR version clashes (which mule module to load/to add to pom.xml)? Also... ==> Could I use Spring XOM (part of spring-ws) as the basis for a custom transformer and how would I bring this into the mule XML config? Which modules would I have to load for this via pom.xml? Thanks + regards, Mike In addition, ... ...
|
|
|
Re: Jaxb TransformersThey havn't been added to Mule yet, but should be soon as it is not
much work. I'm unsure if they'll make it for 2.2 now though.. Alternatively it's very easy to implement your own... take a look at the example here: http://blog.mulesource.org/2009/01/implementing-messaging-patterns-using-web-services-with-mule-webinar-archive-and-sample-code/ Dan On Wed, Jan 21, 2009 at 11:17 PM, mschiffedb <michael.schifferdecker@...> wrote: > > Hi, > > since JAXB-based unmarshalling of XML messages received via XML is one of > the first requirements for my mule prototype / showcase, I would like to > follow up on the JIRA that has been created for this work in the meantime: > http://mule.mulesource.org/jira/browse/MULE-1208 > > As far as my understanding reaches JAXB unmarshalling is not yet available > as part of mule's XML modules? > > In order to get something like the custom transformer workaround working > (see below) it looks like one has to include some special mule module in > one's maven config / pom.xml config file in order to (indirectly) have JAXB > jars available as part of one's project (this is what comments on the JIRA > ticket say). > > ==> Could somebody advise on how exactly I can get the custom transformer / > the previously posted codebase to work? How can I ensure that I have JAXB > jars available + that there are no JAR version clashes (which mule module to > load/to add to pom.xml)? > > Also... > > ==> Could I use Spring XOM (part of spring-ws) as the basis for a custom > transformer and how would I bring this into the mule XML config? Which > modules would I have to load for this via pom.xml? > > Thanks + regards, Mike > > In addition, ... > ... > > > James Richardson-3 wrote: >> >> Not sure if these already exist, but might be useful to somebody.... >> >> Configure like this: >> >> <transformer name="JaxbXmlToObject" className="JaxbXmlToObject"> >> <properties> >> <property name="jaxbContextFactoryClass" >> value="YourJaxbContextFactory "/> >> </properties> >> </transformer> >> >> public class YourJaxbContextFactory { >> public static JAXBContext getJaxbContext() throws JAXBException { >> return JAXBContext.newInstance(SomeJaxb.class,AnotherJaxb.class); >> } >> } >> >> Best Regards, >> >> James >> >> >> public abstract class AbstractJaxbTransformer extends >> AbstractEventAwareTransformer { >> private String jaxbContextFactoryClass; >> protected JAXBContext jaxbContext; >> >> @Override >> public void initialise() throws InitialisationException { >> >> try { >> Class clazz = Class.forName(jaxbContextFactoryClass); >> Method method = clazz.getMethod("getJaxbContext"); >> jaxbContext = (JAXBContext) method.invoke(clazz); >> } >> catch (ClassNotFoundException e) { >> throw new InitialisationException(e, this); >> } >> catch (NoSuchMethodException e) { >> throw new InitialisationException(e, this); >> } >> catch (IllegalAccessException e) { >> throw new InitialisationException(e, this); >> } >> catch (InvocationTargetException e) { >> throw new InitialisationException(e, this); >> } >> } >> >> public String getJaxbContextFactoryClass() { >> return jaxbContextFactoryClass; >> } >> >> public void setJaxbContextFactoryClass(String jaxbContextFactoryClass) >> { >> this.jaxbContextFactoryClass = jaxbContextFactoryClass; >> } >> >> public JAXBContext getJaxbContext() { >> return jaxbContext; >> } >> >> public void setJaxbContext(JAXBContext jaxbContext) { >> this.jaxbContext = jaxbContext; >> } >> } >> >> >> >> >> import org.mule.umo.UMOEventContext; >> import org.mule.umo.transformer.TransformerException; >> >> import javax.xml.bind.Unmarshaller; >> import javax.xml.bind.JAXBException; >> import javax.xml.bind.Marshaller; >> import java.io.StringReader; >> import java.io.StringWriter; >> >> public class JaxbObjectToXml extends AbstractJaxbTransformer { >> >> public JaxbObjectToXml() { >> registerSourceType(Object.class); >> setReturnClass(String.class); >> } >> >> public Object transform(Object src, String encoding, UMOEventContext >> context) throws TransformerException { >> try { >> Marshaller unmarshaller = jaxbContext.createMarshaller(); >> StringWriter writer = new StringWriter(); >> unmarshaller.marshal(src,writer); >> return writer.toString(); >> } >> catch (JAXBException e) { >> throw new TransformerException(this, e); >> } >> >> >> } >> } >> >> >> >> import org.mule.umo.UMOEventContext; >> import org.mule.umo.transformer.TransformerException; >> >> import javax.xml.bind.JAXBException; >> import javax.xml.bind.Unmarshaller; >> import java.io.StringReader; >> >> public class JaxbXmlToObject extends AbstractJaxbTransformer { >> >> public JaxbXmlToObject() { >> registerSourceType(String.class); >> setReturnClass(Object.class); >> } >> >> public Object transform(Object src, String encoding, UMOEventContext >> context) throws TransformerException { >> try { >> Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); >> return unmarshaller.unmarshal(new StringReader((String) src)); >> } >> catch (JAXBException e) { >> throw new TransformerException(this, e); >> } >> } >> >> } >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> > > -- > View this message in context: http://www.nabble.com/Jaxb-Transformers-tp7434848p21593501.html > Sent from the Mule - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |