Package org.switchyard

Examples of org.switchyard.Message


    }
   
    @Test
    public void invokeRequestResponseProviderWithInOut() {
        String ECHO_MSG = "hello";
        Message response = reply.sendInOut(ECHO_MSG);

        Assert.assertEquals(ECHO_MSG, response.getContent());
    }
View Full Code Here


                    camelFault = camelExchange.getOut().getBody();
                }
            }

            if (camelFault != null && declaredFault != null && declaredFault.isAssignableFrom(camelFault.getClass())) {
                Message msg = switchyardExchange.createMessage().setContent(camelFault);
                switchyardExchange.sendFault(msg);
            } else if (camelFault instanceof Throwable) {
                throw new HandlerException(Throwable.class.cast(camelFault));
            } else if (camelFault instanceof Node) {
                Message msg = switchyardExchange.createMessage().setContent((Node)camelFault);
                switchyardExchange.sendFault(msg);
            } else {
                String faultMessage = (camelFault == null) ? null : camelFault.toString();
                throw SwitchYardCamelComponentMessages.MESSAGES.camelExchangeFailedWithoutException(faultMessage);
            }
View Full Code Here

            throw new HandlerException(e);
        }
    }

    private void sendResponse(org.apache.camel.Exchange camelExchange, final Exchange switchyardExchange) throws HandlerException {    
        Message message = ExchangeMapper.mapCamelToSwitchYard(
                camelExchange, switchyardExchange, ExchangePhase.OUT);
        switchyardExchange.send(message);
    }
View Full Code Here

    /**
     * Gets the {@link Message} for the current thread.
     * @return the message
     */
    private static Message getMessage() {
        Message message = MESSAGE.get();
        if (message == null) {
            throw BeanMessages.MESSAGES.illegalCallToGetTheSwitchYardContextMustBeCalledWithinTheExecutionOfAnExchangeHandlerChain();
        }
        return message;
    }
View Full Code Here

    @Test
    public void standardDocLitOperation() throws Exception {
       
        DOMSource domSource = new DOMSource(_testKit.readResourceDocument("/doclit_request.xml"));
        Message responseMsg = consumerService.operation("submitOrder").sendInOut(toString(domSource.getNode()));
        String response = toString(responseMsg.getContent(Node.class));
        _testKit.compareXMLToResource(response, "/doclit_response.xml");
       
    }
