Java 类org.apache.camel.model.DataFormatDefinition 实例源码

项目:Camel    文件:DozerProducer.java   
/**
 * Find and configure an unmarshaller for the specified data format.
 */
private synchronized UnmarshalProcessor resolveUnmarshaller(
        Exchange exchange, String dataFormatId) throws Exception {

    if (unmarshaller == null) {
        DataFormat dataFormat = DataFormatDefinition.getDataFormat(
                exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
        if (dataFormat == null) {
            throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId);
        }

        // Wrap the data format in a processor and start/configure it.  
        // Stop/shutdown is handled when the corresponding methods are 
        // called on this producer.
        unmarshaller = new UnmarshalProcessor(dataFormat);
        unmarshaller.setCamelContext(exchange.getContext());
        unmarshaller.start();
    }
    return unmarshaller;
}
项目:Camel    文件:DozerProducer.java   
/**
 * Find and configure an unmarshaller for the specified data format.
 */
private synchronized MarshalProcessor resolveMarshaller(
        Exchange exchange, String dataFormatId) throws Exception {

    if (marshaller == null) {
        DataFormat dataFormat = DataFormatDefinition.getDataFormat(
                exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
        if (dataFormat == null) {
            throw new Exception("Unable to resolve data format for marshalling: " + dataFormatId);
        }

        // Wrap the data format in a processor and start/configure it.  
        // Stop/shutdown is handled when the corresponding methods are 
        // called on this producer.
        marshaller = new MarshalProcessor(dataFormat);
        marshaller.setCamelContext(exchange.getContext());
        marshaller.start();
    }
    return marshaller;
}
项目:switchyard    文件:RouteFactory.java   
private static List<RouteDefinition> processCamelContextElement(CamelContextFactoryBean camelContextFactoryBean, SwitchYardCamelContext camelContext) throws Exception {
    if (camelContext != null) {
        if (camelContextFactoryBean.getEndpoints() != null) {
            // processing camelContext/endpoint
            for (CamelEndpointFactoryBean epBean : camelContextFactoryBean.getEndpoints()) {
                epBean.setCamelContext(camelContext);
                camelContext.getWritebleRegistry().put(epBean.getId(), epBean.getObject());
            }
        }
        if (camelContextFactoryBean.getDataFormats() != null) {
            // processing camelContext/dataFormat
            for (DataFormatDefinition dataFormatDef : camelContextFactoryBean.getDataFormats().getDataFormats()) {
                camelContext.getDataFormats().put(dataFormatDef.getId(), dataFormatDef);
            }
        }
    }
    return camelContextFactoryBean.getRoutes();
}
项目:fuse-bxms-integ    文件:CamelEndpointWithMarshallersTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @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:ksession1").marshal("xstream");
            from("direct:test-with-session-json").policy(new KiePolicy()).unmarshal("json").to("kie:ksession1").marshal("json");
            from("direct:test-no-session").policy(new KiePolicy()).unmarshal("xstream").to("kie:dynamic").marshal("xstream");
            from("direct:test-no-session-custom").policy(new KiePolicy()).unmarshal("custom-xstream").to("kie:dynamic").marshal("custom-xstream");
        }
    };
}
项目:Camel    文件:DataFormatsDefinition.java   
/***
 * @return A Map of the contained DataFormatType's indexed by id.
 */
