NormalizedMessage in, QName service) throws MessagingException { NormalizedMessage msg = exchange.createMessage(); getMessageTransformer().transform(exchange, in, msg); exchange.setMessage(msg, "in"); boolean result = this.getDeliveryChannel().sendSync(exchange); if (result) { if (exchange.getStatus() == ExchangeStatus.ERROR) { exchange.setStatus(ExchangeStatus.DONE); getDeliveryChannel().send(exchange); if (exchange.getError() != null) { throw new MessagingException("Received error", exchange.getError()); } else if (exchange.getFault() != null) { throw new FaultException("Received fault", exchange, exchange.getFault()); } else { throw new MessagingException("Received unknown error"); NormalizedMessage out = exchange.getOutMessage(); exchange.setStatus(ExchangeStatus.DONE); getDeliveryChannel().send(exchange); return out;
protected void inOutDone(InOut inout) { _mexTimeouts.remove(inout.getExchangeId()); }
@Override public NormalizedMessage invoke(InOut mex) throws MessagingException { try { DynamicService<T> service = new DynamicService<T>(_service); OMElement payload = OMUtils.toOM(mex.getInMessage().getContent()); OMElement response = service.invoke(mex.getOperation().getLocalPart(), payload); NormalizedMessage nresponse = null; if (response != null) { nresponse = mex.createMessage(); nresponse.setContent(new DOMSource(OMUtils.toDOM(response))); } return nresponse; } catch (Exception e) { throw new RuntimeException(e); } }
public InOut createInOutExchange() throws MessagingException { InOut exchange = getExchangeFactory().createInOutExchange(); NormalizedMessage in = exchange.createMessage(); exchange.setInMessage(in); return exchange; }
public Object request(org.apache.servicemix.jbi.api.EndpointResolver resolver, Map exchangeProperties, Map inMessageProperties, Object content) throws JBIException { InOut exchange = createInOutExchange(resolver); populateMessage(exchange, exchangeProperties, inMessageProperties, content); boolean answer = sendSync(exchange); if (!answer) { throw new JBIException("Exchange aborted"); } Exception error = exchange.getError(); if (error != null) { throw new JBIException(error); } if (exchange.getFault() != null) { done(exchange); throw FaultException.newInstance(exchange); } NormalizedMessage outMessage = exchange.getOutMessage(); if (outMessage == null) { throw new NoOutMessageAvailableException(exchange); } Object result = getMarshaler().unmarshal(exchange, outMessage); done(exchange); return result; }
done(current); if (me.getStatus() == ExchangeStatus.DONE) { throw new IllegalStateException("Exchange status is " + ExchangeStatus.DONE); } else if (me.getStatus() == ExchangeStatus.ERROR) { fail(exchange, me.getError()); return; } else if (me.getFault() != null) { Fault fault = MessageUtil.copyFault(me); MessageUtil.transferToFault(fault, exchange); sendSync(exchange); return; } else if (me.getOutMessage() == null) { throw new IllegalStateException("Exchange status is " + ExchangeStatus.ACTIVE + " but has no Out nor Fault message");
if (!isOneWay) { channel.sendSync(xchng); NormalizedMessage outMsg = ((InOut)xchng).getOutMessage(); Source content = null; Set normalizedMessageProps = null; normalizedMessageProps = outMsg.getPropertyNames(); } else { if (((InOut)xchng).getFault() == null) { throw xchng.getError(); content = ((InOut)xchng).getFault().getContent(); normalizedMessageProps = ((InOut)xchng).getFault().getPropertyNames();
public void onMessageExchange(MessageExchange exchange) throws MessagingException { // Skip done exchanges if (exchange.getStatus() == ExchangeStatus.DONE) { return; // Handle error exchanges } else if (exchange.getStatus() == ExchangeStatus.ERROR) { return; } // lets create an endpoint DeliveryChannel deliveryChannel = getDeliveryChannel(); MessageExchangeFactory rpcFactory = deliveryChannel.createExchangeFactory(requestResponseEndpoint); InOut rpc = rpcFactory.createInOutExchange(); rpc.setInMessage(exchange.getMessage("in")); boolean answer = deliveryChannel.sendSync(rpc); MessageExchangeFactory outputFactory = deliveryChannel.createExchangeFactory(outputEndpoint); InOnly inOnly = outputFactory.createInOnlyExchange(); if (answer) { inOnly.setInMessage(rpc.getOutMessage()); deliveryChannel.send(inOnly); done(exchange); } else if (!(exchange instanceof InOnly)) { inOnly.setError(rpc.getError()); Fault fault = rpc.getFault(); fail(exchange, fault); } else { // terminate the exchange done(exchange); } done(rpc); }
/** * sends the given DOMSource as message to the given service (inOut) * * @param service * the service name to send the message to * @param source * the source to put in the in message content * @return the DOMSource of the out message or null * @throws MessagingException * on any messaging exception */ public Source sendRequest(QName service, Source source) throws MessagingException { InOut inOut = getChannel().createExchangeFactoryForService(service).createInOutExchange(); NormalizedMessage msg = inOut.createMessage(); msg.setContent(source); inOut.setInMessage(msg); if (getChannel().sendSync(inOut)) { try { Source result = sourceTransformer.toDOMSource(inOut.getOutMessage().getContent()); done(inOut); return result; } catch (Exception ex) { ex.printStackTrace(); return null; } } else { return null; } }
SoapFault soapFault = soap.getFault(); if (soapFault != null) { Fault fault = exchange.createFault(); fault.setContent(soapFault.getDetails()); exchange.setFault(fault); } else { NormalizedMessage msg = exchange.createMessage(); soapHelper.getJBIMarshaler().toNMS(msg, soap); ((InOut) exchange).setOutMessage(msg); exchange.setError(e);
public static boolean hasOutMessage(MessageExchange mex) { if (mex instanceof InOut) { return ((InOut) mex).getOutMessage() != null; } return false; }
private void outResponse(MyRoleMessageExchange mex, javax.jbi.messaging.MessageExchange jbiMex) throws MessagingException { InOut inout = (InOut) jbiMex; try { NormalizedMessage nmsg = inout.createMessage(); String mapperName = mex.getProperty(Mapper.class.getName()); Mapper mapper = _ode.getMapper(mapperName); if (mapper == null) { String errmsg = "Message-mapper " + mapperName + " used in ODE MEX " + mex.getMessageExchangeId() + " is no longer available."; __log.error(errmsg); throw new MessageTranslationException(errmsg); } mapper.toNMS(nmsg, mex.getResponse(), mex.getOperation().getOutput().getMessage(), null); inout.setOutMessage(nmsg); } catch (MessageTranslationException e) { __log.error("Error translating ODE message " + mex.getResponse() + " to NMS format!", e); setError(jbiMex, e); } }
if (enricherTargetME.getStatus() == ExchangeStatus.ERROR) { fail(exchange, enricherTargetME.getError()); return; Document document = combineToDOMDocument(exchange.getMessage("in"), enricherTargetME.getMessage("out")); copyPropertiesAndAttachments(enricherTargetME.getMessage("out"), outExchange.getMessage("in"));
public static boolean hasInMessage(MessageExchange mex) { if (mex instanceof InOnly) { return ((InOnly) mex).getInMessage() != null; } else if (mex instanceof InOut) { return ((InOut) mex).getInMessage() != null; } return false; }
NormalizedMessage out = exchange.createMessage(); soapHelper.getJBIMarshaler().toNMS(out, soap); ((InOut) exchange).setOutMessage(out);
MessageExchange me = getExchangeFactory().createExchange(exchange.getPattern()); (faultsTarget != null ? faultsTarget : target).configureTarget(me, getContext()); MessageUtil.transferToIn(tme.getFault(), me); copyPropertiesAndAttachments(exchange.getMessage("in"), me.getMessage("in")); sendSync(me); String fault = new SourceTransformer().contentToString(tme.getFault()); done(tme); fail(exchange, new FaultException(fault, null, null));
public Boolean call() throws Exception { pmex.replyWithFailure(FailureType.OTHER, "Error: " + jbiMex.getError(), null); return null; } });
public Object request(EndpointResolver resolver, Map exchangeProperties, Map inMessageProperties, Object content) throws JBIException { InOut exchange = createInOutExchange(resolver); populateMessage(exchange, exchangeProperties, inMessageProperties, content); boolean answer = sendSync(exchange); if (!answer) { throw new JBIException("Exchange aborted"); } Exception error = exchange.getError(); if (error != null) { throw new JBIException(error); } if (exchange.getFault() != null) { done(exchange); throw FaultException.newInstance(exchange); } NormalizedMessage outMessage = exchange.getOutMessage(); if (outMessage == null) { throw new NoOutMessageAvailableException(exchange); } Object result = getMarshaler().unmarshal(exchange, outMessage); done(exchange); return result; }
sendSync(tme); if (tme.getStatus() == ExchangeStatus.DONE) { throw new IllegalStateException("Received a DONE status from the transformer"); } else if (tme.getStatus() == ExchangeStatus.ERROR) { fail(exchange, tme.getError()); } else if (tme.getFault() != null) { processFault(exchange, tme); } else if (tme.getOutMessage() == null) { throw new IllegalStateException("Exchange status is " + ExchangeStatus.ACTIVE + " but has no correlation set");
if (!isOneWay) { channel.sendSync(xchng); NormalizedMessage outMsg = ((InOut)xchng).getOutMessage(); Source content = null; Set normalizedMessageProps = null; normalizedMessageProps = outMsg.getPropertyNames(); } else { if (((InOut)xchng).getFault() == null) { throw xchng.getError(); content = ((InOut)xchng).getFault().getContent(); normalizedMessageProps = ((InOut)xchng).getFault().getPropertyNames();