Refine search
public static void main(String[] args) { List<Processor> processors = new ArrayList<>(); processors.add(new Processor(10, 3, false) { @Override protected void doProcess(int i) { System.out.println("Fizz" + "(" + i + ") 3%10"); } }); // add more processors here for(int i = 1; i < 100; i++){ for (Processor processor : processors) { processor.process(i); } } }
@Override public void doResume() throws Exception { log.info("Resuming goal live stream"); // signal the clock is started Exchange exchange = getEndpoint().createExchange(); exchange.getIn().setHeader("action", "clock"); exchange.getIn().setBody(String.valueOf(gameTime.get())); getProcessor().process(exchange); }
if (sendReply && !exchange.getPattern().isOutCapable()) { log.debug("In an inOut capable route"); exchange.setPattern(ExchangePattern.InOut); long deliveryTag = envelope.getDeliveryTag(); try { consumer.getProcessor().process(exchange); } catch (Exception e) { exchange.setException(e); if (exchange.getException() != null) { consumer.getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); exchange.setException(e); consumer.getExceptionHandler().handleException("Error processing exchange", exchange, e); msg.setBody(exchange.getException()); exchange.setOut(msg); exchange.getOut().setHeader(RabbitMQConstants.CORRELATIONID, exchange.getIn().getHeader(RabbitMQConstants.CORRELATIONID)); try { consumer.getEndpoint().publishExchangeToChannel(exchange, channel, properties.getReplyTo()); } catch (RuntimeCamelException e) { consumer.getExceptionHandler().handleException("Error processing exchange", exchange, e);
camelExchange = consumer.getEndpoint().createExchange(); consumer.createUoW(camelExchange); int i = s.indexOf('='); if (i == -1) { camelExchange.getIn().setHeader(s, ""); } else { camelExchange.getIn().setHeader(s.substring(0, i), s.substring(i + 1)); camelExchange.getIn().setHeader(org.apache.camel.Exchange.CONTENT_TYPE, mt); camelExchange.getIn().setBody(bytes); consumer.getProcessor().process(camelExchange); Message target = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn();
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (!isStarted()) { throw new IllegalStateException("The endpoint is not active: " + getEndpoint().getEndpointUri()); Exchange exchange = getEndpoint().createExchange(); exchange.getIn().setBody(invocation); try { log.debug("Invoking {} with args {}", method, args); getProcessor().process(exchange); } catch (Exception e) { exchange.setException(e); Throwable fault = exchange.getException(); if (fault != null) { Object match = null; return exchange.getOut().getBody();
protected void sendExchange(String operation, Object key, Object value) { Exchange exchange = consumer.getEndpoint().createExchange(); // set object to body exchange.getIn().setBody(value); // set headers if (key != null) { exchange.getIn().setHeader(HazelcastConstants.OBJECT_ID, key); } HazelcastComponentHelper.setListenerHeaders(exchange, HazelcastConstants.CACHE_LISTENER, operation, cacheName); try { consumer.getProcessor().process(exchange); } catch (Exception e) { exchange.setException(e); } if (exchange.getException() != null) { consumer.getExceptionHandler().handleException(String.format("Error processing exchange for hazelcast consumer on object '%s' in cache '%s'.", key, cacheName), exchange, exchange.getException()); } }
client.setServerKeyVerifier(new ResourceBasedSSHKeyVerifier(exchange.getContext(), knownHostResource, endpoint.isFailOnUnknownHost())); SshResult result = SshHelper.sendExecCommand(exchange.getIn().getHeaders(), command, endpoint, client); exchange.getIn().setBody(result.getStdout()); exchange.getIn().setHeader(SshResult.EXIT_VALUE, result.getExitValue()); exchange.getIn().setHeader(SshResult.STDERR, result.getStderr()); getProcessor().process(exchange); return 1; // number of messages polled } finally { if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
@Test public void shouldUnmarshallToSpecifiedInputType() throws Exception { final ComponentProxyComponent component = setUpComponent("salesforce-delete-sobject"); final Exchange exchange = new DefaultExchange(context); final Message in = exchange.getIn(); in.setBody("{}"); component.getBeforeProducer().process(exchange); Assertions.assertThat(in.getBody()).isInstanceOf(SalesforceIdentifier.class); }
@Override protected int poll() throws Exception { int count = 0; List<Ref> call = getGit().branchList().call(); for (Ref ref : call) { if (!branchesConsumed.contains(ref.getName())) { Exchange e = getEndpoint().createExchange(); e.getOut().setBody(ref); getProcessor().process(e); branchesConsumed.add(ref.getName()); count++; } } return count; }
/** * Invoked by Spring-WS when a {@link WebServiceMessage} is received */ public void invoke(MessageContext messageContext) throws Exception { Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOptionalOut); populateExchangeFromMessageContext(messageContext, exchange); // populate camel exchange with breadcrumb from transport header populateExchangeWithBreadcrumbFromMessageContext(messageContext, exchange); // start message processing getProcessor().process(exchange); if (exchange.getException() != null) { throw exchange.getException(); } else if (exchange.getPattern().isOutCapable()) { Message responseMessage = exchange.hasOut() ? exchange.getOut(Message.class) : exchange.getIn(Message.class); if (responseMessage != null) { Source responseBody = responseMessage.getBody(Source.class); WebServiceMessage response = messageContext.getResponse(); configuration.getMessageFilter().filterConsumer(exchange, response); XmlConverter xmlConverter = configuration.getXmlConverter(); xmlConverter.toResult(responseBody, response.getPayloadResult()); } } }
@Override public void process(Exchange message) { Object event = message.getIn().getBody(); event = context.getMessagesSerializer().deserialize(event, context.getClassLoader()); try { dispatchMessage(procMock, event, message.getIn().getHeaders()); original.process(message); } catch (Exception e) { throw new RuntimeException("Could not dispatch to the mocked processor: ", e); } } }
protected int poll() throws Exception { List<InactiveDevice> inactiveDeviceList = getInactiveDevices(); Iterator<InactiveDevice> it = inactiveDeviceList.iterator(); while (it.hasNext()) { InactiveDevice inactiveDevice = it.next(); Exchange e = getEndpoint().createExchange(); e.getIn().setBody(inactiveDevice); getProcessor().process(e); } return inactiveDeviceList.size(); }
/** * @param exchange The exchange received by an mock definition that will invoke a given response * - note that processors and predicates must be thread safe */ @Override public void process(Exchange exchange) throws Exception { for (MatchedResponse matchedResponse : responses) { if (matchedResponse.inputPredicate.matches(exchange)) { logger.debug("Matched input for predicate {} at endpoint {}", matchedResponse.inputPredicate, (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); for (Processor e : matchedResponse.responseProcessors) e.process(exchange); return; } } if (defaultResponse != null) { logger.debug("The exchange arriving at endpoint {} found no response match for body {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown") , exchange.getIn().getBody(String.class)); for (Processor processor : defaultResponse.responseProcessors) processor.process(exchange); } else logger.warn("The exchange arriving at endpoint {} found no response match for body {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), exchange.getIn().getBody(String.class)); }
/** * Checks acceptance of the input message and calls the route. */ public static void processRequest( InterceptorSupport<HL7v2Endpoint> interceptor, Exchange exchange) throws Exception { // check input message Hl7v2TransactionConfiguration config = interceptor.getEndpoint().getHl7v2TransactionConfiguration(); config.checkRequestAcceptance(exchange.getIn().getBody(Message.class)); // run the route interceptor.getWrappedProcessor().process(exchange); }
@Test public void shouldNotConvertFailedExchanges() throws Exception { final ComponentProxyComponent component = setUpComponent("salesforce-create-sobject"); final Exchange exchange = new DefaultExchange(context); final Message out = exchange.getOut(); exchange.setException(new Exception()); out.setBody("wat"); component.getAfterProducer().process(exchange); Assertions.assertThat(out.getBody()).isEqualTo("wat"); }
@Override public void intercept(MessageRouter messageRouter, CommandMessage message) { Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOnly); exchange.setIn(message); try { getProcessor().process(exchange); } catch (Exception e) { exchange.setException(e); } if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing intercepted message: " + message, exchange, exchange.getException()); } }
/** * Converts outgoing request to a {@link Message} * and performs some exchange configuration. */ @Override public void process(Exchange exchange) throws Exception { Message msg = exchange.getIn().getMandatoryBody(Message.class); messageTracer.sendMessage(msg, getEndpoint().getEndpointUri(), (message, span) -> { exchange.getIn().setBody(message, Message.class); getWrappedProcessor().process(exchange); }); }
Message message = new DefaultMessage(this.getEndpoint().getCamelContext()); String fileName = StringUtils.substringAfterLast(status.getPath().toString(), "/"); message.setHeader(Exchange.FILE_NAME, fileName); if (key.value != null) { message.setHeader(HdfsHeader.KEY.name(), key.value); message.setBody(value.value); exchange.setIn(message); processor.process(exchange); } catch (Exception e) { exchange.setException(e); if (exchange.getException() != null) { getExceptionHandler().handleException(exchange.getException());
private void sendEvent(Exchange exchange) { try { getProcessor().process(exchange); } catch (Exception e) { exchange.setException(e); } finally { // log exception if an exception occurred and was not handled if (exchange.getException() != null) { getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); } } }