@Override public ExchangeContract getContract() { return getExchange().getContract(); }
@Override public ExchangeContract getContract() { return getExchange().getContract(); }
private boolean isInOnly(final Exchange exchange) { return exchange.getContract().getConsumerOperation().getExchangePattern() == ExchangePattern.IN_ONLY; }
private boolean isInOut(final Exchange exchange) { return exchange.getContract().getProviderOperation().getExchangePattern() == ExchangePattern.IN_OUT; }
private boolean isInOnly(final Exchange exchange) { return exchange.getContract().getConsumerOperation().getExchangePattern() == ExchangePattern.IN_ONLY; }
private boolean isInOut(final Exchange exchange) { return exchange.getContract().getProviderOperation().getExchangePattern() == ExchangePattern.IN_OUT; }
/** * 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; }
/** * 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; }
@Override public void recordMetrics(Exchange exchange) { final String operationName = exchange.getContract().getProviderOperation().getName(); if (operationName != null) { for (final ServiceOperation operation : _operations) { if (operationName.equals(operation.getName())) { operation.recordMetrics(exchange); break; } } } super.recordMetrics(exchange); }
private void initInTransformSequence(Exchange exchange) { QName exchangeInputType = exchange.getContract().getConsumerOperation().getInputType(); QName serviceOperationInputType = exchange.getContract().getProviderOperation().getInputType(); if (exchangeInputType != null && serviceOperationInputType != null) { TransformSequence. from(exchangeInputType). to(serviceOperationInputType). associateWith(exchange.getMessage()); } }
private void initOutTransformSequence(Exchange exchange) { QName serviceOperationOutputType = exchange.getContract().getProviderOperation().getOutputType(); QName exchangeOutputType = exchange.getContract().getConsumerOperation().getOutputType(); if (serviceOperationOutputType != null && exchangeOutputType != null) { TransformSequence. from(serviceOperationOutputType). to(exchangeOutputType). associateWith(exchange.getMessage()); } }
private void initOutTransformSequence(Exchange exchange) { QName serviceOperationOutputType = exchange.getContract().getProviderOperation().getOutputType(); QName exchangeOutputType = exchange.getContract().getConsumerOperation().getOutputType(); if (serviceOperationOutputType != null && exchangeOutputType != null) { TransformSequence. from(serviceOperationOutputType). to(exchangeOutputType). associateWith(exchange.getMessage()); } }
private void initInTransformSequence(Exchange exchange) { QName exchangeInputType = exchange.getContract().getConsumerOperation().getInputType(); QName serviceOperationInputType = exchange.getContract().getProviderOperation().getInputType(); if (exchangeInputType != null && serviceOperationInputType != null) { TransformSequence. from(exchangeInputType). to(serviceOperationInputType). associateWith(exchange.getMessage()); } }
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(); }
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(); }
/** * {@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); } }
@Test public void testCreateExchange() { Exchange inOnly = _inOnlyReference.createExchange(); inOnly.consumer(null, new InOnlyOperation("foo")); Assert.assertEquals(ExchangePattern.IN_ONLY, inOnly.getContract().getConsumerOperation().getExchangePattern()); Exchange inOut = _inOutReference.createExchange(new MockHandler()); inOut.consumer(null, new InOutOperation("foo")); Assert.assertEquals(ExchangePattern.IN_OUT, inOut.getContract().getConsumerOperation().getExchangePattern()); }
@Override public void handleMessage(final Exchange exchange) throws HandlerException { // identify ourselves exchange.getContext() .setProperty(ExchangeCompletionEvent.GATEWAY_NAME, _bindingName, Scope.EXCHANGE).addLabels(BehaviorLabel.TRANSIENT.label()); if (getState() != State.STARTED) { throw JCAMessages.MESSAGES.referenceBindingNotStarted(_referenceName, _bindingName); } Message out = _processor.process(exchange); if (exchange.getContract().getProviderOperation().getExchangePattern() == ExchangePattern.IN_OUT) { exchange.send(out); } } }
RemoteMessage createReplyMessage(Exchange exchange) { RemoteMessage reply = new RemoteMessage(); reply.setDomain(exchange.getProvider().getDomain().getName()) .setOperation(exchange.getContract().getConsumerOperation().getName()) .setService(exchange.getConsumer().getName()); exchange.getContext().mergeInto(reply.getContext()); if (exchange.getMessage() != null) { reply.setContent(exchange.getMessage().getContent()); } if (exchange.getState().equals(ExchangeState.FAULT)) { reply.setFault(true); } return reply; }
RemoteMessage createReplyMessage(Exchange exchange) { RemoteMessage reply = new RemoteMessage(); reply.setDomain(exchange.getProvider().getDomain().getName()) .setOperation(exchange.getContract().getConsumerOperation().getName()) .setService(exchange.getConsumer().getName()); exchange.getContext().mergeInto(reply.getContext()); if (exchange.getMessage() != null) { reply.setContent(exchange.getMessage().getContent()); } if (exchange.getState().equals(ExchangeState.FAULT)) { reply.setFault(true); } return reply; }