Java Code Examples for org.apache.camel.impl.DefaultCamelContext

The following examples show how to use org.apache.camel.impl.DefaultCamelContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: secure-data-service   Source File: TenantProcessorTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test to check that a single lz that is added to the
 * tenant collection is added by processor.
 *
 * @throws Exception
 */
@Test
public void shouldAddNewLz() throws Exception {

    List<String> testLzPaths = new ArrayList<String>();
    testLzPaths.add("."); // this must be a path that exists on all platforms
    when(mockedTenantDA.getLzPaths()).thenReturn(testLzPaths);

    // get a test tenantRecord
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    tenantProcessor.process(exchange);

    // check there is no error on the received message
    assertEquals("Header on exchange should indicate success", TenantProcessor.TENANT_POLL_SUCCESS, exchange
            .getIn().getHeader(TenantProcessor.TENANT_POLL_HEADER));
}
 
Example 2
Source Project: wildfly-camel   Source File: UndertowIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void overwriteDeploymentContextPathTest() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("undertow:http://localhost/test-servlet")
            .setBody(constant("Hello Kermit"));
        }
    });

    deployer.deploy(TEST_SERVLET_WAR);
    try {
        // Context start should fail as the undertow consumer path is already registered by test-servlet.war
        expectedException.expect(IllegalStateException.class);
        camelctx.start();
    } finally {
        camelctx.close();
        deployer.undeploy(TEST_SERVLET_WAR);
    }
}
 
Example 3
Source Project: wildfly-camel   Source File: CassandraIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeAll() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("cql://localhost/camel_ks?cql=" + CQL).to("seda:end");
        }
    });

    camelctx.start();
    try {
        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        List<?> result = consumer.receiveBody("seda:end", 3000, List.class);
        Assert.assertNotNull("Result not null", result);
        Assert.assertEquals("Two records selected", 2, result.size());
    } finally {
        camelctx.close();
    }
}
 
Example 4
Source Project: wildfly-camel   Source File: NettyIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNettyTcpSocket() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("netty:tcp://" + SOCKET_HOST + ":" + SOCKET_PORT + "?textline=true")
            .transform(simple("Hello ${body}"))
            .inOnly("seda:end");
        }
    });

    camelctx.start();
    try {
        PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
        pollingConsumer.start();

        Socket socket = new Socket(SOCKET_HOST, SOCKET_PORT);
        socket.setKeepAlive(true);
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

        try {
            out.write("Kermit\n");
        } finally {
            out.close();
            socket.close();
        }

        String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example 5
Source Project: camelinaction   Source File: QuartzExample.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create CamelContext
    CamelContext context = new DefaultCamelContext();

    // add our route to the CamelContext
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("quartz://myTimer?trigger.repeatInterval=2000&trigger.repeatCount=-1")
            .setBody().simple("I was fired at ${header.fireTime}")
            .to("stream:out");
        }
    });

    // start the route and let it do its work
    context.start();
    Thread.sleep(10000);

    // stop the CamelContext
    context.stop();
}
 
Example 6
@Test
public void testKubernetesFunction() {
    Runtime runtime = Runtime.on(new DefaultCamelContext());
    runtime.setProperties("my.property", "{{secret:my-secret/my-property}}");

    new PropertiesConfigurer().accept(runtime);

    assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:my-secret/my-property}}"))
        .isEqualTo("my-secret-property");
    assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property:my-default-secret}}"))
        .isEqualTo("my-default-secret");
    assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{secret:none/my-property}}"))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessageContaining("returned null value which is not allowed, from input");

    assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property}}")).isEqualTo("my-cm-property");
    assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:my-cm/my-property:my-default-cm}}"))
        .isEqualTo("my-default-cm");
    assertThatThrownBy(() -> runtime.getCamelContext().resolvePropertyPlaceholders("{{configmap:none/my-property}}"))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessageContaining("returned null value which is not allowed, from input");

    assertThat(runtime.getCamelContext().resolvePropertyPlaceholders("{{my.property}}")).isEqualTo("my-secret-property");
}
 
