当前位置: 首页>>代码示例>>Java>>正文


Java ExchangeHelper类代码示例

本文整理汇总了Java中org.apache.camel.util.ExchangeHelper的典型用法代码示例。如果您正苦于以下问题:Java ExchangeHelper类的具体用法?Java ExchangeHelper怎么用?Java ExchangeHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExchangeHelper类属于org.apache.camel.util包,在下文中一共展示了ExchangeHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    String user = exchange.getIn().getHeader("User", String.class);
    String contentType = ExchangeHelper.getContentType(exchange);
    String body = exchange.getIn().getBody(String.class);
    String encoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
    if (encoding != null) {
        exchange.getOut().setHeader(Exchange.CONTENT_ENCODING, encoding);
    }
    if ("Claus".equals(user) && contentType.startsWith("text/xml") && body.equals("<order>123</order>")) {
        assertEquals("test", exchange.getIn().getHeader("SOAPAction", String.class));
        if (contentType.endsWith("UTF-8")) {
            assertEquals("Get a wrong charset name.", exchange.getProperty(Exchange.CHARSET_NAME, String.class), "UTF-8");
        }
        exchange.getOut().setBody("<order>OK</order>");
        exchange.getOut().setHeader("Content-Type", "text/xml");
    } else {
        exchange.getOut().setBody("FAIL");
        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:JettyContentTypeTest.java

示例2: matches

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
@Override
public boolean matches(Exchange exchange) {
    Object msgBody = exchange.getIn().getBody();

    // TODO: Maybe check for content-type, too ?
    // String contentType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, String.class);
    // if ("application/json".equals(contentType)) { ... }
    // ???
    if (!(msgBody instanceof String)) {
        return language.createPredicate(expression).matches(exchange);
    }

    Exchange exchangeToCheck = exchange;
    // If it is a json document , suppose that this is a document which needs to be parsed as JSON
    // Therefor we set a map instead of the string
    Map jsonDocument = jsonStringAsMap((String) msgBody, exchange);
    if (jsonDocument != null) {
        // Clone the exchange and set the JSON message converted to a Map / List as in message.
        // The intention is that only this predicate acts on the converted value,
        // but the original in-message still continues to carry the same format
        // The predicated is supposed to be read only with respect to the incoming messaeg.
        exchangeToCheck = ExchangeHelper.createCopy(exchange, true);
        exchangeToCheck.getIn().setBody(jsonDocument);
    }
    return language.createPredicate(convertSimpleToOGNLForMaps(expression)).matches(exchangeToCheck);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:27,代码来源:JsonSimplePredicate.java

示例3: push

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
public void push(ServerSession remote, ServerMessage cometdMessage) throws Exception {
    Object data = null;

    Message message = binding.createCamelMessage(remote, cometdMessage, data);

    Exchange exchange = endpoint.createExchange();
    exchange.setIn(message);

    consumer.getProcessor().process(exchange);

    if (ExchangeHelper.isOutCapable(exchange)) {
        ServerChannel channel = getBayeux().getChannel(channelName);
        ServerSession serverSession = getServerSession();

        ServerMessage.Mutable outMessage = binding.createCometdMessage(channel, serverSession, exchange.getOut());
        remote.deliver(serverSession, outMessage);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:CometdConsumer.java

示例4: maybeDisconnectOnDone

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
protected void maybeDisconnectOnDone(Exchange exchange) {
    if (session == null) {
        return;
    }

    // should session be closed after complete?
    Boolean close;
    if (ExchangeHelper.isOutCapable(exchange)) {
        close = exchange.getOut().getHeader(MinaConstants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class);
    } else {
        close = exchange.getIn().getHeader(MinaConstants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class);
    }

    // should we disconnect, the header can override the configuration
    boolean disconnect = getEndpoint().getConfiguration().isDisconnect();
    if (close != null) {
        disconnect = close;
    }
    if (disconnect) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Closing session when complete at address: {}", getEndpoint().getAddress());
        }
        session.close();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:MinaProducer.java

示例5: failedExchange

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
public synchronized void failedExchange(Exchange exchange) {
    increment();
    exchangesFailed.increment();
    exchangesInflight.decrement();

    if (ExchangeHelper.isRedelivered(exchange)) {
        redeliveries.increment();
    }
    Boolean externalRedelivered = exchange.isExternalRedelivered();
    if (externalRedelivered != null && externalRedelivered) {
        externalRedeliveries.increment();
    }

    long now = new Date().getTime();
    if (firstExchangeFailureTimestamp.getUpdateCount() == 0) {
        firstExchangeFailureTimestamp.updateValue(now);
    }

    lastExchangeFailureTimestamp.updateValue(now);
    if (firstExchangeFailureExchangeId == null) {
        firstExchangeFailureExchangeId = exchange.getExchangeId();
    }
    lastExchangeFailureExchangeId = exchange.getExchangeId();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:ManagedPerformanceCounter.java

示例6: getResponseMessage

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
/**
 * Gets the Camel {@link Message} to use as the message to be set on the current {@link Exchange} when
 * we have received a reply message.
 * <p/>
 *
 * @param exchange      the current exchange
 * @param messageEvent  the incoming event which has the response message from Netty.
 * @return the Camel {@link Message} to set on the current {@link Exchange} as the response message.
 * @throws Exception is thrown if error getting the response message
 */
protected Message getResponseMessage(Exchange exchange, MessageEvent messageEvent) throws Exception {
    Object body = messageEvent.getMessage();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Channel: {} received body: {}", new Object[]{messageEvent.getChannel(), body});
    }

    // if textline enabled then covert to a String which must be used for textline
    if (producer.getConfiguration().isTextline()) {
        body = producer.getContext().getTypeConverter().mandatoryConvertTo(String.class, exchange, body);
    }

    // set the result on either IN or OUT on the original exchange depending on its pattern
    if (ExchangeHelper.isOutCapable(exchange)) {
        NettyPayloadHelper.setOut(exchange, body);
        return exchange.getOut();
    } else {
        NettyPayloadHelper.setIn(exchange, body);
        return exchange.getIn();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:ClientChannelHandler.java

示例7: getProperty

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T getProperty(String name, Class<T> type) {
    Object value = getProperty(name);
    if (value == null) {
        // lets avoid NullPointerException when converting to boolean for null values
        if (boolean.class.isAssignableFrom(type)) {
            return (T) Boolean.FALSE;
        }
        return null;
    }

    // eager same instance type test to avoid the overhead of invoking the type converter
    // if already same type
    if (type.isInstance(value)) {
        return type.cast(value);
    }

    return ExchangeHelper.convertToType(this, type, value);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:DefaultExchange.java

示例8: printImage

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
/**
 * Writes the image file to the output stream.
 *
 * @param graph    the object graph
 * @param exchange the camel exchange
 * @param stream   the output stream
 */
private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception {
    final String payload = ExchangeHelper
            .convertToMandatoryType(exchange, String.class, graph);
    final MultiFormatWriter writer = new MultiFormatWriter();

    // set values
    final String type = this.params.getType().toString();

    // create code image  
    final BitMatrix matrix = writer.encode(
            payload,
            this.params.getFormat(),
            this.params.getWidth(),
            this.params.getHeight(),
            writerHintMap);

    // write image back to stream
    MatrixToImageWriter.writeToStream(matrix, type, stream);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:BarcodeDataFormat.java

示例9: outHeadersExpression

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
/**
 * Returns an expression for the outbound message headers
 *
 * @return an expression object which will return the headers, will be <tt>null</tt> if the
 * exchange is not out capable.
 */
public static Expression outHeadersExpression() {
    return new ExpressionAdapter() {
        public Object evaluate(Exchange exchange) {
            // only get out headers if the MEP is out capable
            if (ExchangeHelper.isOutCapable(exchange)) {
                return exchange.getOut().getHeaders();
            } else {
                return null;
            }
        }

        @Override
        public String toString() {
            return "outHeaders";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:ExpressionBuilder.java

示例10: assertMessageExpected

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
protected void assertMessageExpected(long index, Exchange expected, Exchange actual) throws Exception {
    switch (getDataSetIndex()) {
    case "off":
        break;
    case "strict":
        long actualCounter = ExchangeHelper.getMandatoryHeader(actual, Exchange.DATASET_INDEX, Long.class);
        assertEquals("Header: " + Exchange.DATASET_INDEX, index, actualCounter, actual);
        break;
    case "lenient":
    default:
        // Validate the header value if it is present
        Long dataSetIndexHeaderValue = actual.getIn().getHeader(Exchange.DATASET_INDEX, Long.class);
        if (dataSetIndexHeaderValue != null) {
            assertEquals("Header: " + Exchange.DATASET_INDEX, index, dataSetIndexHeaderValue, actual);
        } else {
            // set the header if it isn't there
            actual.getIn().setHeader(Exchange.DATASET_INDEX, index);
        }
        break;
    }

    getDataSet().assertMessageExpected(this, expected, actual, index);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:DataSetEndpoint.java

示例11: onExchange

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
protected synchronized void onExchange(Exchange exchange) {
    try {
        if (reporter != null) {
            reporter.process(exchange);
        }
        Exchange copy = exchange;
        if (copyOnExchange) {
            // copy the exchange so the mock stores the copy and not the actual exchange
            copy = ExchangeHelper.createCopy(exchange, true);
        }
        performAssertions(exchange, copy);
    } catch (Throwable e) {
        // must catch java.lang.Throwable as AssertionError extends java.lang.Error
        failures.add(e);
    } finally {
        // make sure latch is counted down to avoid test hanging forever
        if (latch != null) {
            latch.countDown();
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MockEndpoint.java

示例12: doProcessResult

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
private void doProcessResult(Exchange exchange, Object result) {
    if (endpoint.getStatementType() == StatementType.QueryForList || endpoint.getStatementType() == StatementType.QueryForObject) {
        Message answer = exchange.getIn();
        if (ExchangeHelper.isOutCapable(exchange)) {
            answer = exchange.getOut();
            // preserve headers
            answer.getHeaders().putAll(exchange.getIn().getHeaders());
        }
        // set the result as body for insert
        answer.setBody(result);

        answer.setHeader(IBatisConstants.IBATIS_RESULT, result);
        answer.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
    } else {
        Message msg = exchange.getIn();
        msg.setHeader(IBatisConstants.IBATIS_RESULT, result);
        msg.setHeader(IBatisConstants.IBATIS_STATEMENT_NAME, statement);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:IBatisProducer.java

示例13: maybeDisconnectOnDone

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
protected void maybeDisconnectOnDone(Exchange exchange) {
    if (session == null) {
        return;
    }

    // should session be closed after complete?
    Boolean close;
    if (ExchangeHelper.isOutCapable(exchange)) {
        close = exchange.getOut().getHeader(Mina2Constants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class);
    } else {
        close = exchange.getIn().getHeader(Mina2Constants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class);
    }

    // should we disconnect, the header can override the configuration
    boolean disconnect = getEndpoint().getConfiguration().isDisconnect();
    if (close != null) {
        disconnect = close;
    }
    if (disconnect) {
        LOG.debug("Closing session when complete at address: {}", address);
        session.close(true);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:Mina2Producer.java

示例14: assertCorrectMapReceived

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
protected void assertCorrectMapReceived() {
    Exchange exchange = endpoint.getReceivedExchanges().get(0);
    // This should be a JMS Exchange
    assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
    JmsMessage in = (JmsMessage) exchange.getIn();
    assertNotNull(in);
    
    Map<?, ?> map = exchange.getIn().getBody(Map.class);
    log.info("Received map: " + map);

    assertNotNull("Should have received a map message!", map);
    assertIsInstanceOf(MapMessage.class, in.getJmsMessage());
    assertEquals("map.foo", "abc", map.get("foo"));
    assertEquals("map.bar", "xyz", map.get("bar"));
    assertEquals("map.size", 2, map.size());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:ConsumeJmsMapMessageTest.java

示例15: createRouteBuilder

import org.apache.camel.util.ExchangeHelper; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // enable POST support
            from("restlet:http://localhost:" + portNum + "/users/?restletMethods=post")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        String type = ExchangeHelper.getContentType(exchange);
                        assertEquals("text/xml", type);
                        exchange.getOut().setBody("<status>OK</status>");
                        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/xml");
                    }
                });
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:RestletContentTypeTest.java


注:本文中的org.apache.camel.util.ExchangeHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。