當前位置: 首頁>>代碼示例>>Java>>正文


Java ExchangePhase類代碼示例

本文整理匯總了Java中org.switchyard.ExchangePhase的典型用法代碼示例。如果您正苦於以下問題:Java ExchangePhase類的具體用法?Java ExchangePhase怎麽用?Java ExchangePhase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExchangePhase類屬於org.switchyard包,在下文中一共展示了ExchangePhase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@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,代碼行數:22,代碼來源:ExchangeImpl.java

示例2: sendFault

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@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,代碼行數:20,代碼來源:ExchangeImpl.java

示例3: handleMessage

import org.switchyard.ExchangePhase; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void handleMessage(Exchange exchange) throws PolicyViolationException {
    // only execute on the IN phase
    if (ExchangePhase.IN.equals(exchange.getPhase())) {
        Set<Policy> required = PolicyUtil.getRequired(exchange);
        Iterator<Policy> reqIt = required.iterator();
        while (reqIt.hasNext()) {
            if (PolicyUtil.isProvided(exchange, reqIt.next())) {
                reqIt.remove();
            }
        }
        if (!required.isEmpty()) {
            // Required policies are missing.  Format the list for fault message.
            Iterator<Policy> missing = required.iterator();
            StringBuilder requires = new StringBuilder(missing.next().getQName().toString());
            while (missing.hasNext()) {
                requires.append(" " + missing.next().getQName().toString());
            }
            throw new PolicyViolationException(required, RuntimeMessages.MESSAGES.requiredPolicesNeeded(requires.toString()));
        }
    }
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:26,代碼來源:PolicyHandler.java

示例4: handleMessage

import org.switchyard.ExchangePhase; //導入依賴的package包/類
/**
 * Transform the current message on the exchange.
 * @param exchange exchange
 * @throws TransformationFailureException transformation failure exception
 */
@Override
public void handleMessage(Exchange exchange) throws TransformationFailureException {
    // Initialize transform sequence for operation types
    if (exchange.getPhase() == ExchangePhase.IN) {
        initInTransformSequence(exchange);
    } else {
        initOutTransformSequence(exchange);
    }
    
    // Apply transforms to the message...
    TransformSequence transformSequence = _registry.getTransformSequence(TransformSequence.getCurrentMessageType(exchange), TransformSequence.getTargetMessageType(exchange));
    if (transformSequence != null) {
        transformSequence.associateWith(exchange.getMessage());
    }

    TransformSequence.applySequence(exchange, _registry);
    if (!TransformSequence.assertTransformsApplied(exchange)) {
        QName actualPayloadType = TransformSequence.getCurrentMessageType(exchange);
        QName expectedPayloadType = TransformSequence.getTargetMessageType(exchange);
        throw new TransformationFailureException(RuntimeMessages.MESSAGES.transformationsNotApplied(expectedPayloadType.toString(), actualPayloadType.toString()));
    }

    // Replace the CONTENT_TYPE property to indicate current content type after transform
    setContentType(exchange);
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:31,代碼來源:TransformHandler.java

示例5: incompatibleRequirements_PropagatesAndSuspends

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void incompatibleRequirements_PropagatesAndSuspends() {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.SUSPENDS_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);

    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        // expected
        System.out.println(handlerEx.toString());
        return;
    }

    Assert.fail("Expected a handler exception due to incompatible policy");
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例6: incompatibleRequirements_managedGlobalAndNoManaged

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void incompatibleRequirements_managedGlobalAndNoManaged() {
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
    PolicyUtil.require(exchange, TransactionPolicy.NO_MANAGED_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);

    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        // expected
        System.out.println(handlerEx.toString());
        return;
    }

    Assert.fail("Expected a handler exception due to incompatible policy");
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例7: incompatibleRequirements_managedLocalAndNoManaged

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void incompatibleRequirements_managedLocalAndNoManaged() {
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_LOCAL);
    PolicyUtil.require(exchange, TransactionPolicy.NO_MANAGED_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);

    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        // expected
        System.out.println(handlerEx.toString());
        return;
    }

    Assert.fail("Expected a handler exception due to incompatible policy");
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例8: incompatibleRequirements_PropagatesAndManagedLocal

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void incompatibleRequirements_PropagatesAndManagedLocal() {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_LOCAL);
    exchange.setPhase(ExchangePhase.IN);

    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        // expected
        System.out.println(handlerEx.toString());
        return;
    }

    Assert.fail("Expected a handler exception due to incompatible policy");
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例9: incompatibleRequirements_PropagatesAndNoManaged

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void incompatibleRequirements_PropagatesAndNoManaged() {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.NO_MANAGED_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);

    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        // expected
        System.out.println(handlerEx.toString());
        return;
    }

    Assert.fail("Expected a handler exception due to incompatible policy");
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例10: propagateProvidedButNotRequired

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void propagateProvidedButNotRequired() throws Exception {
    // We currently view a propagated transaction without a requirement
    // as harmless. This tests confirms this behavior and acts as a guard
    // in case our behavior changes.
    PolicyUtil.provide(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);
    tm.begin();
    
    try {
        handler.handleMessage(exchange);
    } catch (HandlerException handlerEx) {
        Assert.fail("Exception not expected when transaction is provided but not required: "
                + handlerEx);
    }
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例11: propagateRequiredAndProvided

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void propagateRequiredAndProvided() throws Exception {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.provide(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    exchange.setPhase(ExchangePhase.IN);

    tm.begin();
    Transaction tx = tm.getTransaction();

    handler.handleMessage(exchange);
    exchange.setPhase(ExchangePhase.OUT);
    handler.handleMessage(exchange);

    Transaction tx2 = tm.getTransaction();
    Assert.assertEquals(tx, tx2);
    Assert.assertEquals(Status.STATUS_ACTIVE, tx2.getStatus());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:18,代碼來源:TransactionHandlerTest.java

示例12: propagateRequiredButNotProvidedWithManagedGlobalRequired

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void propagateRequiredButNotProvidedWithManagedGlobalRequired() throws Exception {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
    exchange.setPhase(ExchangePhase.IN);

    Assert.assertEquals(null, tm.getTransaction());

    handler.handleMessage(exchange);
    Transaction tx = tm.getTransaction();
    Assert.assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.PROPAGATES_TRANSACTION));
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL));

    exchange.setPhase(ExchangePhase.OUT);
    handler.handleMessage(exchange);
    Assert.assertEquals(Status.STATUS_COMMITTED, tx.getStatus());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:19,代碼來源:TransactionHandlerTest.java

