public void process(Exchange exchange) throws Exception { logger.trace("Setting response code to {} for endpoint {}", statusCode, (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, statusCode); }
protected boolean checkChunked(Message message, Exchange exchange) { boolean answer = true; if (message.getHeader(Exchange.HTTP_CHUNKED) == null) { // check the endpoint option Endpoint endpoint = exchange.getFromEndpoint(); if (endpoint instanceof HttpCommonEndpoint) { answer = ((HttpCommonEndpoint)endpoint).isChunked(); } } else { answer = message.getHeader(Exchange.HTTP_CHUNKED, boolean.class); } return answer; }
@Override public boolean matches(Exchange exchange) { Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); if (t == null) { logger.warn("An exception was expected to be received on endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); return false; } return true; }
@Override public void process(Exchange exchange) throws Exception { logger.trace("Applying {} processors against exchange from endpoint {}", processors.size(), (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); for (Processor processor : processors) { logger.trace("Applying processor"); if (processor != null) processor.process(exchange); } } }
@Override public boolean matches(Exchange exchange) { Throwable t = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); if (t == null) { logger.warn("An exception was expected to be received on endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); return false; } logger.debug("An execution exception was encountered on endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), t); boolean matches = exception.getClass().isAssignableFrom(t.getClass()); if (matches) logger.warn("The exception did not match the expected exception from endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); return matches; }
@Override public boolean matches(Exchange exchange) { logger.trace("Starting validation of exchange from endpoint {} against {} predicates", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), predicates.size()); boolean result = true; for (Predicate predicate : predicates) { boolean matches = predicate.matches(exchange); logger.trace("Result of predicate {}: {}", predicate, matches); if (!matches) { logger.warn("The predicate {} did not validate successfully - check the logs for details", predicate); result = false; } } logger.trace("Validation of {} predicates was " + (result ? "successful" : "unsuccessful") + " for endpoint {}", predicates.size(), (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); return result; }
@Override public void process(Exchange exchange) throws Exception { logger.trace("Setting response method to {} for endpoint {}", httpMethod.name(), (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); exchange.getIn().setHeader(Exchange.HTTP_METHOD, httpMethod.name()); }
@Override public void process(Exchange exchange) throws Exception { Map<String, Object> headers = getValue(); logger.trace("Setting headers of exchange from endpoint {} to {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), headers); Map<String, Object> currentHeaders = exchange.getIn().getHeaders(); currentHeaders.putAll(headers); } }
@Override public void process(Exchange exchange) throws Exception { T body = getValue(); logger.trace("Setting body of exchange from endpoint {} to {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown"), body); exchange.getIn().setBody(body); contentTypeTestResource.process(exchange); } }
@Override public void process(Exchange exchange) throws Exception { logger.trace("Setting fault for exchange arriving from endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); exchange.getIn().setFault(true); exchange.getIn().setBody(getValue()); new ContentTypeTestResource("application/xml").process(exchange); }
ZipkinServerResponseAdapter(ZipkinTracer eventNotifier, Exchange exchange) { this.eventNotifier = eventNotifier; this.endpoint = exchange.getFromEndpoint(); this.url = URISupport.sanitizeUri(endpoint.getEndpointUri()); }
/** * Helper method which lookup for BindingDataCreatorResolver and uses returned * instance to create new CamelBindingData. * * @param camelExchange Camel exchange. * @return Binding data creator. */ private BindingDataCreator<?> getBindingDataCreator(org.apache.camel.Exchange camelExchange) { BindingDataCreatorResolver resolver = ((SwitchYardEndpoint) getEndpoint()).getBindingDataCreatorResolver(); String resolverKey = camelExchange.getFromEndpoint().getClass().getSimpleName(); return resolver.resolveBindingCreator(resolverKey, getEndpoint().getCamelContext()); }
/** * Helper method which lookup for BindingDataCreatorResolver and uses returned * instance to create new CamelBindingData. * * @param camelExchange Camel exchange. * @return Binding data creator. */ private BindingDataCreator<?> getBindingDataCreator(org.apache.camel.Exchange camelExchange) { BindingDataCreatorResolver resolver = ((SwitchYardEndpoint) getEndpoint()).getBindingDataCreatorResolver(); String resolverKey = camelExchange.getFromEndpoint().getClass().getSimpleName(); return resolver.resolveBindingCreator(resolverKey, getEndpoint().getCamelContext()); }
@Override public void send(Message message, TestContext context) { Assert.notNull(message, "Message is empty - unable to send empty message"); String correlationKeyName = endpointConfiguration.getCorrelator().getCorrelationKeyName(getName()); String correlationKey = correlationManager.getCorrelationKey(correlationKeyName, context); Exchange exchange = correlationManager.find(correlationKey, endpointConfiguration.getTimeout()); Assert.notNull(exchange, "Failed to find camel exchange for message correlation key: '" + correlationKey + "'"); buildOutMessage(exchange, message); if (log.isDebugEnabled()) { log.debug("Sending reply message to camel endpoint: '" + exchange.getFromEndpoint() + "'"); } getConsumerTemplate().doneUoW(exchange); context.onOutboundMessage(message); log.info("Message was sent to camel endpoint: '" + exchange.getFromEndpoint() + "'"); }
ZipkinServerRequestAdapter(ZipkinTracer eventNotifier, Exchange exchange) { this.eventNotifier = eventNotifier; this.endpoint = exchange.getFromEndpoint(); this.spanName = URISupport.sanitizeUri(endpoint.getEndpointKey()).toLowerCase(Locale.ROOT); this.url = URISupport.sanitizeUri(endpoint.getEndpointUri()); }
private RouteExecution beginRouteExecution(Route route, Exchange exchange) { Date now = Date.from(Instant.now()); RouteExecution routeExchange = new RouteExecution(); routeExchange.setRouteBeginDate(now); routeExchange.setRouteId(route.getId()); routeExchange.setExchangeId(exchange.getExchangeId()); routeExchange.setMessageId(exchange.getIn().getMessageId()); routeExchange.setFromEndpointUri(exchange.getFromEndpoint().getEndpointUri()); routeExchange.setFromEndpointId(getEndpointId(exchange.getFromEndpoint())); routeExchange.setFromRouteId(exchange.getFromRouteId()); Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class); routeExchange.setExchangeCreatedDate(created.getTime()); return routeExchange; }
protected void handleDoneEvent(AbstractExchangeEvent doneEvent) { String name = namingStrategy.getName(doneEvent.getExchange(), doneEvent.getExchange().getFromEndpoint()); Tags tags = namingStrategy.getTags(doneEvent, doneEvent.getExchange().getFromEndpoint()); // Would have preferred LongTaskTimer, but you cannot set the FAILED_TAG once it is registered Timer.Sample sample = (Timer.Sample) doneEvent.getExchange().removeProperty("eventTimer:" + name); if (sample != null) { sample.stop(getMeterRegistry().timer(name, tags)); } }
private BisExchangeEvent createBisEvent(Exchange exchange) { Date now = Date.from(Instant.now()); BisExchangeEvent bisExchangeEvent = new BisExchangeEvent(); Long property = exchange.getProperty(Exchange.BATCH_SIZE, Long.class); bisExchangeEvent.setBatchSize(property); bisExchangeEvent.setFromEndpoint(exchange.getFromEndpoint().getEndpointKey()); bisExchangeEvent.setFromRouteId(exchange.getFromRouteId()); bisExchangeEvent.setExchangeId(exchange.getExchangeId()); Date created = exchange.getProperty(Exchange.CREATED_TIMESTAMP, Date.class); bisExchangeEvent.setCreatedDate(created); bisExchangeEvent.setEndDate(now); bisExchangeEvent.setDuration(now.getTime() - created.getTime()); return bisExchangeEvent; } }
public byte[] marshallExchange(CamelContext camelContext, Exchange exchange) throws IOException { // use DefaultExchangeHolder to marshal to a serialized object DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false); // add the aggregated size property as the only property we want to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class)); // add the aggregated completed by property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class)); // add the aggregated correlation key property to retain DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class)); // persist the from endpoint as well if (exchange.getFromEndpoint() != null) { DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri()); } return encode(pe); }
protected void handleCreatedEvent(ExchangeCreatedEvent createdEvent) { String name = namingStrategy.getName(createdEvent.getExchange(), createdEvent.getExchange().getFromEndpoint()); createdEvent.getExchange().setProperty("eventTimer:" + name, Timer.start(getMeterRegistry())); }