Package org.switchyard

Examples of org.switchyard.Message


        serviceDomain.registerServiceReference(signalService.getName(), signalService.getInterface(), signalService.getProviderHandler());
        handler.start();
        Invoker processInvoker = new Invoker(serviceDomain, serviceName);
        Holder holderOne = new Holder();
        holderOne.setValue("HolderOne");
        Message processResponse = processInvoker.operation("process").sendInOut(holderOne);
        Long processInstanceId = (Long)processResponse.getContext().getPropertyValue(PROCESSS_INSTANCE_ID_PROPERTY);
        Invoker signalInvoker = new Invoker(serviceDomain, serviceName);
        Holder holderTwo = new Holder();
        holderTwo.setValue("HolderTwo");
        Message signalResponse = signalInvoker.operation("signal").property(PROCESSS_INSTANCE_ID_PROPERTY, processInstanceId).sendInOut(holderTwo);
        Holder holderResponse = signalResponse.getContent(Holder.class);
        handler.stop();
        Assert.assertEquals(holderOne.getValue(), testAssertionMap.get("ServiceOne"));
        Assert.assertEquals(holderTwo.getValue(), testAssertionMap.get("ServiceTwo"));
        Assert.assertEquals(holderTwo.getValue(), holderResponse.getValue());
    }
