Java Code Examples for org.apache.camel.Exchange#getMessage()
The following examples show how to use
org.apache.camel.Exchange#getMessage() .
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: FileWatchResource.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Path("/get-events") @GET @Produces(MediaType.APPLICATION_JSON) public Response getEvent(@QueryParam("path") String path) throws Exception { final Exchange exchange = consumerTemplate.receiveNoWait("file-watch://" + path); if (exchange == null) { return Response.noContent().build(); } else { final Message message = exchange.getMessage(); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); node.put("type", message.getHeader(FileWatchComponent.EVENT_TYPE_HEADER, FileEventEnum.class).toString()); node.put("path", message.getHeader("CamelFileAbsolutePath", String.class)); return Response .ok() .entity(node) .build(); } }
Example 2
Source File: QuarkusPlatformHttpConsumer.java From camel-quarkus with Apache License 2.0 | 6 votes |
static int determineResponseCode(Exchange camelExchange, Object body) { boolean failed = camelExchange.isFailed(); int defaultCode = failed ? 500 : 200; Message message = camelExchange.getMessage(); Integer currentCode = message.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class); int codeToUse = currentCode == null ? defaultCode : currentCode; if (codeToUse != 500) { if ((body == null) || (body instanceof String && ((String) body).trim().isEmpty())) { // no content codeToUse = currentCode == null ? 204 : currentCode; } } return codeToUse; }
Example 3
Source File: TwitterMediaAction.java From syndesis-extensions with Apache License 2.0 | 6 votes |
/** * Builds JSON message body of the MediaEntities detected in the Twitter message. Removes * the Body of the message if no Entities are found * * * @param exchange The Camel Exchange object containing the Message, that in turn should * contain the MediaEntity and MediaURL */ private void process(Exchange exchange) { // validate input if (ObjectHelper.isEmpty(exchange)) { throw new NullPointerException("Exchange is empty. Should be impossible."); } Message message = exchange.getMessage(); if (ObjectHelper.isEmpty(message)) { throw new NullPointerException("Message is empty. Should be impossible."); } Object incomingBody = message.getBody(); if (incomingBody instanceof Status) { message.setBody((new TweetMedia((Status)incomingBody)).toJSON()); } else { throw new ClassCastException("Body isn't Status, why are you using this component!?" + (incomingBody != null ? incomingBody.getClass() : " empty")); } }
Example 4
Source File: RestRouteBuilder.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void readQueue(Exchange exchange, BlockingQueue<FromDeviceMessagePinStateChanged> messages) throws InterruptedException { FromDeviceMessagePinStateChanged polled = checkNotNull(messages.poll(1, SECONDS), "Timout retrieving message from arduino"); Message message = exchange.getMessage(); if (Integer.compare(polled.getPin().pinNum(), ((int) message.getHeader(HEADER_PIN))) == 0) { message.setBody(polled.getValue(), String.class); } else { messages.offer(polled); } }
Example 5
Source File: RestRouteBuilder.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void patch(Exchange exchange, ALPProtocolKey startKey, ALPProtocolKey stopKey) { Message message = exchange.getMessage(); Object pinRaw = message.getHeader("pin"); String stateRaw = message.getBody(String.class); String[] split = stateRaw.split("="); checkState(split.length == 2, "Could not split %s by =", stateRaw); checkState(split[0].equalsIgnoreCase("listen"), "Expected listen=${state} but was %s", stateRaw); int pin = tryParse(String.valueOf(pinRaw)).getOrThrow("Pin %s not parseable", pinRaw); boolean state = parseBoolean(split[1]); message.setBody(alpProtocolMessage(state ? startKey : stopKey).forPin(pin).withoutValue()); }
Example 6
Source File: RestRouteBuilder.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void switchDigital(Exchange exchange) { Message message = exchange.getMessage(); Object pinRaw = message.getHeader("pin"); String stateRaw = message.getBody(String.class); int pin = tryParse(String.valueOf(pinRaw)).getOrThrow("Pin %s not parseable", pinRaw); boolean state = parseBoolean(stateRaw); message.setBody(alpProtocolMessage(DIGITAL_PIN_READ).forPin(pin).withState(state)); }
Example 7
Source File: RestRouteBuilder.java From Ardulink-2 with Apache License 2.0 | 5 votes |
private void switchAnalog(Exchange exchange) { Message message = exchange.getMessage(); Object pinRaw = message.getHeader("pin"); String valueRaw = message.getBody(String.class); int pin = tryParse(String.valueOf(pinRaw)).getOrThrow("Pin %s not parseable", pinRaw); int value = tryParse(valueRaw).getOrThrow("Value %s not parseable", valueRaw); message.setBody(alpProtocolMessage(ANALOG_PIN_READ).forPin(pin).withValue(value)); }
Example 8
Source File: RestRouteBuilder.java From Ardulink-2 with Apache License 2.0 | 4 votes |
private void setTypeAndPinHeader(Exchange exchange, Type type) { Message message = exchange.getMessage(); setTypeAndPinHeader(message, type, readPin(type, message)); }