if (line.startsWith("$GPRMC")) { ClientGpsCoordinates coordinates = ClientGpsCoordinates.parseNMEA(line); Exchange exchange = ExchangeBuilder.anExchange(getEndpoint().getCamelContext()).withBody(coordinates).build(); getProcessor().process(exchange); return 1;
/** * Process the TPVObject, all params required. * * @param tpv The time-position-velocity object to process * @param processor Processor that handles the exchange. * @param endpoint GpsdEndpoint receiving the exchange. */ public static void consumeTPVObject(TPVObject tpv, Processor processor, GpsdEndpoint endpoint, ExceptionHandler exceptionHandler) { // Simplify logging when https://github.com/taimos/GPSd4Java/pull/19 is merged into upstream. LOG.debug("About to consume TPV object {},{} from {}", tpv.getLatitude(), tpv.getLongitude(), endpoint); Validate.notNull(tpv); Validate.notNull(processor); Validate.notNull(endpoint); GpsCoordinates coordinates = gpsCoordinates(new Date(new Double(tpv.getTimestamp()).longValue()), tpv.getLatitude(), tpv.getLongitude()); Exchange exchange = anExchange(endpoint.getCamelContext()).withPattern(OutOnly). withHeader(TPV_HEADER, tpv).withBody(coordinates).build(); try { processor.process(exchange); } catch (Exception e) { exceptionHandler.handleException(e); } } }
ExchangeBuilder exchangeBuilder = ExchangeBuilder.anExchange(producerTemplate.getCamelContext()); Exchange exchange = exchangeBuilder.build();
private void onInternalMessageArrived(final String deviceId, final String appTopic, final KuraPayload message, final int qos, final boolean retain, final boolean control) { this.log.debug("Received message with deviceId {}, application topic {}.", deviceId, appTopic); final Exchange exchange = anExchange(getEndpoint().getCamelContext()) // .withBody(message) // .withHeader(CAMEL_KURA_CLOUD_TOPIC, appTopic) // .withHeader(CAMEL_KURA_CLOUD_DEVICEID, deviceId) // .withHeader(CAMEL_KURA_CLOUD_QOS, qos) // .withHeader(CAMEL_KURA_CLOUD_CONTROL, control) // .withHeader(CAMEL_KURA_CLOUD_RETAIN, retain) // .build(); exchange.setFromEndpoint(getEndpoint()); try { getProcessor().process(exchange); } catch (final Exception e) { handleException("Error while processing an incoming message:", e); } }
@Test public void whenExchangeExceptionIsNotNull_thenExceptionHasNotBeenHandled() { // Given String actionToDoInRoute = "throwIllegalArgumentException"; // When Exchange exchange = producerTemplate.send(anExchange(camelContext) .withProperty(actionToDoInRoute, "Did IQs just drop sharply while I was away?") .build()); // Then // ...... An Exception has NOT been handled if it IS in Exchange::exception assertThat(exchange.getException()).isExactlyInstanceOf(IllegalArgumentException.class); // assertThat(exchange.getProperty(EXCEPTION_CAUGHT)) .isExactlyInstanceOf(IllegalArgumentException.class); }
@Test public void whenExchangeExceptionIsNull_thenExceptionHasBeenHandled() { // Given String actionToDoInRoute = "throwNullPointerException"; // When Exchange exchange = producerTemplate.send(anExchange(camelContext) .withProperty(actionToDoInRoute, "Did IQs just drop sharply while I was away?") .build()); // Then // ...... An Exception has been handled if it is NOT in Exchange::exception assertThat(exchange.getException()).isNull(); // ...... But there is still evidence of it assertThat(exchange.getProperty(EXCEPTION_CAUGHT)) .isExactlyInstanceOf(NullPointerException.class); }