Java 类org.apache.camel.model.dataformat.JsonDataFormat 实例源码

项目:openex-worker    文件:OpenexContext.java   
private void createContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("openexRouter", new OpenexRouter());
    registry.put("openexStrategy", new OpenexAggregationStrategy());
    registry.put("openexCallback", new OpenexCallbackBuilder());
    context.setRegistry(registry);
    context.addComponent("properties", buildPropertiesComponent());
    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfileRemote());
    context.getExecutorServiceManager().registerThreadPoolProfile(threadPoolProfileExecutor());
    context.setTracing(true);

    //Populate data formats
    JsonDataFormat jsonDataFormat = new JsonDataFormat(JsonLibrary.Gson);
    jsonDataFormat.setUseList(true);
    context.setDataFormats(Collections.singletonMap("json", jsonDataFormat));

    //Rest direct call routes
    InputStream defaultRoutesStream = getClass().getResourceAsStream("routes.xml");
    context.addRouteDefinitions(context.loadRoutesDefinition(defaultRoutesStream).getRoutes());

    //Dynamic routes building
    for (Executor executor : workerRegistry.workers().values()) {
        registerCamelModule(executor);
    }

    //Starting context
    context.start();
}
项目: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());
}
项目:Camel    文件:DataFormatClause.java   
/**
 * Uses the JSON data format using the XStream json library
 */
public T json() {
    return dataFormat(new JsonDataFormat());
}
项目:Camel    文件:DataFormatClause.java   
/**
 * Uses the JSON data format
 *
 * @param library the json library to use
 */
public T json(JsonLibrary library) {
    return dataFormat(new JsonDataFormat(library));
}