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


Java ExchangeHelper.isOutCapable方法代码示例

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


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

示例1: 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

示例2: 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

示例3: process

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
    InputSource is = exchange.getIn().getMandatoryBody(InputSource.class);
    XMLStreamReader stream = exchange.getIn().getMandatoryBody(XMLStreamReader.class);
    XMLReader reader = new StaxStreamXMLReader(stream);

    ContentHandler handler;
    if (contentHandlerClass != null) {
        handler = contentHandlerClass.newInstance();
    } else {
        handler = contentHandler;
    }
    reader.setContentHandler(handler);
    reader.parse(is);

    if (ExchangeHelper.isOutCapable(exchange)) {
        // preserve headers
        exchange.getOut().setHeaders(exchange.getIn().getHeaders());
        exchange.getOut().setBody(handler);
    } else {
        exchange.getIn().setBody(handler);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:StAXProcessor.java

示例4: 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 ctx       the channel handler context
 * @param message  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, ChannelHandlerContext ctx, Object message) throws Exception {
    Object body = message;

    if (LOG.isDebugEnabled()) {
        LOG.debug("Channel: {} received body: {}", new Object[]{ctx.channel(), 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, message);
    }

    // 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,代码行数:33,代码来源:ClientChannelHandler.java

示例5: 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

示例6: 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

示例7: 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

示例8: toExpression

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
 * Returns an expression processing the exchange to the given endpoint uri
 *
 * @param uri endpoint uri to send the exchange to
 * @return an expression object which will return the OUT body
 */
public static Expression toExpression(final String uri) {
    return new ExpressionAdapter() {
        public Object evaluate(Exchange exchange) {
            String text = simpleExpression(uri).evaluate(exchange, String.class);
            Endpoint endpoint = exchange.getContext().getEndpoint(text);
            if (endpoint == null) {
                throw new NoSuchEndpointException(text);
            }

            Producer producer;
            try {
                producer = endpoint.createProducer();
                producer.start();
                producer.process(exchange);
                producer.stop();
            } catch (Exception e) {
                throw ObjectHelper.wrapRuntimeCamelException(e);
            }

            // return the OUT body, but check for exchange pattern
            if (ExchangeHelper.isOutCapable(exchange)) {
                return exchange.getOut().getBody();
            } else {
                return exchange.getIn().getBody();
            }
        }

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

示例9: processExchange

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
/**
 * Creates exchange and processes it.
 *
 * @param consumer Holds processor and exception handler
 * @param message Message on which exchange is created
 * @param params Params of exchange
 * @return Response of exchange processing
 * @throws Exception
 */
private static Object processExchange(AvroConsumer consumer, Protocol.Message message, Object params) throws Exception {
    Object response;
    Exchange exchange = consumer.getEndpoint().createExchange(message, params);

    try {
        consumer.getProcessor().process(exchange);
    } catch (Throwable e) {
        consumer.getExceptionHandler().handleException(e);
    }

    if (ExchangeHelper.isOutCapable(exchange)) {
        response = exchange.getOut().getBody();
    } else {
        response = null;
    }

    boolean failed = exchange.isFailed();
    if (failed) {
        if (exchange.getException() != null) {
            throw exchange.getException();
        } else {
            // failed and no exception, must be a fault
            throw new AvroComponentException("Camel processing error.");
        }
    }
    return response;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:AvroListener.java

示例10: getAnswerMessage

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
protected Message getAnswerMessage(final Exchange exchange) {
    Message answer = exchange.getIn();
    if (ExchangeHelper.isOutCapable(exchange)) {
        answer = exchange.getOut();
        // preserve headers
        answer.getHeaders().putAll(exchange.getIn().getHeaders());
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:DefaultCommand.java

示例11: setResult

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
public void setResult(Exchange exchange, Object result) {
    if (ExchangeHelper.isOutCapable(exchange)) {
        exchange.getOut().setBody(result);
    } else {
        exchange.getIn().setBody(result);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:SWFEndpoint.java

示例12: setHeader

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
private void setHeader(Exchange exchange, String key, Object value) {
    if (ExchangeHelper.isOutCapable(exchange)) {
        exchange.getOut().setHeader(key, value);
    } else {
        exchange.getIn().setHeader(key, value);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:SWFWorkflowProducer.java

示例13: process

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    EventBus eventBus = getEndpoint().getEventBus();
    if (eventBus == null) {
        exchange.setException(new IllegalStateException("EventBus is not started or not configured"));
        callback.done(true);
        return true;
    }

    String address = getEndpoint().getAddress();

    boolean reply = ExchangeHelper.isOutCapable(exchange);
    boolean pubSub = getEndpoint().isPubSub();

    Object body = getVertxBody(exchange);
    if (body != null) {
        if (reply) {
            LOG.debug("Sending to: {} with body: {}", address, body);
            eventBus.send(address, body, new CamelReplyHandler(exchange, callback));
            return false;
        } else {
            if (pubSub) {
                LOG.debug("Publishing to: {} with body: {}", address, body);
                eventBus.publish(address, body);
            } else {
                LOG.debug("Sending to: {} with body: {}", address, body);
                eventBus.send(address, body);
            }
            callback.done(true);
            return true;
        }
    }

    exchange.setException(new InvalidPayloadRuntimeException(exchange, String.class));
    callback.done(true);
    return true;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:VertxProducer.java

示例14: process

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
  Message in = exchange.getIn();

  Object body = CamelHelper.convert(inbound, in);

  DeliveryOptions delivery = CamelHelper.getDeliveryOptions(in, inbound.isHeadersCopy());
  if (inbound.getTimeout() > 0) {
    delivery.setSendTimeout(inbound.getTimeout());
  }

  try {
    if (inbound.isPublish()) {
      vertx.eventBus().publish(inbound.getAddress(), body, delivery);
    } else {
      if (ExchangeHelper.isOutCapable(exchange)) {
        vertx.eventBus().send(inbound.getAddress(), body, delivery, reply -> {
          Message out = exchange.getOut();
          if (reply.succeeded()) {
            out.setBody(reply.result().body());
            MultiMapHelper.toMap(reply.result().headers(), out.getHeaders());
          } else {
            exchange.setException(reply.cause());
          }
          // continue callback
          callback.done(false);
        });
        // being routed async so return false
        return false;
      } else {
        // No reply expected.
        vertx.eventBus().send(inbound.getAddress(), body, delivery);
      }
    }
  } catch (Throwable e) {
    // Mark the exchange as "failed".
    exchange.setException(e);
  }

  callback.done(true);
  return true;
}
 
开发者ID:vert-x3,项目名称:vertx-camel-bridge,代码行数:43,代码来源:CamelToVertxProcessor.java

示例15: channelRead0

import org.apache.camel.util.ExchangeHelper; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    messageReceived = true;

    if (LOG.isTraceEnabled()) {
        LOG.trace("Message received: {}", msg);
    }

    ChannelHandler handler = ctx.pipeline().get("timeout");
    if (handler != null) {
        LOG.trace("Removing timeout channel as we received message");
        ctx.pipeline().remove(handler);
    }

    Exchange exchange = getExchange(ctx);
    if (exchange == null) {
        // we just ignore the received message as the channel is closed
        return;
    }
    AsyncCallback callback = getAsyncCallback(ctx);

    Message message;
    try {
        message = getResponseMessage(exchange, ctx, msg);
    } catch (Exception e) {
        exchange.setException(e);
        callback.done(false);
        return;
    }

    // set the result on either IN or OUT on the original exchange depending on its pattern
    if (ExchangeHelper.isOutCapable(exchange)) {
        exchange.setOut(message);
    } else {
        exchange.setIn(message);
    }

    try {
        // should channel be closed after complete?
        Boolean close;
        if (ExchangeHelper.isOutCapable(exchange)) {
            close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
        } else {
            close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
        }

        // check the setting on the exchange property
        if (close == null) {
            close = exchange.getProperty(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
        }

        // should we disconnect, the header can override the configuration
        boolean disconnect = producer.getConfiguration().isDisconnect();
        if (close != null) {
            disconnect = close;
        }
        // we should not close if we are reusing the channel
        if (!producer.getConfiguration().isReuseChannel() && disconnect) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Closing channel when complete at address: {}", producer.getConfiguration().getAddress());
            }
            NettyHelper.close(ctx.channel());
        }
    } finally {
        // signal callback
        callback.done(false);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:69,代码来源:ClientChannelHandler.java


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