本文整理汇总了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);
}
示例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);
}
示例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()));
}
}
}
示例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);
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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");
}
示例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);
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}