當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。