JaxbDataFormat dataFormat = new JaxbDataFormat(); dataFormat.setContextPath("com.somepath.xml"); from("jms:topic:myTopic?transacted=true&connectionFactory=myJmsConnectionFactory") .transacted() .unmarshal(dataFormat) .routeId("myRouteId")
/** * Clones the passed JaxbDataFormat and then augments it with with Drools related namespaces * * @param jaxbDataFormat * @return */ public static JaxbDataFormat augmentJaxbDataFormatDefinition(JaxbDataFormat jaxbDataFormat) { Set<String> set = new HashSet<String>(); for ( String clsName : DroolsJaxbHelperProviderImpl.JAXB_ANNOTATED_CMD ) { set.add( clsName.substring( 0, clsName.lastIndexOf( '.' ) ) ); } StringBuilder sb = new StringBuilder(); sb.append( jaxbDataFormat.getContextPath() ); sb.append( ":" ); for ( String pkgName : set ) { sb.append( pkgName ); sb.append( ':' ); } jaxbDataFormat.setContextPath( sb.toString() ); return jaxbDataFormat; }
/** * Creates a JAXB data format for marshalling and unmarshalling * the specified class to/from its native XML representation. * Unlike data format returned by {@link #jaxb(Class)}, * this data format works with classes that are not root elements * (e.g., not annotated with {@link XmlRootElement}). * * @param xmlClass the class that this data format will be able to marshal and unmarshal * @param partNamespace the namespace (optional) with the name of the root element * (name in XML, not its Java class name), * which is necessary for marshalling the class to XML * @return the Camel {@link DataFormatDefinition} instance for use in routes */ public static JaxbDataFormat jaxbFragment(Class<?> xmlClass, String partNamespace) { JaxbDataFormat dataFormat = jaxbFragment(xmlClass); // partial marshaling - class without @XmlRootElement dataFormat.setFragment(true); dataFormat.setPartClass(xmlClass.getName()); dataFormat.setPartNamespace(partNamespace); return dataFormat; } }
/** * Creates a JAXB data format for <strong>unmarshalling</strong> (only) * the specified class to/from its native XML representation. * Unlike data format returned by {@link #jaxb(Class)}, * this data format works with classes that are not root elements * (e.g., not annotated with {@link XmlRootElement}). * * @param xmlClass the class that this data format will be able to marshal and unmarshal * @return the Camel {@link DataFormatDefinition} instance for use in routes * @see #jaxbFragment(Class, String) for marshalling fragments (as this one can only unmarshal) */ public static JaxbDataFormat jaxbFragment(Class<?> xmlClass) { JaxbDataFormat jaxbIn = jaxb(xmlClass); // partial unmarshaling - class without @XmlRootElement jaxbIn.setFragment(true); jaxbIn.setPartClass(xmlClass.getName()); return jaxbIn; }
public void configure() throws Exception { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint(true); def.setContextPath("org.kie.pipeline.camel"); from("direct:test-with-session").policy(new KiePolicy()).unmarshal(def).to("kie-local:ksession1").marshal(def); } };
public JAXBContext getJaxbContext() { if ( this.jaxbContext == null ) { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint( true ); // TODO does not work: def.setContextPath( "org.drools.camel.testdomain:org.drools.pipeline.camel" ); def.setContextPath( "org.drools.pipeline.camel" ); // create a jaxbContext for the test to use outside of Camel. StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get( "ksession1", CommandExecutor.class ); KnowledgeBase kbase = ksession1.getKieBase(); ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( ((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader() ); def = DroolsPolicy.augmentJaxbDataFormatDefinition( def ); org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat( this.context.getRoutes().get( 0 ).getRouteContext() ); jaxbDataformat.setCamelContext(routeBuilder.getContext()); try { jaxbDataformat.start(); } catch (Exception e) { throw new IllegalStateException(e); } jaxbContext = jaxbDataformat.getContext(); } finally { Thread.currentThread().setContextClassLoader( originalCl ); } } return jaxbContext; }
JaxbDataFormat jaxb = new JaxbDataFormat("com.example.foobar"); from("ftp://user:pass@server:21/inbox") .unmarshal().zip() .split(xpath("//foo")) .unmarshal(jaxb) .to("jpa:com.example.foobar.Foo")
public void configure() throws Exception { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint(true); def.setContextPath("org.drools.pipeline.camel"); from("direct:test-with-session").policy(new DroolsPolicy()). unmarshal(def).to("drools:node/ksession1").marshal(def); } };
public JAXBContext getJaxbContext() { if ( this.jaxbContext == null ) { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint( true ); // TODO does not work: def.setContextPath( "org.drools.camel.testdomain:org.drools.pipeline.camel" ); def.setContextPath( "org.drools.pipeline.camel" ); // create a jaxbContext for the test to use outside of Camel. StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get( "ksession1", CommandExecutor.class ); KnowledgeBase kbase = ksession1.getKieBase(); ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( ((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader() ); def = DroolsPolicy.augmentJaxbDataFormatDefinition( def ); org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat( this.context.getRoutes().get( 0 ).getRouteContext() ); jaxbDataformat.setCamelContext(routeBuilder.getContext()); try { jaxbDataformat.start(); } catch (Exception e) { throw new IllegalStateException(e); } jaxbContext = jaxbDataformat.getContext(); } finally { Thread.currentThread().setContextClassLoader( originalCl ); } } return jaxbContext; }
JaxbDataFormat jaxb = new JaxbDataFormat("add.your.namespace.to.the.ObjectFactory"); jaxb.setPrettyPrint(true); from("seda:out?concurrentConsumers=20") .process(new process_1()) .marshal(jaxb) .process(new process_2());
public void configure() throws Exception { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint(true); // TODO does not work: def.setContextPath( "org.drools.camel.testdomain:org.drools.pipeline.camel" ); def.setContextPath("org.drools.pipeline.camel"); from("direct:test-with-session").policy(new DroolsPolicy()). unmarshal(def).to("drools:node/ksession1").marshal(def); } };
public JAXBContext getJaxbContext() { if ( this.jaxbContext == null ) { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint( true ); def.setContextPath( "org.drools.model:org.drools.pipeline.camel" ); // create a jaxbContext for the test to use outside of Camel. StatefulKnowledgeSession ksession1 = (StatefulKnowledgeSession) node.get( "ksession1", CommandExecutor.class ); KnowledgeBase kbase = ksession1.getKieBase(); ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader( ((ReteooRuleBase) ((KnowledgeBaseImpl) kbase).getRuleBase()).getRootClassLoader() ); def = DroolsPolicy.augmentJaxbDataFormatDefinition( def ); org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat) def.getDataFormat( this.context.getRoutes().get( 0 ).getRouteContext() ); jaxbDataformat.setCamelContext(routeBuilder.getContext()); try { jaxbDataformat.start(); } catch (Exception e) { throw new IllegalStateException(e); } jaxbContext = jaxbDataformat.getContext(); } finally { Thread.currentThread().setContextClassLoader( originalCl ); } } return jaxbContext; }
/** * Creates a JAXB data format for marshalling and unmarshalling * the specified class to/from its native XML representation. * * @param xmlClass the class that this data format will be able to marshal and unmarshal * @return the Camel {@link DataFormatDefinition} instance for use in routes */ public static JaxbDataFormat jaxb(Class<?> xmlClass) { JaxbDataFormat dataFormat = new JaxbDataFormat(false); dataFormat.setContextPath(xmlClass.getPackage().getName()); return dataFormat; }
DataFormat jaxb = new JaxbDataFormat("com.acme.model"); from("activemq:My.Queue"). unmarshal(jaxb). to("mqseries:Another.Queue");
/** * Clones the passed JaxbDataFormat and then augments it with with Drools related namespaces * * @param jaxbDataFormat * @return */ public static JaxbDataFormat augmentJaxbDataFormatDefinition(JaxbDataFormat jaxbDataFormat) { Set<String> set = new HashSet<String>(); for ( String clsName : DroolsJaxbHelperProviderImpl.JAXB_ANNOTATED_CMD ) { set.add( clsName.substring( 0, clsName.lastIndexOf( '.' ) ) ); } StringBuilder sb = new StringBuilder(); sb.append( jaxbDataFormat.getContextPath() ); sb.append( ":" ); for ( String pkgName : set ) { sb.append( pkgName ); sb.append( ':' ); } jaxbDataFormat.setContextPath( sb.toString() ); return jaxbDataFormat; }
/** * Creates a JAXB data format for marshalling and unmarshalling the specified class * to/from its native XML representation. * <p> * If rootQName is provided, this data format will work with classes that are not root elements * (not annotated with {@link XmlRootElement}). * * @param xmlClass the class that this data format will be able to marshal and unmarshal * @param rootQName the QName (optional) of the root element in XML, * which is necessary for marshalling classes without XmlRootElement to XML * @return the Camel {@link DataFormatDefinition} instance for use in routes */ public static JaxbDataFormat jaxb(Class<?> xmlClass, @Nullable QName rootQName) { JaxbDataFormat dataFormat = jaxb(xmlClass); // partial marshaling - class without @XmlRootElement if (rootQName != null) { dataFormat.setFragment(true); dataFormat.setPartClass(xmlClass.getName()); dataFormat.setPartNamespace(rootQName.toString()); } return dataFormat; }
public void configure() throws Exception { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint(true); // TODO does not work: def.setContextPath( "org.drools.camel.testdomain:org.drools.pipeline.camel" ); def.setContextPath("org.kie.pipeline.camel"); from("direct:test-with-session").policy(new KiePolicy()).unmarshal(def).to("kie-local:ksession1").marshal(def); } };
public JAXBContext getJaxbContext() { if (this.jaxbContext == null) { JaxbDataFormat def = new JaxbDataFormat(); def.setPrettyPrint(true); def.setContextPath("org.drools.model:org.kie.pipeline.camel"); org.apache.camel.converter.jaxb.JaxbDataFormat jaxbDataformat = (org.apache.camel.converter.jaxb.JaxbDataFormat)def.getDataFormat(this.context.getRoutes().get(0) .getRouteContext());
public void configure() throws Exception { JaxbDataFormat jaxbDf = new JaxbDataFormat(); jaxbDf.setContextPath( "org.drools.camel.testdomain" ); from( "direct:exec" ).policy( new DroolsPolicy() ).unmarshal( dataformat ).to( "drools://node/ksession1" ).marshal( dataformat ); from( "direct:execWithLookup" ).policy( new DroolsPolicy() ).unmarshal( dataformat ).to( "drools://node" ).marshal( dataformat ); from( "direct:unmarshal" ).policy( new DroolsPolicy() ).unmarshal( dataformat ); from( "direct:marshal" ).policy( new DroolsPolicy() ).marshal( dataformat ); from( "direct:to-xstream" ).policy( new DroolsPolicy() ).unmarshal( dataformat ).marshal( "xstream" ); from( "direct:to-jaxb" ).policy( new DroolsPolicy() ).unmarshal( dataformat ).marshal( jaxbDf ); } };
DataFormat jaxb = new JaxbDataFormat("com.acme.model"); from("activemq:My.Queue"). unmarshal(jaxb). to("mqseries:Another.Queue");