Java 类org.apache.camel.builder.ExchangeBuilder 实例源码

项目:camel-springboot    文件:PostTest.java   
@Test
public void testMultiplePostTypes() throws Exception {

    UserApiPojo user = new UserApiPojo("My Name", 21);
    resultEndpointUser.expectedBodiesReceived(user);
    resultEndpointUser.expectedMessageCount(1);

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

    //Send a message to each post endpoint
    ExchangeBuilder builder = ExchangeBuilder.anExchange(context)
            .withHeader(Exchange.HTTP_METHOD, HttpMethod.POST)
            .withHeader(Exchange.CONTENT_TYPE, MediaType.APPLICATION_JSON)
            .withHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.APPLICATION_JSON);
    Exchange outExchangeUser = builder.withBody("{\"age\": 21, \"name\": \"My Name\"}").build();
    Exchange outExchangeCountry = builder.withBody("{\"iso\": \"EN\", \"country\": \"England\"}").build();

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

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

}
项目:Camel    文件:SedaErrorTest.java   
@Test
public void testErrorHandle() throws InterruptedException {
    MockEndpoint mockDLC = getMockEndpoint("mock:dlc");
    mockDLC.expectedMessageCount(1);

    for (int i = 0; i < 3; i++) {
        template.send("direct:start", ExchangeBuilder.anExchange(context).withBody("msg" + i).build());
    }

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:JcrProducerSubNodeTest.java   
@Test
public void testCreateNodeAndSubNode() throws Exception {
    Session session = openSession();

    try {
        // create node
        Exchange exchange1 = ExchangeBuilder.anExchange(context)
            .withHeader(JcrConstants.JCR_NODE_NAME, "node")
            .build();
        Exchange out1 = template.send("direct:a", exchange1);
        assertNotNull(out1);
        String uuidNode = out1.getOut().getBody(String.class);

        Node node = session.getNodeByIdentifier(uuidNode);
        assertNotNull(node);
        assertEquals("/home/test/node", node.getPath());

        // create sub node
        Exchange exchange2 = ExchangeBuilder.anExchange(context)
            .withHeader(JcrConstants.JCR_NODE_NAME, "node/subnode")
            .build();
        Exchange out2 = template.send("direct:a", exchange2);
        assertNotNull(out2);
        String uuidSubNode = out2.getOut().getBody(String.class);

        Node subNode = session.getNodeByIdentifier(uuidSubNode);
        assertNotNull(subNode);
        assertEquals("/home/test/node/subnode", subNode.getPath());
        assertNotNull(subNode.getParent());
        assertEquals("/home/test/node", subNode.getParent().getPath());
    } finally {
        if (session != null && session.isLive()) {
            session.logout();
        }
    }
}
项目:wildfly-camel    文件:SESIntegrationTest.java   
@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.stop();
    }
}
项目:wildfly-camel    文件:DynamoDBUtils.java   
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);
}