boolean isNew() { return _exchange.getPhase() == null; }
boolean isNew() { return _exchange.getPhase() == null; }
/** * {@inheritDoc} */ public void before(String target, Exchange exchange) throws HandlerException { if (exchange.getPhase() == ExchangePhase.IN) { handleExchange(exchange); } }
/** * {@inheritDoc} */ public void after(String target, Exchange exchange) throws HandlerException { if (exchange.getPhase() == ExchangePhase.OUT) { handleExchange(exchange); } }
@Override public ExchangePhase getPhase() { return getExchange().getPhase(); }
@Override public ExchangePhase getPhase() { return getExchange().getPhase(); }
/** * {@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())); } } }
@Override public void dispatch(final Exchange exchange) { switch (exchange.getPhase()) { case IN: _requestChain.handle(exchange); break; case OUT: ExchangeHandler replyHandler = ((ExchangeImpl)exchange).getReplyHandler(); if (replyHandler != null) { _replyChain.replace(HandlerChain.CONSUMER_HANDLER, replyHandler); } _replyChain.handle(exchange); break; default: throw RuntimeMessages.MESSAGES.invalidPhaseForDispatch(exchange.getPhase().toString()); } }
@Override public void dispatch(final Exchange exchange) { switch (exchange.getPhase()) { case IN: _requestChain.handle(exchange); break; case OUT: ExchangeHandler replyHandler = ((ExchangeImpl)exchange).getReplyHandler(); if (replyHandler != null) { _replyChain.replace(HandlerChain.CONSUMER_HANDLER, replyHandler); } _replyChain.handle(exchange); break; default: throw RuntimeMessages.MESSAGES.invalidPhaseForDispatch(exchange.getPhase().toString()); } }
@Test public void testPhaseIsNullOnNewExchange() { Exchange exchange = new ExchangeImpl(_domain, _dispatch); Assert.assertNull(exchange.getPhase()); }
/** * {@inheritDoc} */ @Override public final void handleMessage(Exchange exchange) throws HandlerException { if (ExchangePhase.IN.equals(exchange.getPhase())) { ExchangeContract contract = exchange.getContract(); KnowledgeOperation operation = getOperation(contract.getProviderOperation()); if (operation == null) { operation = getOperation(contract.getConsumerOperation()); } if (operation == null) { // we use "default" here instead of getDefaultOperation() so that a // user can define a name="default" in their switchyard.xml operation = _operations.get(DEFAULT); } handleOperation(exchange, operation); } }
/** * {@inheritDoc} */ @Override public final void handleMessage(Exchange exchange) throws HandlerException { if (ExchangePhase.IN.equals(exchange.getPhase())) { ExchangeContract contract = exchange.getContract(); KnowledgeOperation operation = getOperation(contract.getProviderOperation()); if (operation == null) { operation = getOperation(contract.getConsumerOperation()); } if (operation == null) { // we use "default" here instead of getDefaultOperation() so that a // user can define a name="default" in their switchyard.xml operation = _operations.get(DEFAULT); } handleOperation(exchange, operation); } }
/** * Returns the current message type based on the state of the exchange. * @param exchange exchange to query * @return the current message type based on the exchange contract */ public static QName getMessageType(Exchange exchange) { QName msgType; if (exchange.getPhase() == null) { msgType = exchange.getContract().getConsumerOperation().getInputType(); } else { msgType = exchange.getContract().getProviderOperation().getOutputType(); } return msgType; }
private static String formatHeaders(Exchange exchange) { StringBuilder headers = new StringBuilder() .append(indent(0) + "Consumer -> " + exchange.getConsumer().getName()) .append(indent(0) + "Provider -> " + ((exchange.getProvider() == null) ? "[unassigned]" : exchange.getProvider().getName())) .append(indent(0) + "Operation -> " + exchange.getContract().getConsumerOperation().getName()) .append(indent(0) + "MEP -> " + ((exchange.getContract().getConsumerOperation().getExchangePattern() == null) ? "[unassigned]" : exchange.getContract().getConsumerOperation().getExchangePattern())) .append(indent(0) + "Phase -> " + exchange.getPhase()) .append(indent(0) + "State -> " + exchange.getState()); // Add context properties headers.append(indent(0) + "Exchange Context -> "); dumpContext(headers, exchange.getContext().getProperties(Scope.EXCHANGE)); headers.append(indent(0) + "Message Context -> "); dumpContext(headers, exchange.getContext().getProperties(Scope.MESSAGE)); return headers.toString(); }
/** * Returns the current message type based on the state of the exchange. * @param exchange exchange to query * @return the current message type based on the exchange contract */ public static QName getMessageType(Exchange exchange) { QName msgType; if (exchange.getPhase() == null) { msgType = exchange.getContract().getConsumerOperation().getInputType(); } else { msgType = exchange.getContract().getProviderOperation().getOutputType(); } return msgType; }
private static String formatHeaders(Exchange exchange) { StringBuilder headers = new StringBuilder() .append(indent(0) + "Consumer -> " + exchange.getConsumer().getName()) .append(indent(0) + "Provider -> " + ((exchange.getProvider() == null) ? "[unassigned]" : exchange.getProvider().getName())) .append(indent(0) + "Operation -> " + exchange.getContract().getConsumerOperation().getName()) .append(indent(0) + "MEP -> " + ((exchange.getContract().getConsumerOperation().getExchangePattern() == null) ? "[unassigned]" : exchange.getContract().getConsumerOperation().getExchangePattern())) .append(indent(0) + "Phase -> " + exchange.getPhase()) .append(indent(0) + "State -> " + exchange.getState()); // Add context properties headers.append(indent(0) + "Exchange Context -> "); dumpContext(headers, exchange.getContext().getProperties(Scope.EXCHANGE)); headers.append(indent(0) + "Message Context -> "); dumpContext(headers, exchange.getContext().getProperties(Scope.MESSAGE)); return headers.toString(); }
@Test public void testPhaseIsInAfterInputMessage() { ServiceReference service = _domain.createInOnlyService(new QName("InPhase")); Exchange exchange = service.createExchange(); exchange.send(exchange.createMessage()); Assert.assertEquals(ExchangePhase.IN, exchange.getPhase()); }
@Test public void testPhaseIsOutAfterOutputMessage() { MockHandler replyHandler = new MockHandler(); ServiceReference service = _domain.createInOutService( new QName("OutPhase"), new MockHandler().forwardInToOut()); Exchange exchange = service.createExchange(replyHandler); exchange.send(exchange.createMessage()); replyHandler.waitForOKMessage(); Assert.assertEquals(ExchangePhase.OUT, exchange.getPhase()); }
@Test public void testPhaseIsOutAfterFaultMessage() { MockHandler replyHandler = new MockHandler(); ServiceReference service = _domain.createInOutService( new QName("FaultPhase"), new MockHandler().forwardInToFault()); Exchange exchange = service.createExchange(replyHandler); exchange.send(exchange.createMessage()); replyHandler.waitForFaultMessage(); Assert.assertEquals(ExchangePhase.OUT, exchange.getPhase()); }
@Override public void dispatch(final Exchange exchange) { // We can only send Camel exchanges through the camel bus if (!CamelExchange.class.isInstance(exchange)) { throw BusMessages.MESSAGES.onlyCamelExchanges(); } CamelExchange camelEx = (CamelExchange)exchange; // For camel exchanges, the only phase we care about is IN. The dispatch method can also // be called on the OUT path, but that should be handled by the IN_OUT filter in the Camel // bus route. if (!exchange.getPhase().equals(ExchangePhase.IN)) { return; } Throttling throttling = _reference.getServiceMetadata().getThrottling(); if (throttling != null && throttling.getMaxRequests() > 0) { exchange.getMessage().getContext().setProperty( Throttling.MAX_REQUESTS, throttling.getMaxRequests()) .addLabels(BehaviorLabel.TRANSIENT.label()); } _producer.send("direct:" + exchange.getConsumer().getName(), camelEx.getExchange()); }