Example 7
Source Project: camel-cookbook-examples   Source File: DirectVmTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setupContexts() throws Exception {
    testHarnessContext = new DefaultCamelContext();
    testHarnessContext.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:in")
                .setHeader("harness.threadName", simple("${threadName}"))
                .to("direct-vm:logMessageToBackendSystem")
                .log("Completed logging");
        }
    });
    testHarnessContext.start();

    externalLoggingContext = new DefaultCamelContext();
    externalLoggingContext.addRoutes(new ExternalLoggingRoute("direct-vm"));
    externalLoggingContext.start();
}
 
Example 8
Source Project: syndesis   Source File: SwaggerProxyComponentTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSwaggerProxyComponent() throws Exception {
    CamelContext context = new DefaultCamelContext();
    ComponentProxyFactory factory = new ConnectorFactory();
    ComponentProxyComponent proxy = factory.newInstance("swagger-1", "rest-openapi");

    try {
        proxy.setCamelContext(context);
        proxy.start();

        Endpoint endpoint = proxy.createEndpoint("swagger-1:http://foo.bar");

        assertThat(endpoint).isInstanceOfSatisfying(DelegateEndpoint.class, e -> {
            assertThat(e.getEndpoint()).isInstanceOf(RestOpenApiEndpoint.class);
            assertThat(e.getEndpoint()).hasFieldOrPropertyWithValue("componentName", SyndesisRestSwaggerComponent.COMPONENT_NAME);
        });
    } finally {
        proxy.stop();
    }
}
 
Example 9
@Override
protected CamelContext createCamelContext() throws Exception {
    final String keyStorePassword = "keystorePassword";
    final String trustStorePassword = "truststorePassword";

    SimpleRegistry registry = new SimpleRegistry();

    KeyStore keyStore = KeyStore.getInstance("JKS"); // Java keystore

    ClassLoader classLoader = getClass().getClassLoader();
    log.info("Loading keystore from [{}]", classLoader.getResource("keystore.jks").toString());
    keyStore.load(classLoader.getResourceAsStream("keystore.jks"), keyStorePassword.toCharArray());
    registry.put("keyStore", keyStore);

    KeyStore trustStore = KeyStore.getInstance("JKS"); // Java keystore
    trustStore.load(classLoader.getResourceAsStream("truststore.jks"), trustStorePassword.toCharArray());
    registry.put("trustStore", trustStore);

    return new DefaultCamelContext(registry);
}
 
Example 10
Source Project: wildfly-camel   Source File: SimpleTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTransform() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").transform(body().prepend("Hello "));
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example 11
@Test
public void testTicker() throws Exception {

    try (CamelContext camelctx = new DefaultCamelContext()) {

        Assume.assumeTrue(checkAPIConnection());

        camelctx.addRoutes(createRouteBuilder());
        camelctx.start();

        ProducerTemplate template = camelctx.createProducerTemplate();
        Ticker ticker = template.requestBody("direct:ticker", CurrencyPair.EOS_ETH, Ticker.class);
        Assert.assertNotNull("Ticker not null", ticker);
        System.out.println(ticker);

        ticker = template.requestBodyAndHeader("direct:ticker", null, HEADER_CURRENCY_PAIR, CurrencyPair.EOS_ETH, Ticker.class);
        Assert.assertNotNull("Ticker not null", ticker);
        System.out.println(ticker);
    }
}
 
Example 12
Source Project: wildfly-camel   Source File: IPFSIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void ipfsCat() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("ipfs:cat");
        }
    });

    camelctx.start();
    try {
        assumeIPFSAvailable(camelctx);

        ProducerTemplate producer = camelctx.createProducerTemplate();
        InputStream res = producer.requestBody("direct:start", SINGLE_HASH, InputStream.class);
        verifyFileContent(res);
    } finally {
        camelctx.close();
    }
}
 
