Package org.switchyard.remote

Examples of org.switchyard.remote.RemoteMessage


            ClassLoader loader = (ClassLoader) domain.getProperty(Deployment.CLASSLOADER_PROPERTY);
            setTCCL = Classes.setTCCL(loader);
           
            transactionPropagated = bridgeIncomingTransaction(request);

            RemoteMessage msg = _serializer.deserialize(request.getInputStream(), RemoteMessage.class);
            if (_log.isDebugEnabled()) {
                _log.debug("Remote servlet received request for service " + msg.getService());
            }
           
            ServiceReference service = domain.getServiceReference(msg.getService());
            SynchronousInOutHandler replyHandler = new SynchronousInOutHandler();
            Exchange ex = msg.getOperation() == null
                    ? service.createExchange(replyHandler)
                    : service.createExchange(msg.getOperation(), replyHandler);
            Message m = ex.createMessage();
            if (msg.getContext() != null) {
                m.getContext().setProperties(msg.getContext().getProperties());
            }
            m.setContent(msg.getContent());
           
            if (_log.isDebugEnabled()) {
                _log.debug("Invoking service " + msg.getService());
            }
            ex.send(m);
           
            // handle reply or fault
            RemoteMessage reply = null;
            if (ExchangePattern.IN_OUT.equals(ex.getPattern())) {
                replyHandler.waitForOut();
                reply = createReplyMessage(ex);
            } else if (ExchangeState.FAULT.equals(ex.getState())) {
                // Even though this is in-only, we need to report a runtime fault on send
                reply = createReplyMessage(ex);
            }
            if (transactionPropagated) {
                bridgeOutgoingTransaction();
                transactionPropagated = false;
            }

            // If there's a reply, send it back
            if (reply != null) {
                OutputStream out = response.getOutputStream();
                if (_log.isDebugEnabled()) {
                    _log.debug("Writing reply message to HTTP response stream " + msg.getService());
                }
                _serializer.serialize(reply, RemoteMessage.class, out);
                out.flush();
            } else {
                response.setStatus(HttpServletResponse.SC_NO_CONTENT);
                if (_log.isDebugEnabled()) {
                    _log.debug("No content to return for invocation of " + msg.getService());
                }
            }
        } catch (SwitchYardException syEx) {
            if (_log.isDebugEnabled()) {
                _log.debug("Failed to process remote invocation", syEx);
            }

            RemoteMessage reply = new RemoteMessage();
            reply.setFault(true);
            reply.setContent(syEx);
            _serializer.serialize(reply, RemoteMessage.class, response.getOutputStream());
            response.getOutputStream().flush();
        } finally {
            if (transactionPropagated) {
                bridgeOutgoingTransaction();
View Full Code Here


    public void setEndpointPublisher(RemoteEndpointPublisher endpointPublisher) {
        _endpointPublisher = endpointPublisher;
    }
   
    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;
    }
View Full Code Here

        Mockito.when(mockEx.getContract().getConsumerOperation().getName()).thenReturn("test-operation");
        Mockito.when(mockEx.getProvider().getDomain().getName()).thenReturn(new QName("test-domain"));
        Mockito.when(mockEx.getMessage().getContent()).thenReturn("test-content");
        scaInvoker.handleMessage(mockEx);
       
        RemoteMessage remoteMsg = msgs.pop();
        Assert.assertEquals(new QName("test-domain"), remoteMsg.getDomain());
        Assert.assertEquals("test-operation", remoteMsg.getOperation());
        Assert.assertEquals("test-content", remoteMsg.getContent());
    }
View Full Code Here

   
    @Test
    public void noOperationName() throws Exception {
        domain.registerServiceReference(TEST_SERVICE, new InOnlyService());
        domain.registerService(TEST_SERVICE, new InOnlyService(), new MockHandler());
        RemoteMessage msg = new RemoteMessage()
            .setService(TEST_SERVICE);
        setRequestMessage(msg);
        servlet.doPost(request, response);
    }
