org.apache.camel.PollingConsumer Java Examples
The following examples show how to use
org.apache.camel.PollingConsumer.
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: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 14 votes |
@Override @SuppressWarnings("unchecked") public Pair<String, List<PropagationStatus>> reactivate( final StatusR statusR, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:statusPort"); Map<String, Object> props = new HashMap<>(); props.put("key", statusR.getKey()); props.put("statusR", statusR); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); if (statusR.isOnSyncope()) { sendMessage("direct:reactivateUser", statusR.getKey(), props); } else { UserWorkflowResult<String> updated = new UserWorkflowResult<>(statusR.getKey(), null, null, statusR.getType().name().toLowerCase()); sendMessage("direct:userStatusPropagation", updated, props); } Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(Pair.class); }
Example #2
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 8 votes |
@Override @SuppressWarnings("unchecked") public List<PropagationStatus> provision( final String key, final boolean changePwd, final String password, final Collection<String> resources, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:provisionPort"); Map<String, Object> props = new HashMap<>(); props.put("key", key); props.put("changePwd", changePwd); props.put("password", password); props.put("resources", resources); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); sendMessage("direct:provisionUser", key, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(List.class); }
Example #3
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 8 votes |
@Override @SuppressWarnings("unchecked") public Pair<String, List<PropagationStatus>> suspend( final StatusR statusR, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:statusPort"); Map<String, Object> props = new HashMap<>(); props.put("key", statusR.getKey()); props.put("statusR", statusR); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); if (statusR.isOnSyncope()) { sendMessage("direct:suspendUser", statusR.getKey(), props); } else { UserWorkflowResult<String> updated = new UserWorkflowResult<>(statusR.getKey(), null, null, statusR.getType().name().toLowerCase()); sendMessage("direct:userStatusPropagation", updated, props); } Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(Pair.class); }
Example #4
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public Pair<UserUR, List<PropagationStatus>> update( final UserUR userUR, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:updatePort"); Map<String, Object> props = new HashMap<>(); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); sendMessage("direct:updateUser", userUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(Pair.class); }
Example #5
Source File: AhcWSSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #6
Source File: SJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMessageConsumerRoute() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sjms:queue:" + QUEUE_NAME + "?connectionFactory=#cfactory"). transform(body().prepend("Hello ")).to("seda:end"); } }); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); try { // Send a message to the queue ConnectionFactory cfactory = lookupConnectionFactory(); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { connection.close(); } } finally { camelctx.close(); } }
Example #7
Source File: AbstractCamelProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
protected PollingConsumer getConsumer(final String uri) { if (!knownURIs.contains(uri)) { knownURIs.add(uri); Endpoint endpoint = contextFactory.getCamelContext().getEndpoint(uri); PollingConsumer pollingConsumer = null; try { pollingConsumer = endpoint.createPollingConsumer(); consumerMap.put(uri, pollingConsumer); pollingConsumer.start(); } catch (Exception ex) { LOG.error("Unexpected error in Consumer creation ", ex); } return pollingConsumer; } else { return consumerMap.get(uri); } }
Example #8
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public void confirmPasswordReset( final String key, final String token, final String password, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:confirmPwdResetPort"); Map<String, Object> props = new HashMap<>(); props.put("key", key); props.put("token", token); props.put("password", password); props.put("updater", updater); props.put("context", context); sendMessage("direct:confirmPwdReset", key, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } }
Example #9
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public void requestPasswordReset(final String key, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:requestPwdResetPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:requestPwdReset", key, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } }
Example #10
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public void internalSuspend(final String key, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:internalSuspendUserPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:internalSuspendUser", key, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } }
Example #11
Source File: NettyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@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 #12
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public List<PropagationStatus> deprovision( final String user, final Collection<String> resources, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:deprovisionPort"); Map<String, Object> props = new HashMap<>(); props.put("resources", resources); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); sendMessage("direct:deprovisionUser", user, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(List.class); }
Example #13
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String link(final UserUR userUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:linkPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:linkUser", userUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(UserUR.class).getKey(); }
Example #14
Source File: NettyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testDeployedContext() throws Exception { ServiceName sname = CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME; CamelContextRegistry registry = ServiceLocator.getRequiredService(sname, CamelContextRegistry.class); CamelContext camelctx = registry.getCamelContext("netty-context"); Assert.assertNotNull("CamelContext not null", camelctx); Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus()); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); Socket socket = new Socket(SOCKET_HOST, 7999); socket.setKeepAlive(true); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); try { out.write("Kermit\n"); } finally { out.close(); socket.close(); } String result = pollingConsumer.receive().getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); }
Example #15
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String unlink(final UserUR userUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:unlinkPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:unlinkUser", userUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(UserUR.class).getKey(); }
Example #16
Source File: AtomIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testConsumeAtomFeed() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("atom://http://localhost:8080/atom-test/atom/feed?splitEntries=true") .to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { Entry result = pollingConsumer.receive(5000).getIn().getBody(Entry.class); Assert.assertEquals(FeedConstants.ENTRY_TITLE, result.getTitle()); Assert.assertEquals(FeedConstants.ENTRY_CONTENT, result.getContent()); } finally { camelctx.close(); } }
Example #17
Source File: TransactedJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJMSTransactionToDLQ() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:dlq").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Bob"); // The JMS transaction should have been rolled back and the message sent to the DLQ String result = consumer.receive().getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Bob", result); connection.close(); camelctx.close(); }
Example #18
Source File: TransactedJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJMSTransaction() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:success").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Kermit"); // The JMS transaction should have been committed and the message payload sent to the direct:success endpoint String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Kermit", result); connection.close(); camelctx.close(); }
Example #19
Source File: CamelGroupProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String link(final GroupUR groupUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:linkGroupPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:linkGroup", groupUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(GroupUR.class).getKey(); }
Example #20
Source File: CamelGroupProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String unlink(final GroupUR groupUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:unlinkGroupPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:unlinkGroup", groupUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(GroupUR.class).getKey(); }
Example #21
Source File: JMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMessageConsumerRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("jms:queue:%s?connectionFactory=ConnectionFactory", QUEUE_NAME) .transform(simple("Hello ${body}")) .to("seda:end"); } }); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); try { // Send a message to the queue ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory"); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { connection.close(); } } finally { camelctx.close(); } }
Example #22
Source File: CamelGroupProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public Pair<String, List<PropagationStatus>> create( final GroupCR req, final boolean nullPriorityAsync, final String creator, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:createGroupPort"); Map<String, Object> props = new HashMap<>(); props.put("excludedResources", Set.of()); props.put("nullPriorityAsync", nullPriorityAsync); props.put("creator", creator); props.put("context", context); sendMessage("direct:createGroup", req, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(Pair.class); }
Example #23
Source File: SQLIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSQLEndpoint() throws Exception { Assert.assertNotNull("DataSource not null", dataSource); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sql:select name from information_schema.users?dataSource=java:jboss/datasources/ExampleDS") .to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { String result = (String) pollingConsumer.receive(3000).getIn().getBody(Map.class).get("NAME"); Assert.assertEquals("SA", result); } finally { camelctx.close(); } }
Example #24
Source File: SQLIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSQLEndpointWithCDIContext() throws Exception { try { deployer.deploy(CAMEL_SQL_CDI_ROUTES_JAR); CamelContext camelctx = contextRegistry.getCamelContext("camel-sql-cdi-context"); Assert.assertNotNull("Camel context not null", camelctx); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); String result = (String) pollingConsumer.receive(3000).getIn().getBody(Map.class).get("NAME"); Assert.assertEquals("SA", result); } finally { deployer.undeploy(CAMEL_SQL_CDI_ROUTES_JAR); } }
Example #25
Source File: CamelAnyObjectProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String link(final AnyObjectUR anyObjectUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:linkAnyObjectPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:linkAnyObject", anyObjectUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(AnyObjectUR.class).getKey(); }
Example #26
Source File: CamelAnyObjectProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
@Override public String unlink(final AnyObjectUR anyObjectUR, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:unlinkAnyObjectPort"); Map<String, Object> props = new HashMap<>(); props.put("updater", updater); props.put("context", context); sendMessage("direct:unlinkAnyObject", anyObjectUR, props); Exchange exchange = pollingConsumer.receive(); if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) { throw (RuntimeException) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); } return exchange.getIn().getBody(AnyObjectUR.class).getKey(); }
Example #27
Source File: ZipFileIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testZipSplitterUnmarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file://" + datadir + File.separator + "zip-unmarshal?initialDelay=500&antInclude=*.zip&noop=true") .split(new ZipSplitter()) .streaming() .convertBodyTo(String.class) .to("seda:end"); } }); createZipFile("Hello Kermit"); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example #28
Source File: AhcWSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testAsyncWsRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ahc-ws:" + WEBSOCKET_ENDPOINT); from("ahc-ws:" + WEBSOCKET_ENDPOINT).to("seda:end"); } }); 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 #29
Source File: CXFWSSecureProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testEndpointRouteWithInvalidCredentials() throws Exception { deployer.deploy(SIMPLE_WAR); try { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .doTry() .to("cxf://" + getEndpointAddress("/simple", "baduser", "badpassword")) .doCatch(Exception.class) .setBody(exceptionMessage()) .to("direct:error") .end(); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("direct:error").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.requestBody("direct:start", "Kermit", String.class); String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertTrue(result.contains("401: Unauthorized")); } finally { camelctx.close(); } } finally { deployer.undeploy(SIMPLE_WAR); } }
Example #30
Source File: ActiveMQIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSendMessage() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory", QUEUE_NAME). transform(simple("Hello ${body}")). to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { ConnectionFactory connectionFactory = lookupConnectionFactory(); Connection con = connectionFactory.createConnection(); try { sendMessage(con, "Kermit"); String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { con.close(); } } finally { camelctx.close(); } }