/** * Add an exchange to this request. All exchanges that are added to the request have to be finished * @param exchange */ public void addExchange(MessageExchange exchange) { exchanges.add(exchange); exchange.setProperty(BeanEndpoint.CORRELATION_ID, correlationId); }
protected void populateExchangeProperties(MessageExchange exchange, Map properties) { if (properties != null) { for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); exchange.setProperty((String) entry.getKey(), entry.getValue()); } } }
protected void populateExchangeProperties(MessageExchange exchange, Map properties) { if (properties != null) { for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); exchange.setProperty((String) entry.getKey(), entry.getValue()); } } }
/** * Propagates the correlation id from an exchange to a newly created exchange * @param source Exchange which already exists * @param dest Newly created exchange which should get the correlation id */ public void propagateCorrelationId(MessageExchange source, MessageExchange dest) { if (source == null || dest == null) { return; } String correlationId = (String) source.getProperty(JbiConstants.CORRELATION_ID); if (correlationId != null) { dest.setProperty(JbiConstants.CORRELATION_ID, correlationId); } else { dest.setProperty(JbiConstants.CORRELATION_ID, source.getExchangeId()); } }
/** * Propagates the correlation id from an exchange to a newly created exchange * @param source Exchange which already exists * @param dest Newly created exchange which should get the correlation id */ public void propagateCorrelationId(MessageExchange source, MessageExchange dest) { if (source == null || dest == null) { return; } String correlationId = (String) source.getProperty(JbiConstants.CORRELATION_ID); if (correlationId != null) { dest.setProperty(JbiConstants.CORRELATION_ID, correlationId); } else { dest.setProperty(JbiConstants.CORRELATION_ID, source.getExchangeId()); } }
/** * * @param in * echange to copy from * @param out * excahnge to copy to */ private void copyProperties(MessageExchange in, MessageExchange out) { Set propertyNames = in.getPropertyNames(); for (Iterator iter = propertyNames.iterator(); iter.hasNext();) { String name = (String) iter.next(); out.setProperty(name, in.getProperty(name)); } }
/** * Set the flow instance identifier and the flow step identifier from the given flow attributes into the given * exchange as properties * * @param messageExchange * The message exchange in which flow information must be set * @param attributes * The flow attribute containing the flow information to set * @param prefix * A prefix used in the property name */ public static void setFlowAttributes(final MessageExchange messageExchange, final FlowAttributes attributes, final String prefix) { if (attributes != null) { final String mexPrefix = prefix + messageExchange.getExchangeId() + "."; messageExchange.setProperty(mexPrefix + FLOW_INSTANCE_ID, attributes.getFlowInstanceId()); messageExchange.setProperty(mexPrefix + FLOW_STEP_ID, attributes.getFlowStepId()); } }
private static void updateProperties(final @Nullable MessageExchange from, final @Nullable MessageExchange to) { assert from != null; assert to != null; // we remove all the properties of the exchange to update @SuppressWarnings("unchecked") final Set<String> oldProps = new HashSet<>(to.getPropertyNames()); for (final String oldProp : oldProps) { assert oldProp != null; if (ignoreProperty(oldProp)) { // let's skip this one, we don't want to remove it! continue; } to.setProperty(oldProp, null); } // and put all of those from the source exchange setProperties(from, to); }
private static void setProperties(final @Nullable MessageExchange from, final @Nullable MessageExchange to) { assert from != null; assert to != null; // we put all the properties from the source exchange @SuppressWarnings("unchecked") final Set<String> props = from.getPropertyNames(); for (final String prop : props) { assert prop != null; if (ignoreProperty(prop)) { // let's skip this one, we don't want to propagate it! continue; } to.setProperty(prop, from.getProperty(prop)); } }
private void copyPropertiesFromCamelToJbi(Exchange exchange, MessageExchange messageExchange) { for (String key : exchange.getProperties().keySet()) { if (messageExchange.getProperty(key) == null) { Object value = exchange.getProperty(key); if (!MESSAGE_EXCHANGE.equals(key) && value != null && !strategies.applyFilterToCamelHeaders(key, value, exchange)) { messageExchange.setProperty(key, value); } } } }
/** * routes a MessageExchange * * @param messageExchange * @throws MessagingException */ public void send(MessageExchange messageExchange) throws MessagingException { // If the delivery channel has been closed checkNotClosed(); // Log call LOGGER.debug("Send {} in {}", messageExchange.getExchangeId(), this); // // JBI 5.5.2.1.3: remove sync property messageExchange.setProperty(JbiConstants.SEND_SYNC, null); // Call doSend MessageExchangeImpl me = (MessageExchangeImpl) messageExchange; doSend(me, false); }
public void populateMessage(Message message, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception { org.apache.servicemix.soap.api.Message req = (org.apache.servicemix.soap.api.Message) exchange.getProperty(Message.class.getName()); exchange.setProperty(org.apache.servicemix.soap.api.Message.class.getName(), null); org.apache.servicemix.soap.api.Message msg = binding.createMessage(req); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); msg.setContent(MessageExchange.class, exchange); msg.setContent(NormalizedMessage.class, normalizedMessage); String str = ((TextMessage) message).getText(); msg.setContent(InputStream.class, new ByteArrayInputStream(str.getBytes())); InterceptorChain phaseIn = getChain(Phase.ClientIn); phaseIn.doIntercept(msg); }
exchange.setProperty(JbiConstants.CORRELATION_ID, exchange.getExchangeId()); logger.debug("Created correlation id: {}", correlationIDValue); } else { exchange.setProperty(JbiConstants.CORRELATION_ID, correlationIDValue); logger.debug("Correlation id retrieved from ThreadLocal: {}", correlationIDValue); exchange.setProperty(JbiConstants.SENDER_ENDPOINT, endpoint.getKey()); if ((exchange.getRole() == Role.CONSUMER && exchange.getStatus() == ExchangeStatus.ACTIVE) || exchange.getRole() == Role.PROVIDER) { if (transactionManager != null) { exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, transactionManager.suspend());
public Message createMessage(MessageExchange exchange, NormalizedMessage in, Session session) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Source source = in.getContent(); if (!(source instanceof DOMSource)) { source = sourceTransformer.toDOMSource(source); in.setContent(source); } org.apache.servicemix.soap.api.Message msg = binding.createMessage(); exchange.setProperty(org.apache.servicemix.soap.api.Message.class.getName(), null); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); msg.setContent(MessageExchange.class, exchange); msg.setContent(NormalizedMessage.class, in); msg.setContent(OutputStream.class, baos); exchange.setProperty(Message.class.getName(), msg); InterceptorChain phaseOut = getChain(Phase.ClientOut); phaseOut.doIntercept(msg); TextMessage jmsMessage = session.createTextMessage(); jmsMessage.setText(baos.toString()); return jmsMessage; }
public void onMessage(final Message message) { try { logger.debug("Received jms message {}", message); Context context = createContext(); MessageExchange exchange = toNMS(message, context); if (!(exchange instanceof InOnly)) { throw new UnsupportedOperationException("JCA consumer endpoints can only use InOnly MEP"); } exchange.setProperty(MessageExchange.JTA_TRANSACTION_PROPERTY_NAME, transactionManager.getTransaction()); pendingMessages.put(exchange.getExchangeId(), context); if (endpoint.isSynchronous()) { channel.sendSync(exchange); process(exchange); } else { endpoint.getServiceUnit().getComponent().prepareExchange(exchange, endpoint); channel.send(exchange); } } catch (Throwable e) { logger.error("Error while handling jms message", e); } }
public void send(MessageExchange exchange) throws MessagingException { assert exchange != null; createTarget(context.getNmr(), exchange); exchange.setProperty(SEND_SYNC, null); ((MessageExchangeImpl) exchange).afterSend(); InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange(); getChannelToUse(ie).send(ie); }
public boolean sendSync(MessageExchange exchange) throws MessagingException { assert exchange != null; createTarget(context.getNmr(), exchange); exchange.setProperty(SEND_SYNC, Boolean.TRUE); ((MessageExchangeImpl) exchange).afterSend(); InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange(); return getChannelToUse(ie).sendSync(ie); }
public boolean sendSync(MessageExchange exchange, long timeout) throws MessagingException { assert exchange != null; createTarget(context.getNmr(), exchange); exchange.setProperty(SEND_SYNC, Boolean.TRUE); ((MessageExchangeImpl) exchange).afterSend(); InternalExchange ie = (InternalExchange) ((MessageExchangeImpl) exchange).getInternalExchange(); return getChannelToUse(ie).sendSync(ie, timeout); }
protected void processProviderAsync(MessageExchange exchange) throws Exception { if (exchange.getStatus() == ExchangeStatus.DONE) { String correlationId = (String) exchange.getProperty(correlation); if (correlationId == null) { throw new IllegalStateException(correlation + " property not found"); } // Ack last target hit MessageExchange me = (MessageExchange) store.load(correlationId); done(me); } else if (exchange.getStatus() == ExchangeStatus.ERROR) { String correlationId = (String) exchange.getProperty(correlation); if (correlationId == null) { throw new IllegalStateException(correlation + " property not found"); } // Ack last target hit MessageExchange me = (MessageExchange) store.load(correlationId); done(me); } else if (!(exchange instanceof InOut)) { throw new IllegalStateException("Use an InOut MEP"); } else { MessageExchange me = getExchangeFactory().createInOutExchange(); me.setProperty(correlation, exchange.getExchangeId()); me.setProperty(index, new Integer(0)); targets[0].configureTarget(me, getContext()); store.store(exchange.getExchangeId(), exchange); MessageUtil.transferInToIn(exchange, me); send(me); } }
public void handleResponse(MessageExchange exchange, SmxHttpExchange httpExchange) throws Exception { Message req = (Message) exchange.getProperty(Message.class.getName()); exchange.setProperty(Message.class.getName(), null); Message msg = binding.createMessage(req); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); msg.setContent(MessageExchange.class, exchange); msg.setContent(InputStream.class, getResponseEncodingStream( httpExchange.getResponseFields().getStringField(HttpHeaders.CONTENT_ENCODING), httpExchange.getResponseStream())); msg.put(StaxInInterceptor.ENCODING, httpExchange.getResponseEncoding()); InterceptorChain phaseOut = getChain(Phase.ClientIn); phaseOut.doIntercept(msg); // TODO: Retrieve headers ? }