View Full Code Here

    public void noOperationNameMultipleOperations() throws Exception {
        MockHandler handler = new MockHandler();
        domain.registerServiceReference(TEST_SERVICE, JavaService.fromClass(MyInterface.class));
        domain.registerService(TEST_SERVICE, JavaService.fromClass(MyInterface.class), handler);
       
        RemoteMessage msg = new RemoteMessage()
            .setService(TEST_SERVICE);
        setRequestMessage(msg);
       
        try {
            servlet.doPost(request, response);
View Full Code Here

    public void operationNameMultipleOperations() throws Exception {
        MockHandler handler = new MockHandler();
        domain.registerServiceReference(TEST_SERVICE, JavaService.fromClass(MyInterface.class));
        domain.registerService(TEST_SERVICE, JavaService.fromClass(MyInterface.class), handler);
       
        RemoteMessage msg = new RemoteMessage()
            .setService(TEST_SERVICE)
            .setOperation("bar");
        setRequestMessage(msg);
        servlet.doPost(request, response);
       
View Full Code Here

   
    private void invokeRemote(Exchange exchange) throws HandlerException {
        // Figure out the QName for the service were invoking
        QName serviceName = getTargetServiceName(exchange);

        RemoteMessage request = new RemoteMessage()
            .setDomain(exchange.getProvider().getDomain().getName())
            .setService(serviceName)
            .setOperation(exchange.getContract().getConsumerOperation().getName())
            .setContent(exchange.getMessage().getContent());
        exchange.getContext().mergeInto(request.getContext());
        boolean transactionPropagated = bridgeOutgoingTransaction(request);

        try {
            RemoteMessage reply = _invoker.invoke(request);
            if (transactionPropagated) {
                bridgeIncomingTransaction();
            }
            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()) {
                    exchange.sendFault(msg);
                } else {
                    exchange.send(msg);
                }
            } else {
                // still need to account for runtime exceptions on in-only
                if (reply.isFault()) {
                    throw createHandlerException(reply.getContent());
                }
            }
        } catch (java.io.IOException ioEx) {
            ioEx.printStackTrace();
            exchange.sendFault(exchange.createMessage().setContent(ioEx));
View Full Code Here

        _endpoint = endpoint;
    }

    @Override
    public RemoteMessage invoke(RemoteMessage request) throws java.io.IOException {
        RemoteMessage reply = null;
        HttpURLConnection conn = null;
       
        if (_log.isDebugEnabled()) {
            _log.debug("Invoking " + request.getService() + " at endpoint " + _endpoint.toString());
        }
View Full Code Here

        // Create request payload
        Offer offer = createOffer(true);

        // Create the request message
        RemoteMessage message = new RemoteMessage();
        message.setService(SERVICE).setOperation("offer").setContent(offer);

        // Invoke the service
        RemoteMessage reply = invoker.invoke(message);
        if (reply.isFault()) {
            System.err.println("Oops ... something bad happened.  "
                + reply.getContent());
        } else {
            Deal deal = (Deal) reply.getContent();
            out.println("==================================");
            out.println("Was the offer accepted? " + deal.isAccepted());
            out.println("==================================");
        }
    }
View Full Code Here

        order.setItemId("Turkey");
        order.setOrderId("Xmas Dinner");
        order.setQuantity(1);

        // Create the request message
        RemoteMessage message = new RemoteMessage();
        message.setService(SERVICE).setOperation("submitOrder").setContent(order);

        // Invoke the service
        RemoteMessage reply = invoker.invoke(message);
        if (reply.isFault()) {
            System.err.println("Oops ... something bad happened.  " + reply.getContent());
        } else {
            OrderAck orderAck = (OrderAck) reply.getContent();
            out.println("==================================");
            out.println("Was the offer accepted? " + orderAck.isAccepted());
            out.println("==================================");
        }
    }
View Full Code Here

TOP

Related Classes of org.switchyard.remote.RemoteMessage

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.