View Full Code Here

            if (reply == null) {
                return;
            }
           
            if (ExchangePattern.IN_OUT.equals(exchange.getPattern())) {
                Message msg = exchange.createMessage();
                msg.setContent(reply.getContent());
                Context replyCtx = reply.getContext();
                if (replyCtx != null) {
                    replyCtx.mergeInto(exchange.getContext());
                }
                if (reply.isFault()) {
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void handleMessage(final Exchange exchange) throws HandlerException {
        Message message = exchange.getMessage();
        Node request = message.getContent(Node.class);

        Map<String, Object> headers = new HashMap<String, Object>();
        for (Property p : exchange.getContext().getProperties()) {
            if (p.hasLabel(EndpointLabel.SOAP.label())) {
                headers.put(p.getName(), p.getValue());
            }
        }

        try {
            // Find part name associated with operation on port type
            javax.wsdl.Operation operation =
                    _portType.getOperation(exchange.getContract().
                            getProviderOperation().getName(),
                                null, null);

            Element newreq =
                    WSDLHelper.wrapRequestMessagePart((Element) request,
                                    operation);

            // Invoke the operation on the BPEL process
            Element response = _engine.invoke(_serviceName, null,
                    exchange.getContract().
                    getProviderOperation().getName(),
                            newreq, headers);

            if (exchange.getContract().getProviderOperation().
                    getExchangePattern().equals(ExchangePattern.IN_OUT)) {

                Message reply = exchange.createMessage();

                // Strip off wrapper and part to just return
                // the part contents
                reply.setContent(WSDLHelper.unwrapMessagePart(response));
               
                // Set header parts for a response message
                for (Map.Entry<String, Object> e : headers.entrySet()) {
                    exchange.getContext(reply).setProperty(e.getKey(),
                            headers.get(e.getKey())).addLabels(EndpointLabel.SOAP.label());
                }               

                exchange.send(reply);
            }
        } catch (Fault f) {
            SOAPFault fault = null;

            try {
                fault = javax.xml.soap.SOAPFactory.newInstance().
                        createFault("", f.getFaultName());

                Detail detail=fault.addDetail();
                Node cloned=detail.getOwnerDocument().importNode(WSDLHelper.unwrapMessagePart(f.getFaultMessage()), true);
                detail.appendChild(cloned);
       
            } catch (Exception e) {
                throw new HandlerException(e);
            }
           
            Message msg = exchange.createMessage().setContent(fault);
            exchange.sendFault(msg);
           
        } catch (Exception e) {
            throw new HandlerException(e);
        }
View Full Code Here

           
            // Need to create an exchange
            SynchronousInOutHandler rh = new SynchronousInOutHandler();
            Exchange exchange=_serviceReference.createExchange(operationName, rh);

            Message req = exchange.createMessage();
            req.setContent(node);
            if (headers != null) {
               
                for (Map.Entry<String, Object> e : headers.entrySet()) {
                    exchange.getContext(req).setProperty(e.getKey(), headers.get(e.getKey())).addLabels(EndpointLabel.SOAP.label());
                   
                }
               
                // Clear the headers in preparation for response headers
                headers.clear();
            }
           
            exchange.send(req);

            try {
                exchange = rh.waitForOut(_waitTimeout);
            } catch (DeliveryException e) {
                throw BPELMessages.MESSAGES.timedOutAfterMsWaitingOnSynchronousResponseFromTargetService(_waitTimeout, _serviceReference.getName().toString());
            }
           
            Message resp=exchange.getMessage();
           
            if (resp == null) {
                throw BPELMessages.MESSAGES.responseNotReturnedFromOperationOnService(operationName, _serviceReference.getName().toString());
            }
           
            // Process header values associated with the response
            for (org.switchyard.Property p : exchange.getContext().getProperties(Scope.MESSAGE)) {
                if (p.hasLabel(EndpointLabel.SOAP.label())) {
                    headers.put(p.getName(), p.getValue());
                }
            }
           
            // Check for exception - but don't rethrow a BPEL
            // fault as it will be converted to a message
            // response
            if (resp.getContent() instanceof Exception
                    && !(resp.getContent() instanceof BPELFault)) {
                throw (Exception)resp.getContent();
            }
           
            Element respelem=(Element)resp.getContent(Node.class);
           
            javax.wsdl.Operation operation=_portType.getOperation(operationName, null, null);
           
            if (exchange.getState() == ExchangeState.FAULT) {
                QName faultCode=null;
View Full Code Here

    private Invoker _store;
   
    @Test
    public void testReferenceBindingInOut() throws Exception {
        final String payload = "store/IN_OUT";
        Message msg = null;
        try {
            msg = _store.sendInOut(payload);
        } catch (Throwable t) {
            System.out.println("Received an Exception: " + formatThrowable(t));
            return;
        }
        Assert.fail("It succeeded while an Exception is expected: " + msg.getContent());
    }
View Full Code Here

    }
   
    @Test
    public void testBeanServiceInOut() throws Exception {
        final String payload = "greet/IN_OUT";
        Message msg = null;
        try {
            msg = _greet.sendInOut(payload);
        } catch (Throwable t) {
            System.out.println("Received an Exception: " + formatThrowable(t));
            return;
        }
        Assert.fail("It succeeded while an Exception is expected: " + msg.getContent());
    }
View Full Code Here

TOP

Related Classes of org.switchyard.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.