示例13: managedLocalRequiredWithNoTransactionProvided

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void managedLocalRequiredWithNoTransactionProvided() throws Exception {
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_LOCAL);
    exchange.setPhase(ExchangePhase.IN);
    
    Assert.assertEquals(null, tm.getTransaction());
    
    handler.handleMessage(exchange);
    Transaction tx = tm.getTransaction();
    Assert.assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.MANAGED_TRANSACTION_LOCAL));
    
    exchange.setPhase(ExchangePhase.OUT);
    handler.handleMessage(exchange);
    Assert.assertEquals(Status.STATUS_COMMITTED, tx.getStatus());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java

示例14: transactionRolledbackByHandler

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void transactionRolledbackByHandler() throws Exception {
    PolicyUtil.require(exchange, TransactionPolicy.PROPAGATES_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
    exchange.setPhase(ExchangePhase.IN);

    Assert.assertEquals(null, tm.getTransaction());

    handler.handleMessage(exchange);
    Transaction tx = tm.getTransaction();
    Assert.assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.PROPAGATES_TRANSACTION));
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL));

    tx.setRollbackOnly();
    exchange.setPhase(ExchangePhase.OUT);
    handler.handleMessage(exchange);
    Assert.assertEquals(Status.STATUS_ROLLEDBACK, tx.getStatus());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:20,代碼來源:TransactionHandlerTest.java

示例15: suspendAndManagedGlobalRequiredButNoTransaction

import org.switchyard.ExchangePhase; //導入依賴的package包/類
@Test
public void suspendAndManagedGlobalRequiredButNoTransaction() throws Exception {
    PolicyUtil.require(exchange, TransactionPolicy.SUSPENDS_TRANSACTION);
    PolicyUtil.require(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL);
    exchange.setPhase(ExchangePhase.IN);

    handler.handleMessage(exchange);
    Transaction tx2 = tm.getTransaction();
    Assert.assertEquals(Status.STATUS_ACTIVE, tx2.getStatus());
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.SUSPENDS_TRANSACTION));
    Assert.assertTrue(PolicyUtil.isProvided(exchange, TransactionPolicy.MANAGED_TRANSACTION_GLOBAL));
    
    exchange.setPhase(ExchangePhase.OUT);
    handler.handleMessage(exchange);
    Assert.assertEquals(Status.STATUS_COMMITTED, tx2.getStatus());
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:17,代碼來源:TransactionHandlerTest.java


注:本文中的org.switchyard.ExchangePhase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。