Java Code Examples for org.apache.camel.Exchange#hasOut()

The following examples show how to use org.apache.camel.Exchange#hasOut() . These examples are extracted from open source projects. 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
@Override
public Map<String, Object> mapFromResponse(Exchange exchange) {
    Map<String, Object> results = new HashMap<String, Object>();
    if (exchange.hasOut()) {
        Message out = exchange.getOut();
        Object response = out.getBody();
        results.put(responseLocation,
                    response);
        Map<String, Object> headerValues = out.getHeaders();
        for (String headerLocation : this.headerLocations) {
            results.put(headerLocation,
                        headerValues.get(headerLocation));
        }
    }
    return results;
}
 
Example 2
Source Project: syndesis   File: DataMapperStepHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {
    if (exchange.removeProperty(DATA_MAPPER_AUTO_CONVERSION) != null) {
        final Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();

        if (message != null && message.getBody(String.class) != null) {
            try {
                JsonNode json = JsonUtils.reader().readTree(message.getBody(String.class));
                if (json.isArray()) {
                    message.setBody(JsonUtils.arrayToJsonBeans(json));
                }
            } catch (JsonParseException e) {
                LOG.warn("Unable to convert json array type String to required format", e);
            }
        }
    }
}
 
Example 3
Source Project: syndesis   File: AggregateStepHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void process(Exchange exchange) throws Exception {
    final Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();

    if (message != null && message.getBody() instanceof List) {
        try {
            List<String> unifiedBodies = new ArrayList<>();
            List<?> jsonBeans = message.getBody(List.class);
            for (Object unifiedJsonBean : jsonBeans) {
                JsonNode unifiedJson = JsonUtils.reader().readTree(String.valueOf(unifiedJsonBean));
                if (unifiedJson.isObject()) {
                    JsonNode body = unifiedJson.get("body");
                    if (body != null) {
                        unifiedBodies.add(JsonUtils.writer().writeValueAsString(body));
                    }
                }
            }

            message.setBody("{\"body\":" + JsonUtils.jsonBeansToArray(unifiedBodies) + "}");
        } catch (JsonParseException e) {
            LOG.warn("Unable to aggregate unified json array type", e);
        }
    }
}
 
Example 4
@Override
public void process(Exchange exchange) throws Exception {
    final Message message = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
    final String id = message.getHeader(IntegrationLoggingConstants.STEP_ID, String.class);

    if (id != null) {
        Message copy = message.copy();
        Map<String, Message> outMessagesMap = getCapturedMessageMap(exchange);
        if (copy instanceof MessageSupport && copy.getExchange() == null) {
            ((MessageSupport) copy).setExchange(message.getExchange());
        }

        outMessagesMap.put(id, copy);
    }
}
 
Example 5
@Override
public void extend(Map<String, Object> data, Exchange exchange) {
    data.put("fromEndpointUri", exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : null);
    setHistory(data, exchange);
    data.put("exchangeId", exchange.getExchangeId());
    data.put("routeId", exchange.getFromRouteId());
    data.put("camelContextName", exchange.getContext().getName());
    data.put("shortExchangeId", extractShortExchangeId(exchange));
    data.put("exchangePattern", exchange.getPattern().toString());
    if (includeProperties) {
        data.put("properties", exchange.getProperties());
    }
    if (includeHeaders) {
        data.put("inHeaders", exchange.getIn().getHeaders());
    }
    if (includeBody) {
        data.put("inBody", MessageHelper.extractBodyAsString(exchange.getIn()));
    }
    data.put("inBodyType", MessageHelper.getBodyTypeName(exchange.getIn()));
    if (exchange.hasOut()) {
        if (includeHeaders) {
            data.put("outHeaders", exchange.getOut().getHeaders());
        }
        if (includeBody) {
            data.put("outBody", MessageHelper.extractBodyAsString(exchange.getOut()));
        }
        data.put("outBodyType", MessageHelper.getBodyTypeName(exchange.getOut()));
    }
    data.put("causedByException", extractCausedByException(exchange));
}
 
Example 6
@Test
public void testBasicSignatureRoute() throws Exception {

    CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository());

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:sign")
            .to("crypto:sign://basic?privateKey=#myPrivateKey&algorithm=SHA1withDSA&provider=SUN")
            .to("direct:verify");

            from("direct:verify")
            .to("crypto:verify://basic?publicKey=#myPublicKey&algorithm=SHA1withDSA&provider=SUN")
            .to("mock:result");
        }
    });

    camelctx.start();
    try {
        camelctx.createProducerTemplate().sendBody("direct:sign", PAYLOAD);

        MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
        Exchange e = mockEndpoint.getExchanges().get(0);
        Message result = e == null ? null : e.hasOut() ? e.getOut() : e.getIn();
        Assert.assertNull(result.getHeader(DigitalSignatureConstants.SIGNATURE));
    } finally {
        camelctx.close();
    }
}