Example 13
Source Project: wildfly-camel   Source File: FastHeadersIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        public void configure() throws Exception {
            from("direct:start").to("log:foo").to("log:bar").to("mock:result");
        }
    });

    MockEndpoint mockResult = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockResult.expectedBodiesReceived("Hello World");

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", "Hello World");

        mockResult.assertIsSatisfied();

        HeadersMapFactory factory = camelctx.adapt(ExtendedCamelContext.class).getHeadersMapFactory();
        Assert.assertTrue("Instance of FastHeadersMapFactory", factory instanceof FastHeadersMapFactory);
    } finally {
        camelctx.close();
    }
}
 
Example 14
Source Project: syndesis   Source File: OnExceptionHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testErrorStatusInfoResponse() {
 
    String expectedBody = "{\"httpResponseCode\":404,\"category\":\"ENTITY_NOT_FOUND_ERROR\",\"message\":\"entity not found\",\"error\":\"syndesis_connector_error\"}";

    Map<String,String> configuredProperties = new HashMap<>();
    configuredProperties.put(HTTP_RESPONSE_CODE_PROPERTY       , "200");
    configuredProperties.put(HTTP_ERROR_RESPONSE_CODES_PROPERTY, ERROR_RESPONSE_CODES);
    configuredProperties.put(ERROR_RESPONSE_BODY               , "true");

    Exception e = new SyndesisConnectorException(
            "ENTITY_NOT_FOUND_ERROR", "entity not found");

    Exchange exchange = new ExchangeBuilder(new DefaultCamelContext()).build();
    exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);

    ApiProviderOnExceptionHandler handler = new ApiProviderOnExceptionHandler();
    handler.setProperties(configuredProperties);
    handler.process(exchange);

    Message in = exchange.getIn();
    Assert.assertEquals(Integer.valueOf(404),in.getHeader(Exchange.HTTP_RESPONSE_CODE));
    Assert.assertEquals(expectedBody        ,in.getBody());

}
 
Example 15
Source Project: wildfly-camel   Source File: MvelTransformTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTransformFromModule() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mvel:template.mvel");
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.close();
    }
}
 
Example 16
@Test
@SuppressWarnings("unchecked")
public void testCurrencies() throws Exception {

    try (CamelContext camelctx = new DefaultCamelContext()) {

        Assume.assumeTrue(checkAPIConnection());

        camelctx.addRoutes(createRouteBuilder());
        camelctx.start();

        ProducerTemplate template = camelctx.createProducerTemplate();
        List<Currency> currencies = template.requestBody("direct:currencies", null, List.class);
        Assert.assertNotNull("Currencies not null", currencies);
        Assert.assertTrue("Contains ETH", currencies.contains(Currency.ETH));
    }
}
 
Example 17
Source Project: wildfly-camel   Source File: XStreamIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMarshal() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal().xstream();
        }
    });

    String expected = wrapWithType(XML_STRING, Customer.class);

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String customer = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertTrue("Contains " + expected + ": " + customer, customer.contains(expected));
    } finally {
        camelctx.close();
    }
}
 
Example 18
Source Project: wildfly-camel   Source File: AhcWSSIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncWssRoute() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("ahc-wss:" + WEBSOCKET_ENDPOINT);
            from("ahc-wss:" + WEBSOCKET_ENDPOINT).to("seda:end");
        }
    });

    WsComponent wsComponent = (WsComponent) camelctx.getComponent("ahc-wss");
    wsComponent.setSslContextParameters(defineSSLContextClientParameters());

    PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    consumer.start();

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        producer.sendBody("direct:start", "Kermit");

        Exchange exchange = consumer.receive(1000);
        Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class));

    } finally {
        camelctx.close();
    }
}
 
