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); } } }
@Test public void mockEndpoint_snapshotsTheExchange() throws Exception { // Given weaveRoute(GreetingRouteBuilder.ROUTE_ID, routeBuilder -> routeBuilder.weaveByToString(".*ocessor.*") .replace() .to(mockEndpoint)); // And Exchange inputExchange = new ExchangeBuilder(camelContext) .withBody("Duke") .build(); // When producerTemplate.send(inputExchange); Exchange mockEndpointExchange = mockEndpoint.getExchanges().get(0); // Then assertThat(mockEndpointExchange.getExchangeId()).isEqualTo(inputExchange.getExchangeId()); // And assertThat(mockEndpointExchange.getProperty(FIRST_PROPERTY)).isEqualTo("Hello Duke"); assertThat(mockEndpointExchange.getProperty(SECOND_PROPERTY)).isNull(); // And assertThat(inputExchange.getProperty(FIRST_PROPERTY)).isEqualTo("Hello Duke"); assertThat(inputExchange.getProperty(SECOND_PROPERTY)).isEqualTo("Goodbye Duke"); // And assertThat(mockEndpointExchange).isNotSameAs(inputExchange); }
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); } }