org.apache.camel.builder.ExchangeBuilder Java Examples

The following examples show how to use org.apache.camel.builder.ExchangeBuilder. 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 File: OnExceptionHandlerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyResponseBodyOnError() {
 
    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               , "false");

    Exception e = new SyndesisConnectorException(
            "CONNECTOR_ERROR", "error msg test");

    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new ExchangeBuilder(context).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(500)             ,in.getHeader(Exchange.HTTP_RESPONSE_CODE));
    Assert.assertEquals(""                               ,in.getBody());
}
 
Example #2
Source File: OnExceptionHandlerTest.java    From syndesis with 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 #3
Source File: RestDslPostTest.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiplePostTypes() throws Exception {

    UserPojo user = new UserPojo();
    user.setId(1);
    user.setName("My Name");
    resultEndpointUser.expectedBodiesReceived(user);
    resultEndpointUser.expectedMessageCount(1);

    CountryPojo country = new CountryPojo();
    country.setCountry("England");
    country.setIso("EN");
    resultEndpointCountry.expectedBodiesReceived(country);
    resultEndpointCountry.expectedMessageCount(1);

    ExchangeBuilder builder = ExchangeBuilder.anExchange(context)
            .withHeader(Exchange.HTTP_METHOD, HttpMethod.POST)
            .withHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.APPLICATION_JSON);
    Exchange outExchangeUser = builder.withBody("{\"id\": 1, \"name\": \"My Name\"}").build();
    Exchange outExchangeCountry = builder.withBody("{\"iso\": \"EN\", \"country\": \"England\"}").build();

    template.send("http://localhost:" + PORT + "/user", outExchangeUser);
    template.send("http://localhost:" + PORT + "/country", outExchangeCountry);

    resultEndpointCountry.assertIsSatisfied();
    resultEndpointUser.assertIsSatisfied();

}
 
Example #4
Source File: SESIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void sendSimpleMessage() throws Exception {

    AmazonSimpleEmailServiceClient sesClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sesClient);

    WildFlyCamelContext camelctx = new WildFlyCamelContext();
    camelctx.getNamingContext().bind("sesClient", sesClient);

    camelctx.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:start")
            .to("aws-ses://" + SESUtils.FROM + "?amazonSESClient=#sesClient");
        }
    });

    camelctx.start();
    try {
        Exchange exchange = ExchangeBuilder.anExchange(camelctx)
                .withHeader(SesConstants.SUBJECT, SESUtils.SUBJECT)
                .withHeader(SesConstants.TO, Collections.singletonList(SESUtils.TO))
                .withBody("Hello world!")
                .build();

        ProducerTemplate producer = camelctx.createProducerTemplate();
        Exchange result = producer.send("direct:start", exchange);

        String messageId = result.getIn().getHeader(SesConstants.MESSAGE_ID, String.class);
        Assert.assertNotNull("MessageId not null", messageId);

    } finally {
        camelctx.close();
    }
}
 
Example #5
Source File: DynamoDBUtils.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public static Map<?, ?> getItem(CamelContext camelctx) {
    HashMap<String, AttributeValue> key = new HashMap<>();
    key.put("Id", new AttributeValue().withN("103"));

    Exchange exchange = new ExchangeBuilder(camelctx)
            .withHeader(DdbConstants.OPERATION, DdbOperations.GetItem)
            .withHeader(DdbConstants.KEY, key).build();

    ProducerTemplate producer = camelctx.createProducerTemplate();
    producer.send("direct:start", exchange);
    Assert.assertNull(exchange.getException());

    return exchange.getIn().getHeader(DdbConstants.ATTRIBUTES, Map.class);
}