View Full Code Here


        invoker.start();
       
        final QName TEST_SERVICE = new QName("urn:test", "SCAInvokerTest");
        ServiceReference reference = _domain.createInOnlyService(TEST_SERVICE, _provider);
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.consumer(reference, new InOnlyOperation("Test"));
        ex.provider(_domain.getServices().get(0), new InOnlyOperation("Test"));
        invoker.handleMessage(ex);
       
        Assert.assertTrue(_provider.getMessages().size() == 1);
        Assert.assertEquals(msg.getContent(), _provider.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

        _domain.registerServiceReference(SERVICE_B, new InOnlyService());
        Service serviceA = _domain.registerService(SERVICE_A, new InOnlyService(), new MockHandler());
        _domain.registerService(SERVICE_B, new InOnlyService(), _provider);
       
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.consumer(referenceA, new InOnlyOperation(null));
        ex.provider(serviceA, new InOnlyOperation(null));
        invoker.handleMessage(ex);
       
        Assert.assertTrue(_provider.getMessages().size() == 1);
        Assert.assertEquals(msg.getContent(), _provider.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

        Service serviceA = domain1.registerService(SERVICE_A, new InOnlyService(), new MockHandler());
        domain2.registerServiceReference(SERVICE_B, new InOnlyService());
        domain2.registerService(SERVICE_B, new InOnlyService(), _provider);
       
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.consumer(referenceA, new InOnlyOperation(null));
        ex.provider(serviceA, new InOnlyOperation(null));
        invoker.handleMessage(ex);
       
        Assert.assertTrue(_provider.getMessages().size() == 1);
        Assert.assertEquals(msg.getContent(), _provider.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

        Service serviceA = _domain.registerService(SERVICE_A, new InOnlyService(), null);
        _domain.registerService(SERVICE_A, new InOnlyService(), _provider);
       
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.consumer(referenceA, new InOnlyOperation(null));
        ex.provider(serviceA, new InOnlyOperation(null));
       
        // Should throw a Handler exception
View Full Code Here

        _domain.registerServiceReference(SERVICE_B, new InOnlyService());
        Service serviceA = _domain.registerService(SERVICE_A, new InOnlyService(), new MockHandler());
        _domain.registerService(SERVICE_B, new InOnlyService(), _provider);
       
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.consumer(referenceA, new InOnlyOperation(null));
        ex.provider(serviceA, new InOnlyOperation(null));
        invoker.handleMessage(ex);
       
        Assert.assertTrue(_provider.getMessages().size() == 1);
        Assert.assertEquals(msg.getContent(), _provider.getMessages().poll().getMessage().getContent());
    }
View Full Code Here

        invoker.start();
       
        final QName TEST_SERVICE = new QName("urn:test", "SCAInvokerTest");
        ServiceReference reference = _domain.createInOnlyService(TEST_SERVICE, _provider);
        MockExchange ex = new MockExchange();
        Message msg = ex.createMessage().setContent("TEST");
        ex.setMessage(msg);
        ex.getMessage().getContext().setProperty("message-prop", "abc");
        ex.consumer(reference, new InOnlyOperation("Test"));
        ex.provider(_domain.getServices().get(0), new InOnlyOperation("Test"));
        invoker.handleMessage(ex);
View Full Code Here

     */
    @Override
    public void handleOperation(Exchange exchange, KnowledgeOperation operation) throws HandlerException {
        Integer sessionId = null;
        Long processInstanceId = null;
        Message inputMessage = exchange.getMessage();
        ExchangePattern exchangePattern = exchange.getContract().getProviderOperation().getExchangePattern();
        Map<String, Object> expressionVariables = new HashMap<String, Object>();
        AS7TransactionHelper utx = new AS7TransactionHelper(_persistent);
        BPMOperationType operationType = (BPMOperationType)operation.getType();
        switch (operationType) {
            case START_PROCESS: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    setGlobals(inputMessage, operation, session);
                    Map<String, Object> inputMap = getInputMap(inputMessage, operation, session);
                    ProcessInstance processInstance;
                    CorrelationKey correlationKey = getCorrelationKey(exchange, inputMessage);
                    if (correlationKey != null) {
                        processInstance = ((CorrelationAwareProcessRuntime)session.getStateful()).startProcess(_processId, correlationKey, inputMap);
                    } else {
                        processInstance = session.getStateful().startProcess(_processId, inputMap);
                    }
                    processInstanceId = Long.valueOf(processInstance.getId());
                    if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                        expressionVariables.putAll(getGlobalVariables(session));
                        expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                    }
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            case SIGNAL_EVENT:
            case SIGNAL_EVENT_ALL: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    setGlobals(inputMessage, operation, session);
                    Object eventObject = getInput(inputMessage, operation, session);
                    String eventId = operation.getEventId();
                    if (BPMOperationType.SIGNAL_EVENT.equals(operationType)) {
                        processInstanceId = getProcessInstanceId(exchange, inputMessage, session);
                        if (processInstanceId == null) {
                            throw BPMMessages.MESSAGES.cannotSignalEventUnknownProcessInstanceIdOrUnknownunmatchedCorrelationKey();
                        }
                        if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                            ProcessInstance processInstance = session.getStateful().getProcessInstance(processInstanceId);
                            processInstance.signalEvent(eventId, eventObject);
                            expressionVariables.putAll(getGlobalVariables(session));
                            expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                        } else {
                            session.getStateful().signalEvent(eventId, eventObject, processInstanceId);
                        }
                    } else if (BPMOperationType.SIGNAL_EVENT_ALL.equals(operationType)) {
                        session.getStateful().signalEvent(eventId, eventObject);
                        if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                            expressionVariables.putAll(getGlobalVariables(session));
                        }
                    }
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            case ABORT_PROCESS_INSTANCE: {
                try {
                    utx.begin();
                    KnowledgeSession session = getBPMSession(exchange, inputMessage);
                    sessionId = session.getId();
                    processInstanceId = getProcessInstanceId(exchange, inputMessage, session);
                    if (processInstanceId == null) {
                        throw BPMMessages.MESSAGES.cannotAbortProcessInstance();
                    }
                    if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
                        expressionVariables.putAll(getGlobalVariables(session));
                        ProcessInstance processInstance = session.getStateful().getProcessInstance(processInstanceId);
                        expressionVariables.putAll(getProcessInstanceVariables(processInstance));
                    }
                    session.getStateful().abortProcessInstance(processInstanceId);
                    utx.commit();
                } catch (RuntimeException re) {
                    utx.rollback();
                    throw re;
                }
                break;
            }
            default: {
                throw BPMMessages.MESSAGES.unsupportedOperationType(operationType);
            }
        }
        if (ExchangePattern.IN_OUT.equals(exchangePattern)) {
            Message outputMessage = exchange.createMessage();
            Context outputContext = exchange.getContext(outputMessage);
            if (sessionId != null && sessionId.intValue() > 0) {
                outputContext.setProperty(BPMConstants.SESSION_ID_PROPERTY, sessionId);
            }
            if (processInstanceId != null && processInstanceId.longValue() > 0) {
                outputContext.setProperty(BPMConstants.PROCESSS_INSTANCE_ID_PROPERTY, processInstanceId);
            }
            setFaults(outputMessage, operation, expressionVariables);
            if (outputMessage.getContent() != null) {
                exchange.sendFault(outputMessage);
            } else {
                setOutputs(outputMessage, operation, expressionVariables);
                exchange.send(outputMessage);
            }
View Full Code Here

                    responseQueue.offer(exchange);
                }
            });

            Exchange exchange = _serviceReference.createExchange(exchangeContract, responseExchangeHandler.get());
            Message message = exchange.createMessage().setContent(payload);

            exchange.send(message);
            Exchange exchangeOut = null;
            try {
                exchangeOut = responseQueue.take();
            } catch (InterruptedException e) {
                throw new SwitchYardException("Operation '" + operationName + "' on Service '" + _serviceReference.getName() + "' interrupted.", e);
            }

            if (exchangeOut.getState() == ExchangeState.OK) {
                return exchangeOut.getMessage().getContent();
            } else {
                Object failureObj = exchangeOut.getMessage().getContent();
                if (failureObj instanceof Throwable) {
                    if (failureObj instanceof InvocationTargetException) {
                        throw ((Throwable)failureObj).getCause();
                    } else {
                        throw (Throwable) failureObj;
                    }
                } else {
                    throw new SwitchYardException("Service invocation failure.  Service '" + _serviceReference.getName() + "', operation '" + operationName + "'.  Non Throwable failure message payload: " + failureObj);
                }
            }
        } else {
            Exchange exchange = _serviceReference.createExchange(exchangeContract);
            Message message = exchange.createMessage().setContent(payload);

            exchange.send(message);
        }

        return null;
View Full Code Here

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

            Message message = _messageComposer.compose(input, exchange);
            _securityContextManager.addCredentials(exchange, input.extractCredentials());
            if (exchange.getContract().getConsumerOperation().getExchangePattern() == ExchangePattern.IN_ONLY) {
                exchange.send(message);
                if (exchange.getState().equals(ExchangeState.FAULT)) {
                    response = (HttpResponseBindingData) _messageComposer.decompose(exchange, new HttpResponseBindingData());
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.