Example 19
Source Project: syndesis   Source File: HttpConnectorVerifierTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBaseUrlWithScheme() throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.disableJMX();
        context.start();

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("baseUrl", "http://" + getLocalServerHostAndPort());

        Verifier verifier = new HttpVerifier();
        List<VerifierResponse> responses = verifier.verify(context, "http", parameters);

        assertThat(responses).hasSize(2);
        assertThat(responses).anyMatch(response -> response.getScope() == Verifier.Scope.CONNECTIVITY);
        assertThat(responses).anyMatch(response -> response.getScope() == Verifier.Scope.PARAMETERS);
        assertThat(responses).allMatch(response -> response.getStatus() == Verifier.Status.OK);
    } finally {
        context.stop();
    }
}
 
Example 20
@Test
public void testJCacheLoadsCachingProviderEhcache() throws Exception {
	
    try (CamelContext camelctx = new DefaultCamelContext()) {
    	
        camelctx.addRoutes(new RouteBuilder() {
            public void configure() {
                from("jcache://test-cacheB?cachingProvider=org.ehcache.jsr107.EhcacheCachingProvider")
                .to("mock:resultB");
            }
        });
        
        // Just ensure we can start up without any class loading issues
        camelctx.start();
    }
}
 
Example 21
Source Project: wildfly-camel   Source File: IPFSIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void ipfsAddSingle() throws Exception {

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("ipfs:add");
        }
    });


    camelctx.start();
    try {
        assumeIPFSAvailable(camelctx);

        Path path = Paths.get("src/test/resources/ipfs/etc/userfile.txt");
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String res = producer.requestBody("direct:start", path, String.class);
        Assert.assertEquals(SINGLE_HASH, res);
    } finally {
        camelctx.close();
    }
}
 
Example 22
@Test
public void testMarshalYaml() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .marshal().yaml(YAMLLibrary.SnakeYAML);
        }
    });

    ClassLoader loader = SnakeYAMLDataFormat.class.getClassLoader();
    loader = loader.loadClass("org.yaml.snakeyaml.Yaml").getClassLoader();
    System.out.println(loader);
    
    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        String result = template.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertEquals(CUSTOMER_YAML, result.trim());
    } finally {
        camelctx.close();
    }
}
 
Example 23
@Test
void getProcessortConfigurationShouldReturnEmptyWhenNoContextSection() throws Exception {
    ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
    when(configurationProvider.getConfiguration("mailetcontainer"))
        .thenReturn(new BaseHierarchicalConfiguration());
    XMLConfiguration defaultConfiguration = FileConfigurationProvider.getConfig(new ByteArrayInputStream((
            "<processors>" +
            "  <key>value</key>" +
            "</processors>")
        .getBytes(StandardCharsets.UTF_8)));

    MailetModuleInitializationOperation testee = new MailetModuleInitializationOperation(configurationProvider,
        mock(CamelCompositeProcessor.class),
        NO_TRANSPORT_CHECKS,
        () -> defaultConfiguration,
        mock(DefaultCamelContext.class));

    assertThat(testee.getProcessorConfiguration())
        .isEqualTo(defaultConfiguration);
}
 
Example 24
Source Project: wildfly-camel   Source File: Olingo4IntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
private CamelContext createCamelContext() throws Exception {

        final CamelContext context = new DefaultCamelContext();

        Map<String, Object> options = new HashMap<String, Object>();
        options.put("serviceUri", getRealServiceUrl(TEST_SERVICE_BASE_URL));
        options.put("contentType", "application/json;charset=utf-8");

        final Olingo4Configuration configuration = new Olingo4Configuration();
        IntrospectionSupport.setProperties(configuration, options);

        // add OlingoComponent to Camel context
        final Olingo4Component component = new Olingo4Component(context);
        component.setConfiguration(configuration);
        context.addComponent("olingo4", component);

        return context;
    }
 
Example 25
Source Project: camelinaction   Source File: FtpToJMSExample.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create CamelContext
    CamelContext context = new DefaultCamelContext();
    
    // connect to embedded ActiveMQ JMS broker
    ConnectionFactory connectionFactory = 
        new ActiveMQConnectionFactory("vm://localhost");
    context.addComponent("jms",
        JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

    // add our route to the CamelContext
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() {
            from("ftp://rider.com/orders?username=rider&password=secret").to("jms:incomingOrders");
        }
    });

    // start the route and let it do its work
    context.start();
    Thread.sleep(10000);

    // stop the CamelContext
    context.stop();
}
 
