private static DataFormatDefinition processDataFormatType(RouteContext routeContext, String ref, DataFormatDefinition dformatDefinition) { if ( dformatDefinition == null ) { if ( "json".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); ((XStreamDataFormat) dformatDefinition).setDriver( "json" ); } else if ( "xstream".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); } else if ( "jaxb".equals( ref ) ) { dformatDefinition = new JaxbDataFormat(); } else { dformatDefinition = routeContext.getCamelContext().resolveDataFormatDefinition( ref ); } } // always clone before changing dformatDefinition = new FastCloner().deepClone( dformatDefinition ); if ( dformatDefinition instanceof JaxbDataFormat ) { dformatDefinition = augmentJaxbDataFormatDefinition( (JaxbDataFormat) dformatDefinition ); } else if ( dformatDefinition instanceof XStreamDataFormat ) { XStreamDataFormat xstreamDataFormat = (XStreamDataFormat) dformatDefinition; if ( "json".equals( xstreamDataFormat.getDriver() ) ) { dformatDefinition = XStreamJson.newJSonMarshaller( xstreamDataFormat );; } else { dformatDefinition = XStreamXml.newXStreamMarshaller( (XStreamDataFormat) dformatDefinition ); } } return dformatDefinition; }
Map<String, String[]> map = xstreamDataFormat.getImplicitCollections(); if ( map == null ) { map = new HashMap<String, String[]>(); xstreamDataFormat.setImplicitCollections( map ); List<String> converters = xstreamDataFormat.getConverters(); if ( converters == null ) { converters = new ArrayList<String>(); converters.add( QueryResultsConverter.class.getName() ); converters.add( FactHandleConverter.class.getName() ); xstreamDataFormat.setConverters( converters );
public static XStreamDataFormat newJSonMarshaller(XStreamDataFormat xstreamDataFormat) { xstreamDataFormat.setDriver( "json" ); xstreamDataFormat.getAliases().put( "commands", CommandsObjectContainer.class.getName() ); xstreamDataFormat.getAliases().put( "objects", ObjectsObjectContainer.class.getName() ); xstreamDataFormat.getAliases().put( "item", RowItemContainer.class.getName() ); xstreamDataFormat.getAliases().put( "parameters", ParameterContainer.class.getName() ); xstreamDataFormat.getAliases().put( "results", WorkItemResultsContainer.class.getName() ); List<String> converters = xstreamDataFormat.getConverters(); if ( converters == null ) { converters = new ArrayList<String>(); converters.add( JSonAbortWorkItemConverter.class.getName() ); xstreamDataFormat.setConverters( converters );
public static void setAliases(XStreamDataFormat dataFormat) { Map<String, String> map = dataFormat.getAliases(); if ( map == null ) { map = new HashMap<String, String>(); DefaultFactHandle.class.getName() ); dataFormat.setAliases( map );
@Override public void configure() throws Exception { org.apache.camel.model.dataformat.XStreamDataFormat xstreamDataFormat = new org.apache.camel.model.dataformat.XStreamDataFormat(); xstreamDataFormat.setConverters(Arrays.asList(new String[] {PersonConverter.class.getName()})); Map<String, DataFormatDefinition> dataFormats = new HashMap<String, DataFormatDefinition>(); dataFormats.put("custom-xstream", xstreamDataFormat); getContext().setDataFormats(dataFormats); from("direct:test-with-session").policy(new KiePolicy()).unmarshal("xstream").to("kie-local:ksession1").marshal("xstream"); from("direct:test-with-session-json").policy(new KiePolicy()).unmarshal("json").to("kie-local:ksession1").marshal("json"); from("direct:test-no-session").policy(new KiePolicy()).unmarshal("xstream").to("kie-local:dynamic").marshal("xstream"); from("direct:test-no-session-custom").policy(new KiePolicy()).unmarshal("custom-xstream").to("kie-local:dynamic").marshal("custom-xstream"); } };
@Override public void configure() throws Exception { org.apache.camel.model.dataformat.XStreamDataFormat xstreamDataFormat = new org.apache.camel.model.dataformat.XStreamDataFormat(); xstreamDataFormat.setConverters( Arrays.asList( new String[]{PersonConverter.class.getName()} ) ); Map<String, DataFormatDefinition> dataFormats = new HashMap<String, DataFormatDefinition>(); dataFormats.put( "custom-xstream", xstreamDataFormat ); getContext().setDataFormats( dataFormats ); from( "direct:test-with-session" ).policy( new DroolsPolicy() ).unmarshal( "xstream" ).to( "drools:node/ksession1" ).marshal( "xstream" ); from( "direct:test-with-session-json" ).policy( new DroolsPolicy() ).unmarshal( "json" ).to( "drools:node/ksession1" ).marshal( "json" ); from( "direct:test-no-session" ).policy( new DroolsPolicy() ).unmarshal( "xstream" ).to( "drools:node" ).marshal( "xstream" ); from( "direct:test-no-session-custom" ).policy( new DroolsPolicy() ).unmarshal( "custom-xstream" ).to( "drools:node" ).marshal( "custom-xstream" ); } };
public static void setAliases(XStreamDataFormat dataFormat) { Map<String, String> map = dataFormat.getAliases(); if ( map == null ) { map = new HashMap<String, String>(); DefaultFactHandle.class.getName() ); dataFormat.setAliases( map );
Map<String, String[]> map = xstreamDataFormat.getImplicitCollections(); if ( map == null ) { map = new HashMap<String, String[]>(); xstreamDataFormat.setImplicitCollections( map ); List<String> converters = xstreamDataFormat.getConverters(); if ( converters == null ) { converters = new ArrayList<String>(); converters.add( QueryResultsConverter.class.getName() ); converters.add( FactHandleConverter.class.getName() ); xstreamDataFormat.setConverters( converters );
public static XStreamDataFormat newJSonMarshaller(XStreamDataFormat xstreamDataFormat) { xstreamDataFormat.setDriver( "json" ); xstreamDataFormat.getAliases().put( "commands", CommandsObjectContainer.class.getName() ); xstreamDataFormat.getAliases().put( "objects", ObjectsObjectContainer.class.getName() ); xstreamDataFormat.getAliases().put( "item", RowItemContainer.class.getName() ); xstreamDataFormat.getAliases().put( "parameters", ParameterContainer.class.getName() ); xstreamDataFormat.getAliases().put( "results", WorkItemResultsContainer.class.getName() ); List<String> converters = xstreamDataFormat.getConverters(); if ( converters == null ) { converters = new ArrayList<String>(); converters.add( JSonAbortWorkItemConverter.class.getName() ); xstreamDataFormat.setConverters( converters );
private static DataFormatDefinition processDataFormatType(RouteContext routeContext, String ref, DataFormatDefinition dformatDefinition) { if ( dformatDefinition == null ) { if ( "json".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); ((XStreamDataFormat) dformatDefinition).setDriver( "json" ); } else if ( "xstream".equals( ref ) ) { dformatDefinition = new XStreamDataFormat(); } else if ( "jaxb".equals( ref ) ) { dformatDefinition = new JaxbDataFormat(); } else { dformatDefinition = routeContext.getCamelContext().resolveDataFormatDefinition( ref ); } } // always clone before changing dformatDefinition = new FastCloner().deepClone( dformatDefinition ); if ( dformatDefinition instanceof JaxbDataFormat ) { dformatDefinition = augmentJaxbDataFormatDefinition( (JaxbDataFormat) dformatDefinition ); } else if ( dformatDefinition instanceof XStreamDataFormat ) { XStreamDataFormat xstreamDataFormat = (XStreamDataFormat) dformatDefinition; if ( "json".equals( xstreamDataFormat.getDriver() ) ) { dformatDefinition = XStreamJson.newJSonMarshaller( xstreamDataFormat );; } else { dformatDefinition = XStreamXml.newXStreamMarshaller( (XStreamDataFormat) dformatDefinition ); } } return dformatDefinition; }