public Map<String, DataFormatDefinition> asMap() {
    Map<String, DataFormatDefinition> dataFormatsAsMap = new HashMap<String, DataFormatDefinition>();
    for (DataFormatDefinition dataFormatType : getDataFormats()) {
        dataFormatsAsMap.put(dataFormatType.getId(), dataFormatType);
    }
    return dataFormatsAsMap;
}
项目:Camel    文件:DefaultCamelContext.java   
public DataFormatDefinition resolveDataFormatDefinition(String name) {
    // lookup type and create the data format from it
    DataFormatDefinition type = lookup(this, name, DataFormatDefinition.class);
    if (type == null && getDataFormats() != null) {
        type = getDataFormats().get(name);
    }
    return type;
}
项目:Camel    文件:DataFormatClause.java   
@SuppressWarnings("unchecked")
private T dataFormat(DataFormatDefinition dataFormatType) {
    switch (operation) {
    case Unmarshal:
        return (T) processorType.unmarshal(dataFormatType);
    case Marshal:
        return (T) processorType.marshal(dataFormatType);
    default:
        throw new IllegalArgumentException("Unknown DataFormat operation: " + operation);
    }
}
项目:Camel    文件:CamelGroovyMethods.java   
private static ProcessorDefinition<?> dataFormat(DataFormatClause<?> self,
        DataFormatDefinition format) {
    try {
        Method m = self.getClass().getDeclaredMethod("dataFormat", DataFormatDefinition.class);
        m.setAccessible(true);
        return (ProcessorDefinition<?>) m.invoke(self, format);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unknown DataFormat operation", e);
    }
}
项目:switchyard    文件:CamelContextConfiguratorTest.java   
@Test
public void configureCamelContextXML() throws Exception {
    domain.setProperty(CamelContextConfigurator.CAMEL_CONTEXT_CONFIG_XML, PATH_CAMEL_CONTEXT_XML);

    Assert.assertNull(context.getProperty("abc"));
    Assert.assertNotEquals("foobar-camel-context", context.getName());
    Assert.assertEquals(false, context.isUseMDCLogging());
    Assert.assertEquals(ManagementStatisticsLevel.All
            , context.getManagementStrategy().getStatisticsLevel());
    Assert.assertEquals(true, context.isAllowUseOriginalMessage());
    Assert.assertEquals(false, context.isStreamCaching());

    context.start();

    Assert.assertNotNull(context.getProperty("abc"));
    Assert.assertEquals("xyz", context.getProperty("abc"));
    Assert.assertEquals("foobar-camel-context", context.getName());
    Assert.assertEquals(true, context.isUseMDCLogging());
    Assert.assertEquals(ManagementStatisticsLevel.RoutesOnly
            , context.getManagementStrategy().getStatisticsLevel());
    Assert.assertEquals(false, context.isAllowUseOriginalMessage());
    Assert.assertEquals(true, context.isStreamCaching());
    DataFormatDefinition dfd = context.getDataFormats().get("transform-json");
    Assert.assertNotNull(dfd);
    Assert.assertEquals("json-jackson", dfd.getDataFormatName());
    Assert.assertTrue(dfd instanceof JsonDataFormat);

    MockEndpoint mock = context.getEndpoint("mock:output", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("foobar-input");
    context.createProducerTemplate().sendBody("direct:input", "foobar-input");
    mock.assertIsSatisfied();

}
项目:switchyard    文件:DomainCamelContextConfigurationTest.java   
@Test
public void testConfiguration() throws Exception {
    Assert.assertNotNull(_camelContext.getProperty("abc"));
    Assert.assertEquals("xyz", _camelContext.getProperty("abc"));
    Assert.assertEquals("foobar-camel-context", _camelContext.getName());
    Assert.assertEquals(true, _camelContext.isUseMDCLogging());
    Assert.assertEquals(ManagementStatisticsLevel.RoutesOnly
            , _camelContext.getManagementStrategy().getStatisticsLevel());
    Assert.assertEquals(false, _camelContext.isAllowUseOriginalMessage());
    Assert.assertEquals(true, _camelContext.isStreamCaching());
    DataFormatDefinition dfd = _camelContext.getDataFormats().get("transform-json");
    Assert.assertNotNull(dfd);
    Assert.assertEquals("json-jackson", dfd.getDataFormatName());
    Assert.assertTrue(dfd instanceof JsonDataFormat);

    MockEndpoint mock = _camelContext.getEndpoint("mock:output", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("foobar-input");
    _camelContext.createProducerTemplate().sendBody("direct:input", "foobar-input");
    mock.assertIsSatisfied();

    // CamelContext should be able to find CDI beans produced by this class from registry.
    Assert.assertEquals(true, _camelContext.isTracing());
    DefaultTraceFormatter formatter =
            (DefaultTraceFormatter) ((Tracer)_camelContext.getDefaultTracer()).getFormatter();
    Assert.assertEquals(false, formatter.isShowBody());
    Assert.assertEquals(false, formatter.isShowBreadCrumb());
    Assert.assertEquals(100, formatter.getMaxChars());

    @SuppressWarnings("deprecation")
    ErrorHandlerBuilder builder = _camelContext.getErrorHandlerBuilder();
    Assert.assertEquals(ErrorHandlerBuilderRef.class, builder.getClass());
    Assert.assertEquals("foobarErrorHandler", ((ErrorHandlerBuilderRef)builder).getRef());
}
项目:cleverbus    文件:AsynchRouteBuilder.java   
private AsynchRouteBuilder(String inUri, ServiceExtEnum serviceType, String operation,
        AsynchResponseProcessor responseProcessor, DataFormatDefinition responseMarshalling) {
    Assert.hasText(operation, "the operation must not be empty");
    Assert.notNull(inUri, "the inUri must not be empty");
    Assert.notNull(serviceType, "the serviceType must not be null");
    Assert.notNull(responseProcessor, "the responseProcessor must not be null");
    Assert.notNull(responseMarshalling, "the responseMarshalling must not be null");

    this.inUri = inUri;
    this.serviceType = serviceType;
    this.operation = operation;
    this.responseProcessor = responseProcessor;
    this.responseMarshalling = responseMarshalling;
}
项目:cleverbus    文件:AsynchRouteBuilder.java   
/**
 * Sets response processor. If not set then general response {@link AsynchResponse} will be used.
 *
 * @param responseProcessor   the response processor
 * @param responseMarshalling the response marshalling
 */
public AsynchRouteBuilder withResponseProcessor(AsynchResponseProcessor responseProcessor,
        DataFormatDefinition responseMarshalling) {
    Assert.notNull(responseProcessor, "the responseProcessor must not be null");
    Assert.notNull(responseMarshalling, "the responseMarshalling must not be null");

    this.responseProcessor = responseProcessor;
    this.responseMarshalling = responseMarshalling;
    return this;
}
项目:Camel    文件:CustomDataFormat.java   
@Override
protected DataFormat createDataFormat(RouteContext routeContext) {
    return DataFormatDefinition.getDataFormat(routeContext, null, ref);
}
项目:Camel    文件:DataFormatsDefinition.java   
/**
 * A list holding the configured data formats
 */
public void setDataFormats(List<DataFormatDefinition> dataFormats) {
    this.dataFormats = dataFormats;
}
项目:Camel    文件:DataFormatsDefinition.java   
public List<DataFormatDefinition> getDataFormats() {
    return dataFormats;
}
项目:Camel    文件:DefaultCamelContext.java   
public void setDataFormats(Map<String, DataFormatDefinition> dataFormats) {
    this.dataFormats = dataFormats;
}
项目:Camel    文件:DefaultCamelContext.java   
public Map<String, DataFormatDefinition> getDataFormats() {
    return dataFormats;
}
项目:Camel    文件:Activator.java   
public DataFormatDefinition resolveDataFormatDefinition(String name, CamelContext context) {
    return null;
}
项目:Camel    文件:CamelNamespaceHandler.java   
private void findDataFormat(DataFormatDefinition dfd, Set<String> dataformats) {
    if (dfd != null && dfd.getDataFormatName() != null) {
        dataformats.add(dfd.getDataFormatName());
    }
}
项目:Camel    文件:CamelGroovyMethods.java   
private static DataFormatDefinition slurper(boolean namespaceAware) {
    return new DataFormatDefinition(new XmlSlurperDataFormat(namespaceAware));
}
项目:Camel    文件:CamelGroovyMethods.java   
private static DataFormatDefinition parser(boolean namespaceAware) {
    return new DataFormatDefinition(new XmlParserDataFormat(namespaceAware));
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
@Deprecated
public void setDataFormats(Map<String, DataFormatDefinition> dataFormats) {
  context.setDataFormats(dataFormats);
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
@Deprecated
public Map<String, DataFormatDefinition> getDataFormats() {
  return context.getDataFormats();
}
项目:microservice-bundle    文件:ManagedCamelContext.java   
@Override
@Deprecated
public DataFormatDefinition resolveDataFormatDefinition(String name) {
  return context.resolveDataFormatDefinition(name);
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
@Deprecated
public void setDataFormats(Map<String, DataFormatDefinition> dataFormats) {
    context.setDataFormats(dataFormats);
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
@Deprecated
public Map<String, DataFormatDefinition> getDataFormats() {
    return context.getDataFormats();
}
项目:dropwizard-camel    文件:ManagedCamelContext.java   
@Override
@Deprecated
public DataFormatDefinition resolveDataFormatDefinition(String name) {
    return context.resolveDataFormatDefinition(name);
}
项目:cleverbus    文件:AsynchRouteBuilder.java   
@Nullable
public DataFormatDefinition getResponseMarshalling() {
    return responseMarshalling;
}
项目:Camel    文件:CamelContext.java   
/**
 * Sets the data formats that can be referenced in the routes.
 *
 * @param dataFormats the data formats
 */
void setDataFormats(Map<String, DataFormatDefinition> dataFormats);
项目:Camel    文件:CamelContext.java   
/**
 * Gets the data formats that can be referenced in the routes.
 *
 * @return the data formats available
 */
Map<String, DataFormatDefinition> getDataFormats();
项目:Camel    文件:CamelContext.java   
/**
 * Resolve a data format definition given its name
 *
 * @param name the data format definition name or a reference to it in the {@link Registry}
 * @return the resolved data format definition, or <tt>null</tt> if not found
 */
DataFormatDefinition resolveDataFormatDefinition(String name);
项目:cleverbus    文件:AsynchRouteBuilder.java   
/**
 * Creates new instance with basic mandatory parameters.
 *
 * @param serviceType service type
 * @param operation operation name with processing route
 * @param inUri the from URI of this route
 * @param responseProcessor the response processor
 * @param responseMarshalling the response marshalling
 * @return new instance
 */
public static AsynchRouteBuilder newInstance(ServiceExtEnum serviceType, String operation, String inUri,
        AsynchResponseProcessor responseProcessor, DataFormatDefinition responseMarshalling) {
    return new AsynchRouteBuilder(inUri, serviceType, operation, responseProcessor, responseMarshalling);
}