/** {@inheritDoc} */ public void after(String target, Exchange exchange) throws HandlerException { System.out.println("-------------- " + exchange.getProvider().getName()); if (exchange.getPhase() == ExchangePhase.OUT && !exchange.getProvider().getName().toString().endsWith("OrderProcessREST")) { handleExchange(exchange); } }
@Test public void testPhaseIsInAfterInputMessage() { ServiceReference service = _domain.createInOnlyService(new QName("InPhase")); Exchange exchange = service.createExchange(); exchange.send(exchange.createMessage()); Assert.assertEquals(ExchangePhase.IN, exchange.getPhase()); }
@Test public void testPhaseIsOutAfterFaultMessage() { MockHandler replyHandler = new MockHandler(); ServiceReference service = _domain.createInOutService(new QName("FaultPhase"), new MockHandler().forwardInToFault()); Exchange exchange = service.createExchange(replyHandler); exchange.send(exchange.createMessage()); replyHandler.waitForFaultMessage(); Assert.assertEquals(ExchangePhase.OUT, exchange.getPhase()); }
/** {@inheritDoc} */ public void before(String target, Exchange exchange) throws HandlerException { if (exchange.getPhase() == ExchangePhase.IN && !exchange.getProvider().getName().toString().endsWith("OrderProcessREST")) { handleExchange(exchange); } }
/** {@inheritDoc} */ @Override public void handleMessage(Exchange exchange) throws HandlerException { if (!ExchangePhase.IN.equals(exchange.getPhase())) { return; } Context context = exchange.getContext(); ServiceOperation serviceOperation = exchange.getContract().getServiceOperation(); ProcessActionModel processActionModel = _actionModels.get(serviceOperation.getName()); ProcessActionType processActionType = getProcessActionType(context, processActionModel); Message messageIn = exchange.getMessage(); Long processInstanceId = null; ProcessInstance processInstance = null; switch (processActionType) { case START_PROCESS: if (_processId != null) { Object messageContentIn = messageIn.getContent(); if (messageContentIn != null) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put(_messageContentInName, messageContentIn); processInstance = _ksession.startProcess(_processId, parameters); } else { processInstance = _ksession.startProcess(_processId); } processInstanceId = Long.valueOf(processInstance.getId()); } else { throwNullParameterException(processActionType, PROCESS_ID_VAR); } break; case SIGNAL_EVENT: String processEventType = getProcessEventType(context, processActionModel); Object processEvent = getProcessEvent(context, messageIn); processInstanceId = getProcessInstanceId(context); if (processInstanceId != null) { _ksession.signalEvent(processEventType, processEvent, processInstanceId.longValue()); } else { throwNullParameterException(processActionType, PROCESS_INSTANCE_ID_VAR); } break; case ABORT_PROCESS_INSTANCE: processInstanceId = getProcessInstanceId(context); if (processInstanceId != null) { _ksession.abortProcessInstance(processInstanceId.longValue()); } else { throwNullParameterException(processActionType, PROCESS_INSTANCE_ID_VAR); } break; } if (processInstanceId != null) { context.setProperty(PROCESS_INSTANCE_ID_VAR, processInstanceId, Scope.EXCHANGE); ExchangePattern exchangePattern = serviceOperation.getExchangePattern(); if (ExchangePattern.IN_OUT.equals(exchangePattern)) { if (processInstance == null) { processInstance = _ksession.getProcessInstance(processInstanceId.longValue()); } Message messageOut = exchange.createMessage(); Object messageContentOut = null; if (processInstance != null) { messageContentOut = ((WorkflowProcessInstance) processInstance).getVariable(_messageContentOutName); } if (messageContentOut != null) { messageOut.setContent(messageContentOut); } exchange.send(messageOut); } } }
@Test public void testPhaseIsNullOnNewExchange() { Exchange exchange = new ExchangeImpl(_domain, _dispatch); Assert.assertNull(exchange.getPhase()); }