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


Java ExchangePhase.OUT属性代码示例

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


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

示例1: send

@Override
public synchronized void send(Message message) {
    assertMessageOK(message);

    // Set exchange phase
    if (_phase == null) {
        _phase = ExchangePhase.IN;
        initContentType(message);
    } else if (_phase.equals(ExchangePhase.IN)) {
        _phase = ExchangePhase.OUT;
        initContentType(message);
        // set relatesTo header on OUT context
        Object propertyValue = _message.getContext().getPropertyValue(MESSAGE_ID);
        message.getContext().setProperty(RELATES_TO, propertyValue)
            .addLabels(BehaviorLabel.TRANSIENT.label());
    } else {
        throw RuntimeMessages.MESSAGES.sendMessageNotAllowed(_phase.toString());
    }

    sendInternal(message);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:21,代码来源:ExchangeImpl.java

示例2: sendFault

@Override
public synchronized void sendFault(Message message) {
    assertMessageOK(message);
    
    // You can't send a fault before you send a message
    if (_phase == null) {
        throw RuntimeMessages.MESSAGES.sendFaultNotAllowed();
    }
    
    _phase = ExchangePhase.OUT;
    _state = ExchangeState.FAULT;
    initFaultContentType();

    // set relatesTo header on OUT context
    message.getContext().setProperty(RELATES_TO, _message.getContext().getPropertyValue(MESSAGE_ID))
        .addLabels(BehaviorLabel.TRANSIENT.label());

    sendInternal(message);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:19,代码来源:ExchangeImpl.java

示例3: handleMessage

@Override
public void handleMessage(Exchange exchange) throws HandlerException {
    if (exchange.getPhase() == ExchangePhase.OUT) {
        throw new RuntimeException("Outgoing runtime error");
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:6,代码来源:RuntimeErrorOutHandler.java

示例4: handle

/**
 * Handle the Service bean invocation.
 *
 * @param exchange The Exchange instance.
 * @throws HandlerException Error invoking Bean component operation.
 */
private void handle(Exchange exchange) throws HandlerException {
    Invocation invocation = _serviceMetadata.getInvocation(exchange);

    if (invocation != null) {
        ExchangePattern exchangePattern = exchange.getContract().getProviderOperation().getExchangePattern();
        try {

            if (_logger.isDebugEnabled()) {
                _logger.debug("CDI Bean Service ExchangeHandler proxy class received " + exchangePattern + " Exchange ("
                        + System.identityHashCode(exchange) + ") for Bean Service '"
                        + exchange.getProvider().getName() + "'.  Invoking bean method '" + invocation.getMethod().getName() + "'.");
            }

            Object responseObject;
            Context origContext = ContextProxy.setContext(exchange.getContext());
            Message origMessage = MessageProxy.setMessage(exchange.getMessage());
            Exchange origExchange = ExchangeProxy.setExchange(exchange);
            try {
                responseObject = invocation.getMethod().invoke(_serviceBean, invocation.getArgs());
            } finally {
                ContextProxy.setContext(origContext);
                MessageProxy.setMessage(origMessage);
                ExchangeProxy.setExchange(origExchange);
            }
            
            if (exchangePattern == ExchangePattern.IN_OUT 
                    && exchange.getPhase() != ExchangePhase.OUT) {
                Message message = exchange.createMessage();
                message.setContent(responseObject);
                exchange.send(message);
            }
        } catch (Exception ex) {
            String errMsg = BeanMessages.MESSAGES.invocationOfOperationFailed(invocation.getMethod().getName(),
                    _serviceBean.getClass().getName());
            // write error details to log
            if (_logger.isDebugEnabled()) {
                _logger.debug(errMsg, ex);
            }
            
            // if the exception is declared on service interface, use sendFault, otherwise throw an exception
            Throwable faultContent = ex;
            if (faultContent instanceof InvocationTargetException) {
                faultContent = ((InvocationTargetException)ex).getTargetException();
            }
            if (exchangePattern == ExchangePattern.IN_OUT) {
                for (Class<?> expectedFault : invocation.getMethod().getExceptionTypes()) {
                    if (expectedFault.isAssignableFrom(faultContent.getClass())) {
                        exchange.sendFault(exchange.createMessage().setContent(faultContent));
                        return;
                    }
                }
            }
            throw new HandlerException(faultContent);
        }
    } else {
        throw BeanMessages.MESSAGES.unexpectedErrorBeanServiceMetadataShouldReturnAnInvocationInstanceOrThrowABeanComponentException();
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:64,代码来源:ServiceProxyHandler.java


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