Example 26
Source Project: camelinaction   Source File: TimerExample.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    // create CamelContext
    CamelContext context = new DefaultCamelContext();

    // add our route to the CamelContext
    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("timer://myTimer?period=2000")
            .setBody().simple("Current time is ${header.firedTime}")
            .to("stream:out");
        }
    });

    // start the route and let it do its work
    context.start();
    Thread.sleep(5000);

    // stop the CamelContext
    context.stop();
}
 
Example 27
Source Project: wildfly-camel   Source File: ProtobufIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUnmarshall() throws Exception {

    final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(format);
        }
    });

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Person person = Person.newBuilder().setId(1).setName("John Doe").build();
    person.writeTo(baos);

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Person result = producer.requestBody("direct:start", baos.toByteArray(), Person.class);
        Assert.assertEquals("John Doe", result.getName().trim());
    } finally {
        camelctx.close();
    }
}
 
Example 28
@Test
public void testUnmarshalBindy() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.addRoutes(createRoute());
    context.start();

    MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);

    ProducerTemplate template = context.createProducerTemplate();
    template.sendBody("direct:toObject", "Camel in Action,39.95,1");

    mock.assertIsSatisfied();

    // bindy returns the order directly (not in a list) if there is only one element
    PurchaseOrder order = mock.getReceivedExchanges().get(0).getIn().getBody(PurchaseOrder.class);
    assertNotNull(order);

    // assert the order contains the expected data
    assertEquals("Camel in Action", order.getName());
    assertEquals("39.95", order.getPrice().toString());
    assertEquals(1, order.getAmount());
}
 
Example 29
Source Project: camelinaction   Source File: HttpServer.java    License: Apache License 2.0 6 votes vote down vote up
public void server() throws Exception {
    CamelContext camel = new DefaultCamelContext();
    camel.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("jetty:" + url)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        String body = exchange.getIn().getBody(String.class);

                        System.out.println("Received message: " + body);

                        if (body != null && body.contains("Kabom")) {
                            throw new Exception("ILLEGAL DATA");
                        }
                        exchange.getOut().setBody("OK");
                    }
                });
        }
    });
    camel.start();

}
 
Example 30
Source Project: syndesis   Source File: ODataMetaDataRetrievalTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testReadFromMetaDataRetrieval() throws Exception {
    CamelContext context = new DefaultCamelContext();
    ODataMetaDataRetrieval retrieval = new ODataMetaDataRetrieval();

    String resourcePath = "Products";

    Map<String, Object> parameters = new HashMap<>();
    parameters.put(SERVICE_URI, defaultTestServer.servicePlainUri());
    parameters.put(RESOURCE_PATH, resourcePath);

    String componentId = "odata";
    String actionId = "io.syndesis:" + Methods.READ.actionIdentifierRoot() + HYPHEN + FROM;

    SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
    assertNotNull(metadata);

    Map<String, List<PropertyPair>> properties = metadata.getProperties();
    assertFalse(properties.isEmpty());

    //
    // The method names are important for collecting prior
    // to the filling in of the integration step (values such as resource etc...)
    //
    List<PropertyPair> resourcePaths = properties.get(RESOURCE_PATH);
    assertNotNull(resourcePaths);
    assertFalse(resourcePaths.isEmpty());

    PropertyPair pair = resourcePaths.get(0);
    assertNotNull(pair);
    assertEquals(resourcePath, pair.getValue());

    //
    // The out data shape is defined after the integration step has
    // been populated and should be a dynamic json-schema based
    // on the contents of the OData Edm metadata object.
    //
    checkTestServerSchemaMap(checkShape(metadata.outputShape, ArraySchema.class));
}