public Book sendFindBookRequest( ProducerTemplate template, String endpointUri, String operation, String body) throws Exception { Book response = (Book) template.requestBodyAndHeader(endpointUri, body, "ROUTE_DISPATCH_KEY", operation); return response; }
@Test public void testSqlIdempotentConsumer() throws Exception { Assert.assertNotNull("DataSource not null", dataSource); final JdbcMessageIdRepository jdbcMessageIdRepository = new JdbcMessageIdRepository(dataSource, "myProcessorName"); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .idempotentConsumer(simple("${header.messageId}"), jdbcMessageIdRepository) .to("mock:result"); } }); camelctx.start(); try { MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedMessageCount(1); // Send 5 messages with the same messageId header. Only 1 should be forwarded to the // mock:result endpoint ProducerTemplate template = camelctx.createProducerTemplate(); for (int i = 0; i < 5; i++) { template.requestBodyAndHeader("direct:start", null, "messageId", "12345"); } mockEndpoint.assertIsSatisfied(); } finally { camelctx.stop(); } }
@Test public void testInvalidCredentials() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .policy(new DomainAuthorizationPolicy()) .transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); try { Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, "bogus"); producer.requestBodyAndHeader( "direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.fail("CamelExecutionException expected"); } catch (CamelExecutionException e) { // expected } } finally { camelctx.stop(); } }
@Test public void testRoleBasedAccess() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .policy(new DomainAuthorizationPolicy().roles("Role2")) .transform(body().prepend("Hello ")); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD); String result = producer.requestBodyAndHeader( "direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.stop(); } }
@Test public void testPlaceOrder() throws Exception { String xmlReq = OrderTestUtils.orderXmlReq(); // ProducerTemplate producer = camelContext.createProducerTemplate(); // service side has duplicated check logic by using messageId String messageId = String.valueOf(getRandomNumber(5)); String respMsg = producer.requestBodyAndHeader("direct:order", xmlReq, "messageId", messageId, String.class); // Thread.sleep(5000); // ConsumerTemplate consumer = camelContext.createConsumerTemplate(); // String respMsg = consumer.receiveBody( // "jms:queue:bookStoreOrderOutbound?jmsMessageType=Text", // String.class); LOGGER.info("respmsg$$$$$$$$$$$$$$$$:{}", respMsg); }
public String sendAddToCatalogRequest( ProducerTemplate template, String endpointUri, String operation, Book book) throws Exception { String response = (String) template.requestBodyAndHeader(endpointUri, book, "ROUTE_DISPATCH_KEY", operation); return response; }