Package org.switchyard

Examples of org.switchyard.Message


    @Ignore // This can be tested only offline.
    @Test
    public void allIsWell() throws Exception {
        try {
            Message responseMsg = _authConsumerService2.operation(METHOD_NAME).sendInOut(input);
        } catch (Exception e) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            e.printStackTrace(new PrintStream(baos));
            // Because the local server is not setup with a SOAP Endpoint or to allow POST method.
            // If we get to this point then we are good.
View Full Code Here


            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);
View Full Code Here

    @Test
    public void testReconsumeStreamXml() throws Exception {
        InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(INPUT);
        _reconsume.inputType(TYPE);
        _reconsume.expectedOutputType(TYPE);
        Message response = _reconsume.sendInOut(stream);
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getContent(InputStream.class)));
        StringBuilder buf = new StringBuilder();
        String line;
        while((line = reader.readLine()) != null) {
            buf.append(line);
        }
View Full Code Here

        }
        SynchronousInOutHandler replyHandler = new SynchronousInOutHandler();
        Exchange ex = ref.createExchange(exchange.getContract().getProviderOperation().getName(), replyHandler);
       
        // Can't send same message twice, so make a copy
        Message invokeMsg = exchange.getMessage().copy();
        exchange.getContext().mergeInto(invokeMsg.getContext());
       
        // Since this invocation may cross application boundaries, we need to set the TCCL
        // based on the target service's application class loader
        ClassLoader origCL = null;
        try {
            ClassLoader targetCL = (ClassLoader)
                    ref.getDomain().getProperty(Deployment.CLASSLOADER_PROPERTY);
            origCL = Classes.setTCCL(targetCL);
            ex.send(invokeMsg);
        } finally {
            if (origCL != null) {
                Classes.setTCCL(origCL);
            }
        }
       
        if (ExchangePattern.IN_OUT.equals(ex.getPattern())) {
            replyHandler.waitForOut();
            if (ex.getMessage() != null) {
                Message replyMsg = ex.getMessage().copy();
                ex.getContext().mergeInto(replyMsg.getContext());
                if (ExchangeState.FAULT.equals(ex.getState())) {
                    exchange.sendFault(replyMsg);
                } else {
                    exchange.send(replyMsg);
                }
View Full Code Here

        }

        try {
            RESTEasyBindingData restResponse = methodInvoker.invoke(restRequest.getParameters(), restRequest.getHeaders());
            restResponse.setOperationName(opName);
            Message out = _messageComposer.compose(restResponse, exchange);
            // Our transformer magic transforms the entity appropriately here :)
            exchange.send(out);
        } catch (Exception e) {
            final String m = "Unexpected exception composing inbound Message from Outbound";
            LOGGER.error(m, e);
View Full Code Here

        exchange.getContext().setProperty(ExchangeCompletionEvent.GATEWAY_NAME, _gatewayName, Scope.EXCHANGE)
                .addLabels(BehaviorLabel.TRANSIENT.label());

        _securityContextManager.addCredentials(exchange, restMessageRequest.extractCredentials());

        Message message = null;
        try {
            message = _messageComposer.compose(restMessageRequest, exchange);
        } catch (WebApplicationException wae) {
            throw wae;
        } catch (Exception e) {
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public Message compose(RESTEasyBindingData source, Exchange exchange) throws Exception {
        final Message message = exchange.createMessage();
        getContextMapper().mapFrom(source, exchange.getContext(message));
        Object content = null;
        if (source.getParameters().length > 0) {
            content = source.getParameters()[0];
        }
        message.setContent(content);

        if (source.getParameters().length > 1) {
            RestEasyLogger.ROOT_LOGGER.defaultRESTEasyMessageComposerDoesnTHandleMultipleInputParameters();
        }
        return message;
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    public RESTEasyBindingData decompose(Exchange exchange, RESTEasyBindingData target) throws Exception {
        Message sourceMessage = exchange.getMessage();
        Object content = sourceMessage.getContent();
        if (exchange.getContract().getProviderOperation() != null) {
            target.setOperationName(exchange.getContract().getProviderOperation().getName());
        } else if (exchange.getContract().getConsumerOperation() != null) {
            target.setOperationName(exchange.getContract().getConsumerOperation().getName());
        }
       
        if (exchange.getState().equals(ExchangeState.FAULT)) {
            if (content instanceof WebApplicationException) {
                throw (WebApplicationException)content;
            } else if (content instanceof HandlerException) {
                Throwable throwable = ((HandlerException)content).getCause();
                if (throwable != null) {
                    if (throwable instanceof WebApplicationException) {
                        throw (WebApplicationException)throwable;
                    } else {
                        throw new WebApplicationException(throwable);
                    }
                } else {
                    throw new WebApplicationException((HandlerException)content);
                }
            } else if (content instanceof Throwable) {
                throw new WebApplicationException((Throwable)content);
            } else {
                throw new WebApplicationException(new Exception(sourceMessage.getContent(String.class)));
            }
        }
        if (content != null) {
            target.setParameters(new Object[]{content});
        }
View Full Code Here

        Assert.assertEquals(4, mockService.getMessages().size());
    }

    @Test
    public void restGatewayReferenceTest() throws Exception {
        Message responseMsg = _consumerService.operation("addGreeter").sendInOut("magesh");
        Assert.assertEquals("magesh", responseMsg.getContent(String.class));
        responseMsg = _consumerService.operation("greeterInfo").sendInOut("keith");
        Assert.assertEquals("keith", responseMsg.getContent(String.class));

        // This cannot be tested by design of SwitchYard, as it does not allow multiple parameters
        /*responseMsg = _consumerService.operation("sayHello").sendInOut("keith");
        Assert.assertEquals("keith", responseMsg.getContent(String.class));*/
    }
View Full Code Here

                        Thread.sleep(10000);
                    } catch (InterruptedException ie) {
                        //Ignore
            }}});
        try {
            Message responseMsg = _consumerService2.operation("addGreeter").sendInOut("magesh");
        } catch (Exception e) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            e.printStackTrace(new PrintStream(baos));
            Assert.assertTrue(baos.toString().contains("SocketTimeoutException: Read timed out"));
        }
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.