Java Code Examples for org.apache.camel.Exchange#getProperty()
The following examples show how to use
org.apache.camel.Exchange#getProperty() .
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: patched.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
/** * Strategy to create the unit of work to be used for the sub route * * @param routeContext the route context * @param processor the processor * @param exchange the exchange * @return the unit of work processor */ protected Processor createUnitOfWorkProcessor(RouteContext routeContext, Processor processor, Exchange exchange) { String routeId = routeContext != null ? routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory()) : null; CamelInternalProcessor internal = new CamelInternalProcessor(processor); // and wrap it in a unit of work so the UoW is on the top, so the entire route will be in the same UoW UnitOfWork parent = exchange.getProperty(Exchange.PARENT_UNIT_OF_WORK, UnitOfWork.class); if (parent != null) { internal.addAdvice(new CamelInternalProcessor.ChildUnitOfWorkProcessorAdvice(routeId, parent)); } else { internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId)); } // and then in route context so we can keep track which route this is at runtime if (routeContext != null) { internal.addAdvice(new CamelInternalProcessor.RouteContextAdvice(routeContext)); } return internal; }
Example 2
Source File: SimpleProcessTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "process/example.bpmn20.xml" }) public void testRunProcess() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); service1.expectedBodiesReceived("ala"); Exchange exchange = ctx.getEndpoint("direct:start").createExchange(); exchange.getIn().setBody(Collections.singletonMap("var1", "ala")); tpl.send("direct:start", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); tpl.sendBodyAndProperty("direct:receive", null, FlowableProducer.PROCESS_ID_PROPERTY, instanceId); assertProcessEnded(instanceId); service1.assertIsSatisfied(); Map<?, ?> m = service2.getExchanges().get(0).getIn().getBody(Map.class); assertThat(m.get("var1")).isEqualTo("ala"); assertThat(m.get("var2")).isEqualTo("var2"); }
Example 3
Source File: CustomContextTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Deployment(resources = { "process/custom.bpmn20.xml" }) public void testRunProcess() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); service1.expectedBodiesReceived("ala"); Exchange exchange = ctx.getEndpoint("direct:start").createExchange(); exchange.getIn().setBody(Collections.singletonMap("var1", "ala")); tpl.send("direct:start", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); tpl.sendBodyAndProperty("direct:receive", null, FlowableProducer.PROCESS_ID_PROPERTY, instanceId); assertProcessEnded(instanceId); service1.assertIsSatisfied(); @SuppressWarnings("rawtypes") Map m = service2.getExchanges().get(0).getIn().getBody(Map.class); assertEquals("ala", m.get("var1")); assertEquals("var2", m.get("var2")); }
Example 4
Source File: InitiatorCamelCallTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment public void testInitiatorCamelCall() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); String body = "body text"; Exchange exchange = ctx.getEndpoint("direct:startWithInitiatorHeader").createExchange(); exchange.getIn().setBody(body); tpl.send("direct:startWithInitiatorHeader", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); String initiator = (String) runtimeService.getVariable(instanceId, "initiator"); assertEquals("kermit", initiator); Object camelInitiatorHeader = runtimeService.getVariable(instanceId, "CamelProcessInitiatorHeader"); assertNull(camelInitiatorHeader); }
Example 5
Source File: original.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
/** * Sets the given {@link org.apache.camel.processor.aggregate.AggregationStrategy} on the {@link Exchange}. * * @param exchange the exchange * @param aggregationStrategy the strategy */ protected void setAggregationStrategyOnExchange(Exchange exchange, AggregationStrategy aggregationStrategy) { Map<?, ?> property = exchange.getProperty(Exchange.AGGREGATION_STRATEGY, Map.class); Map<Object, AggregationStrategy> map = CastUtils.cast(property); if (map == null) { map = new ConcurrentHashMap<Object, AggregationStrategy>(); } else { // it is not safe to use the map directly as the exchange doesn't have the deep copy of it's properties // we just create a new copy if we need to change the map map = new ConcurrentHashMap<Object, AggregationStrategy>(map); } // store the strategy using this processor as the key // (so we can store multiple strategies on the same exchange) map.put(this, aggregationStrategy); exchange.setProperty(Exchange.AGGREGATION_STRATEGY, map); }
Example 6
Source File: file_t.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
/** * Strategy to create the unit of work to be used for the sub route * * @param routeContext the route context * @param processor the processor * @param exchange the exchange * @return the unit of work processor */ protected Processor createUnitOfWorkProcessor(RouteContext routeContext, Processor processor, Exchange exchange) { String routeId = routeContext != null ? routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory()) : null; CamelInternalProcessor internal = new CamelInternalProcessor(processor); // and wrap it in a unit of work so the UoW is on the top, so the entire route will be in the same UoW UnitOfWork parent = exchange.getProperty(Exchange.PARENT_UNIT_OF_WORK, UnitOfWork.class); if (parent != null) { internal.addAdvice(new CamelInternalProcessor.ChildUnitOfWorkProcessorAdvice(routeId, parent)); } else { internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId)); } // and then in route context so we can keep track which route this is at runtime if (routeContext != null) { internal.addAdvice(new CamelInternalProcessor.RouteContextAdvice(routeContext)); } return internal; }
Example 7
Source File: EmptyProcessTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "process/empty.bpmn20.xml" }) public void testRunProcessWithHeader() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = camelContext.createProducerTemplate(); String body = "body text"; Exchange exchange = ctx.getEndpoint("direct:startEmptyWithHeader").createExchange(); exchange.getIn().setBody(body); tpl.send("direct:startEmptyWithHeader", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); assertProcessEnded(instanceId); HistoricVariableInstance var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("camelBody").singleResult(); assertThat(var).isNotNull(); assertThat(var.getValue()).isEqualTo(body); var = processEngine.getHistoryService().createHistoricVariableInstanceQuery().variableName("MyVar").singleResult(); assertThat(var).isNotNull(); assertThat(var.getValue()).isEqualTo("Foo"); }
Example 8
Source File: CustomContextTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = { "process/custom.bpmn20.xml" }) public void testRunProcess() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); service1.expectedBodiesReceived("ala"); Exchange exchange = ctx.getEndpoint("direct:start").createExchange(); exchange.getIn().setBody(Collections.singletonMap("var1", "ala")); tpl.send("direct:start", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_ID_PROPERTY, instanceId); assertProcessEnded(instanceId); service1.assertIsSatisfied(); @SuppressWarnings("rawtypes") Map m = service2.getExchanges().get(0).getIn().getBody(Map.class); assertEquals("ala", m.get("var1")); assertEquals("var2", m.get("var2")); }
Example 9
Source File: InitiatorCamelCallTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment public void testInitiatorCamelCall() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); String body = "body text"; Exchange exchange = ctx.getEndpoint("direct:startWithInitiatorHeader").createExchange(); exchange.getIn().setBody(body); tpl.send("direct:startWithInitiatorHeader", exchange); String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY"); String initiator = (String) runtimeService.getVariable(instanceId, "initiator"); assertEquals("kermit", initiator); Object camelInitiatorHeader = runtimeService.getVariable(instanceId, "CamelProcessInitiatorHeader"); assertNull(camelInitiatorHeader); }
Example 10
Source File: ActivitiProducer.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected String findProcessInstanceId(Exchange exchange) { String processInstanceId = exchange.getProperty(PROCESS_ID_PROPERTY, String.class); if (processInstanceId != null) { return processInstanceId; } String processInstanceKey = exchange.getProperty(PROCESS_KEY_PROPERTY, String.class); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(processInstanceKey).singleResult(); if (processInstance == null) { throw new ActivitiException("Could not find activiti with key " + processInstanceKey); } return processInstance.getId(); }
Example 11
Source File: file_t.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
/** * Removes the associated {@link org.apache.camel.processor.aggregate.AggregationStrategy} from the {@link Exchange} * which must be done after use. * * @param exchange the current exchange */ protected void removeAggregationStrategyFromExchange(Exchange exchange) { Map<?, ?> property = exchange.getProperty(Exchange.AGGREGATION_STRATEGY, Map.class); Map<Object, AggregationStrategy> map = CastUtils.cast(property); if (map == null) { return; } // remove the strategy using this processor as the key map.remove(this); }
Example 12
Source File: CamelGroupProvisioningManager.java From syncope with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public List<PropagationStatus> provision( final String key, final Collection<String> resources, final boolean nullPriorityAsync, final String updater, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:provisionGroupPort"); Map<String, Object> props = new HashMap<>(); props.put("resources", resources); props.put("nullPriorityAsync", nullPriorityAsync); props.put("updater", updater); props.put("context", context); sendMessage("direct:provisionGroup", 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 13
Source File: CustomerCamelRoute.java From istio-tutorial with Apache License 2.0 | 5 votes |
private void handleHttpFailure(Exchange exchange) { HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT, String.format("%d %s", e.getStatusCode(), e.getResponseBody()) )); }
Example 14
Source File: CombineDataAggregationStrategy.java From camelinaction2 with Apache License 2.0 | 5 votes |
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { // to contains the endpoint which we send to so we know which system // has returned data back to us String to = newExchange.getProperty(Exchange.TO_ENDPOINT, String.class); if (to.contains("erp")) { return aggregate("ERP", oldExchange, newExchange); } else if (to.contains("crm")) { return aggregate("CRM", oldExchange, newExchange); } else { return aggregate("SHIPPING", oldExchange, newExchange); } }
Example 15
Source File: CamelUserProvisioningManager.java From syncope with Apache License 2.0 | 5 votes |
@Transactional(propagation = Propagation.REQUIRES_NEW) @Override @SuppressWarnings("unchecked") public List<PropagationStatus> delete( final String key, final Set<String> excludedResources, final boolean nullPriorityAsync, final String eraser, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:deletePort"); Map<String, Object> props = new HashMap<>(); props.put("excludedResources", excludedResources); props.put("nullPriorityAsync", nullPriorityAsync); props.put("eraser", eraser); props.put("context", context); sendMessage("direct:deleteUser", 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 16
Source File: DefaultExchangeExtender.java From karaf-decanter with Apache License 2.0 | 5 votes |
private static String extractCausedByException(Exchange exchange) { Throwable cause = exchange.getException(); if (cause == null) { cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class); } return (cause != null) ? cause.toString() : null; }
Example 17
Source File: file_s.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
/** * Removes the associated {@link org.apache.camel.processor.aggregate.AggregationStrategy} from the {@link Exchange} * which must be done after use. * * @param exchange the current exchange */ protected void removeAggregationStrategyFromExchange(Exchange exchange) { Map<?, ?> property = exchange.getProperty(Exchange.AGGREGATION_STRATEGY, Map.class); Map<Object, AggregationStrategy> map = CastUtils.cast(property); if (map == null) { return; } // remove the strategy using this processor as the key map.remove(this); }
Example 18
Source File: CamelGroupProvisioningManager.java From syncope with Apache License 2.0 | 5 votes |
@Transactional(propagation = Propagation.REQUIRES_NEW) @Override @SuppressWarnings("unchecked") public List<PropagationStatus> delete( final String key, final Set<String> excludedResources, final boolean nullPriorityAsync, final String eraser, final String context) { PollingConsumer pollingConsumer = getConsumer("direct:deleteGroupPort"); Map<String, Object> props = new HashMap<>(); props.put("excludedResources", excludedResources); props.put("nullPriorityAsync", nullPriorityAsync); props.put("eraser", eraser); props.put("context", context); sendMessage("direct:deleteGroup", 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 19
Source File: file_t.java From gumtree-spoon-ast-diff with Apache License 2.0 | 4 votes |
protected Integer getExchangeIndex(Exchange exchange) { return exchange.getProperty(Exchange.MULTICAST_INDEX, Integer.class); }
Example 20
Source File: original.java From gumtree-spoon-ast-diff with Apache License 2.0 | 4 votes |
protected Integer getExchangeIndex(Exchange exchange) { return exchange.getProperty(Exchange.MULTICAST_INDEX, Integer.class); }