/** * Return the synchronized mode related to a message exchange. * * @param messageExchange * the message exchange to check * @param isResponse * true if it is property checking for a response message false * otherwise * @return true if message is in CONSUMER role and it is a response or if * message is in PROVIDER role and it isn't a response, false * otherwise */ public static boolean getSyncMode(MessageExchangeImpl messageExchange, boolean isResponse) { boolean syncMode = false; if ((MessageExchange.Role.CONSUMER.equals(messageExchange.getRole()) && isResponse) || (MessageExchange.Role.PROVIDER.equals(messageExchange.getRole()) && !isResponse)) { syncMode = (messageExchange.getProperty(TransporterUtil.PROPERTY_SENDSYNC_CONSUMER) != null && ((String) messageExchange .getProperty(TransporterUtil.PROPERTY_SENDSYNC_CONSUMER)).toLowerCase().equals( "true")); } else { syncMode = (messageExchange.getProperty(TransporterUtil.PROPERTY_SENDSYNC_PROVIDER) != null && ((String) messageExchange .getProperty(TransporterUtil.PROPERTY_SENDSYNC_PROVIDER)).toLowerCase().equals( "true")); } return syncMode; }
/** * Check that the Role allows the specified reference. This only works for * the JBI predefined MEPs. It check that reference is IN or OUT and the * Role is CONSUMER or PROVIDER. Other reference will cause an exception * * @param name * @throws MessagingException * the Role does not allow the reference */ protected void checkRoleMatching(String name) throws MessagingException { if (role == null) { throw new MessagingException("the Role is not defined."); } if (name == null) { throw new MessagingException("The reference name is not defined."); } if (MessageExchange.Role.CONSUMER.equals(role)) { if (IN_MSG.equalsIgnoreCase(name)) { return; } } else if (MessageExchange.Role.PROVIDER.equals(role) && OUT_MSG.equalsIgnoreCase(name)) { return; } throw new MessagingException("The Role does not allow this operation."); }
if (Role.CONSUMER.equals(role)) { if (IN_ONLY_PATTERN.equals(pattern)) { throw new MessagingException(
if (Role.CONSUMER.equals(state.role)) { state.component = exchange.getConsumerEndpoint().getComponentName(); state.container = exchange.getConsumerEndpoint().getContainerName();
state.role = exchange.getRole(); if (Role.CONSUMER.equals(state.role)) { state.component = exchange.getConsumerEndpoint().getComponentName(); state.container = exchange.getConsumerEndpoint().getContainerName();
/** * Send the message synchroniously into the NMR. * * @param source * the source * @param exchange * the exchange * @param timeOut * timeout of the message (in ms). 0 for no timeout * * @return the reponse exchange if received, or <code>null</code> if the * timeout is reached * * @throws RoutingException * impossible to realize a send synchrone */ public MessageExchangeImpl sendSync(final ComponentContextImpl source, final MessageExchangeImpl exchange, final long timeOut) throws RoutingException { this.log.call(); MessageExchangeImpl responseExchange = null; if (MessageExchange.Role.CONSUMER.equals(exchange.getRole())) { responseExchange = this.sendToProvider(source, exchange, timeOut, true); } else { responseExchange = this.sendToConsumer(source, exchange, timeOut, true); } return responseExchange; }
/** * (non-Javadoc) * * @see javax.jbi.messaging.MessageExchange#setFault(javax.jbi.messaging.Fault) */ public void setFault(Fault fault) throws MessagingException { checkNotTerminated(); if (role == null) { throw new MessagingException("The Role is not defined."); } // check that a fault has not already been sent if (this.fault != null) { throw new MessagingException("A fault has already been set."); } // check that the status has not be positionned with DONEor EXCEPTION if (ExchangeStatus.DONE.equals(status) || ExchangeStatus.ERROR.equals(status)) { throw new MessagingException( "The MessageExchange state and the current Role do not allow this operation."); } // only the provider can send a fault, except in the case of a // InOptionnalOut, // where the consumer can set a fault after the provider sent a response if (MessageExchange.Role.CONSUMER.equals(role) && !messages.containsKey(OUT_MSG)) { throw new MessagingException( "The MessageExchange state and the current Role do not allow this operation."); } this.fault = fault; }
/** * @see MessageExchangeImpl#writeObject(ObjectOutputStream). * @param s * the object output stream * @throws IOException * impossible to write object delegate * */ protected void writeObjectDelegate(final ObjectOutputStream s) throws IOException { // Role serialization if (MessageExchange.Role.CONSUMER.equals(this.role)) { s.writeShort(MessageExchange.SERIALIZE_ROLE_CONSUMER); } else { s.writeShort(MessageExchange.SERIALIZE_ROLE_PROVIDER); } // Status serialization if (ExchangeStatus.ACTIVE.equals(this.status)) { s.writeShort(MessageExchange.SERIALIZE_STATUS_ACTIVE); } else if (ExchangeStatus.DONE.equals(this.status)) { s.writeShort(MessageExchange.SERIALIZE_STATUS_DONE); } else { s.writeShort(MessageExchange.SERIALIZE_STATUS_ERROR); } s.defaultWriteObject(); }
/** * Set the properties to the message exchange to specify that a synchronious * response is expected * * @param exchange * * @throws MessagingException * The <code>sync_send()</code> is forbidden for * acknowledgment send */ public static void setSendSyncProperties(MessageExchangeImpl exchange) throws MessagingException { if (!exchange.getStatus().equals(ExchangeStatus.ACTIVE)) { throw new MessagingException( "Synchronious send is forbidden when sending an acknowledgement"); } // specify the role of the requester of the sync exchange, used // internally if (MessageExchange.Role.PROVIDER.equals(exchange.getRole())) exchange.setProperty(PROPERTY_SENDSYNC_CONSUMER, "true"); else exchange.setProperty(PROPERTY_SENDSYNC_PROVIDER, "true"); // set the property as defined in the JBI specifications exchange.setProperty(DeliveryChannelImpl.PROPERTY_SENDSYNC, "true"); }
/** * Send back to the issuer of the response an error ack message * * @param exchange * the message to send back */ private void sendBackErrorExchange(MessageExchangeImpl exchange) { log.start(); // set the timeout arbitrary to 10 seconds try { AbstractEndpoint endpoint = null; if (exchange.getRole().equals(MessageExchange.Role.PROVIDER)) { exchange.setRole(MessageExchange.Role.CONSUMER); endpoint = exchange.getConsumerEndpoint(); } else { exchange.setRole(MessageExchange.Role.PROVIDER); endpoint = (AbstractEndpoint) exchange.getEndpoint(); } send(exchange, endpoint.getComponentName(), endpoint.getContainerName(), 10000L); } catch (TransportException e) { // do nothing, the message is lost. } log.end(); }
/** * Sends the specified message. Depending on the Role of the sender, send * the message to the producer (request) or to the consumer (response) * * @param source * the source * @param exchange * the exchange * @param timeOut * timeout of the message (in ms). 0 for no timeout * @throws RoutingException * impossible to send the message */ public void send(final ComponentContextImpl source, final MessageExchangeImpl exchange, final long timeOut) throws RoutingException { this.log.call(); if (MessageExchange.Role.CONSUMER.equals(exchange.getRole())) { this.sendToProvider(source, exchange, timeOut, false); } else { this.sendToConsumer(source, exchange, timeOut, false); } }
/** * Get the matching component name * * @param jbiMsg * @param componentName * @return * @throws TransportException */ private String getComponentName(MessageExchangeImpl jbiMsg) { log.start(); String componentName = null; if (jbiMsg.getRole().equals(MessageExchange.Role.CONSUMER)) { componentName = (jbiMsg.getConsumerEndpoint()).getComponentName(); log.debug("consumer endpoint" + componentName); } else if (jbiMsg.getRole().equals(MessageExchange.Role.PROVIDER)) { componentName = ((AbstractEndpoint) jbiMsg.getEndpoint()).getComponentName(); log.debug("service endpoint " + componentName); } log.end(); return componentName; }
/** * @see MessageExchangeImpl#writeObject(ObjectOutputStream) */ protected void writeObjectDelegate(ObjectOutputStream s) throws IOException { // Role serialization if (MessageExchange.Role.CONSUMER.equals(role)) { s.writeShort(SERIALIZE_ROLE_CONSUMER); } else { s.writeShort(SERIALIZE_ROLE_PROVIDER); } // Status serialization if (ExchangeStatus.ACTIVE.equals(status)) { s.writeShort(SERIALIZE_STATUS_ACTIVE); } else if (ExchangeStatus.DONE.equals(status)) { s.writeShort(SERIALIZE_STATUS_DONE); } else { s.writeShort(SERIALIZE_STATUS_ERROR); } s.defaultWriteObject(); }
/** * Update the sync properties of the message exchange * * @param exchange */ public static void updateSyncProperties(MessageExchangeImpl exchange) { if (MessageExchange.Role.PROVIDER.equals(exchange.getRole())) { // remove the SENDSYNC property for eventually futher exchanges exchange.setProperty(DeliveryChannelImpl.PROPERTY_SENDSYNC, null); exchange.setProperty(PROPERTY_SENDSYNC_PROVIDER, null); } else { // remove the SENDSYNC property for eventually futher exchanges exchange.setProperty(DeliveryChannelImpl.PROPERTY_SENDSYNC, null); exchange.setProperty(PROPERTY_SENDSYNC_CONSUMER, null); } }
/** * Convert a Role to a string representation * * @param role * @return "consumer" or "provider */ protected static String roleToRaw(Role role) { return (Role.CONSUMER.equals(role)) ? "consumer" : "provider"; }
/** * Return if the component owns the message exchange. (Check that the role * of the observer is the same than the role of the message exchange) * * @throws IllegalStateException */ public boolean hasOwnership() { return messageExchange.getRole().equals(observerRole); }
/** * Convert a Role to a string representation * * @param role * @return "consumer" or "provider */ protected static String roleToRaw(Role role) { return (Role.CONSUMER.equals(role)) ? "consumer" : "provider"; }
/** * Convert a Role to a string representation * * @param role * @return "consumer" or "provider */ private String roleToRaw(Role role) { return (Role.CONSUMER.equals(role)) ? "consumer" : "provider"; }