/** * Creates an InOnly exchange and propagates the correlation id from the given exchange * to the newly created exchange * @param srcExchange * @return InOnly * @throws MessagingException */ public InOnly createInOnlyExchange(MessageExchange srcExchange) throws MessagingException { MessageExchangeFactory factory = getExchangeFactory(); InOnly inOnly = factory.createInOnlyExchange(); propagateCorrelationId(srcExchange, inOnly); return inOnly; }
/** * Creates an InOnly exchange and propagates the correlation id from the given exchange * to the newly created exchange * @param srcExchange * @return InOnly * @throws MessagingException */ public InOnly createInOnlyExchange(MessageExchange srcExchange) throws MessagingException { MessageExchangeFactory factory = getExchangeFactory(); InOnly inOnly = factory.createInOnlyExchange(); propagateCorrelationId(srcExchange, inOnly); return inOnly; }
public InOnly createInOnlyExchange() throws MessagingException { InOnly exchange = getExchangeFactory().createInOnlyExchange(); NormalizedMessage in = exchange.createMessage(); exchange.setInMessage(in); return exchange; }
public InOnly createInOnlyExchange() throws MessagingException { InOnly exchange = getExchangeFactory().createInOnlyExchange(); NormalizedMessage in = exchange.createMessage(); exchange.setInMessage(in); return exchange; }
protected void processFile(File file) throws Exception { InputStream stream = new BufferedInputStream(new FileInputStream(file)); InOnly exchange = getExchangeFactory().createInOnlyExchange(); configureExchangeTarget(exchange); NormalizedMessage message = exchange.createMessage(); exchange.setInMessage(message); marshaler.readMessage(exchange, message, stream, file.getCanonicalPath()); // sending the file itself along as a message property and holding on to // the stream we opened exchange.getInMessage().setProperty(FileComponent.FILE_PROPERTY, file); this.openExchanges.put(exchange.getExchangeId(), stream); send(exchange); }
public void fireAndForget(Message message) throws ClientException { // create a internal message from the given one... // this is a send operation try { // assume that this is a inonly message... MessageExchange messageExchange = this.messageExchangeFactory .createInOnlyExchange(); this.send(message, new ExchangeImpl(messageExchange), message.getOperation(), false); } catch (MessagingException e) { throw new ClientException(e); } }
/** * Return a <code>MessageExchangeDecorator</code> for Consumer, as * <code>InOnly</code>. * * @see javax.jbi.messaging.MessageExchangeFactory#createInOnlyExchange() * @return * the message exchange * @throws MessagingException * impossible to create the message exchange */ public InOnly createInOnlyExchange() throws MessagingException { // Create the concrete message exchange MessageExchange meC = this.concreteMef.createInOnlyExchange(); // Convert into fake message exchange InOnly meF = (InOnly) Convert. convertConcreteMessageExchangeToFakeMessageExchange(meC, Convert.IN_ONLY_PATTERN); ((org.objectweb.petals.tools.rmi.common.serializable. MessageExchange) meF).setRole(meC.getRole()); // Store the messages this.messages.put(meF.getExchangeId(), meC); return meF; }
/** * This constructs a {@link ClassResolver} from the container {@link ClassLoader}. * * This is needed because when we receive a {@link MessageExchange} from the other side, its class was coming from * the container on the other side. If we didn't use the container {@link ClassLoader}, then we couldn't unserialize * the {@link MessageExchange}. */ private ClassResolver newClassResolver() throws PEtALSCDKException { final ClassLoader cl; try { cl = getChannel().createExchangeFactory().createInOnlyExchange().getClass().getClassLoader(); } catch (final MessagingException e) { throw new PEtALSCDKException(e); } final ClassResolver cr = ClassResolvers.cacheDisabled(cl); final ClassResolver mine = ClassResolvers.cacheDisabled(null); return new ClassResolver() { @Override public @Nullable Class<?> resolve(final @Nullable String className) throws ClassNotFoundException { try { return mine.resolve(className); } catch (final ClassNotFoundException e) { return cr.resolve(className); } } }; }
/** * Sends the message to the bus * @param pdu the trap received */ private void sendSnmpTrapMessage(PDU pdu) { try { // create an inOnly exchange InOnly io = getExchangeFactory().createInOnlyExchange(); // configure the exchange target configureExchangeTarget(io); // create the in message NormalizedMessage inMsg = io.createMessage(); // now let the marshaler convert the snmp data into // a normalized message to send to jbi bus this.marshaler.convertToJBI(io, inMsg, null, pdu); // put the in message into the inOnly exchange io.setInMessage(inMsg); // send the exchange getChannel().send(io); } catch (MessagingException ex) { logger.error("Error while trying to send the snmp trap PDU to the jbi bus", ex); } }
/** * creates a msg object * * @param qname * the service which will be the receiver * @param inOut * should it be inOut or InOnly * @return the created exchange * @throws MessagingException */ public MessageExchange getNewExchange(QName qname, boolean inOut) throws MessagingException { MessageExchange exchange = null; if (inOut) { exchange = getChannel().createExchangeFactoryForService(qname).createInOutExchange(); } else { exchange = getChannel().createExchangeFactoryForService(qname).createInOnlyExchange(); } return exchange; }
/** * sends the message to the bus * * @param request the request PDU * @param response the response PDU */ private void sendSnmpDataMessage(PDU request, PDU response) { try { // create a inOnly exchange InOnly io = getExchangeFactory().createInOnlyExchange(); // configure the exchange target configureExchangeTarget(io); // create the in message NormalizedMessage inMsg = io.createMessage(); // now let the marshaller convert the snmp data into a normalized // message to send to jbi bus this.marshaler.convertToJBI(io, inMsg, request, response); // then put the in message into the inOnly exchange io.setInMessage(inMsg); // and use send to deliver it getChannel().send(io); } catch (MessagingException ex) { logger.error("Error while trying to send the snmp event to the jbi bus", ex); } }
protected void processFile(FTPClient ftp, String file) throws Exception { InputStream in = ftp.retrieveFileStream(file); InOnly exchange = getExchangeFactory().createInOnlyExchange(); configureExchangeTarget(exchange); NormalizedMessage message = exchange.createMessage(); exchange.setInMessage(message); if (getTargetOperation() != null) { exchange.setOperation(getTargetOperation()); } marshaler.readMessage(exchange, message, in, file); if (stateless) { exchange.setProperty(FtpData.class.getName(), new FtpData(file, ftp, in)); } else { this.openExchanges.put(exchange.getExchangeId(), new FtpData(file, ftp, in)); } send(exchange); }
/** * Creates a new InOnly exchange for the given service, interface and/or operation (any of which can be null). */ public InOnly createInOnlyExchange(QName service, QName interfaceName, QName operation) throws MessagingException { DeliveryChannel channel = getDeliveryChannel(); MessageExchangeFactory factory = null; if (service != null) { factory = channel.createExchangeFactoryForService(service); } else if (interfaceName != null) { factory = channel.createExchangeFactory(interfaceName); } else { factory = getExchangeFactory(); } InOnly outExchange = factory.createInOnlyExchange(); if (service != null) { outExchange.setService(service); } if (interfaceName != null) { outExchange.setInterfaceName(interfaceName); } if (operation != null) { outExchange.setOperation(operation); } return outExchange; }
/** * sends the given DOMSource as message to the given service (inOnly) * * @param service * the service name to send the message to * @param source * the source to put in the in message content * @return true on sucessful delivering or false on failure * @throws MessagingException * on any messaging exception */ public boolean sendMessage(QName service, Source source) throws MessagingException { InOnly inOnly = getChannel().createExchangeFactoryForService(service).createInOnlyExchange(); NormalizedMessage msg = inOnly.createMessage(); msg.setContent(source); inOnly.setInMessage(msg); if (getChannel().sendSync(inOnly)) { return inOnly.getStatus() == ExchangeStatus.DONE; } else { return false; } }
protected MessageExchange createJbiMessageExchange(Exchange camelExchange, MessageExchangeFactory exchangeFactory, String defaultMep) throws MessagingException, URISyntaxException { // option 1 -- use the MEP that was configured on the endpoint URI ExchangePattern mep = ExchangePattern.fromWsdlUri(defaultMep); if (mep == null) { // option 2 -- use the MEP from the Camel Exchange mep = camelExchange.getPattern(); } MessageExchange answer = null; if (mep != null) { if (mep == ExchangePattern.InOnly) { answer = exchangeFactory.createInOnlyExchange(); } else if (mep == ExchangePattern.InOptionalOut) { answer = exchangeFactory.createInOptionalOutExchange(); } else if (mep == ExchangePattern.InOut) { answer = exchangeFactory.createInOutExchange(); } else if (mep == ExchangePattern.RobustInOnly) { answer = exchangeFactory.createRobustInOnlyExchange(); } else { answer = exchangeFactory.createExchange(new URI(mep.toString())); } } if (getOperation(camelExchange) != null) { answer.setOperation(getOperation(camelExchange)); } return answer; }
/** * Creates a new InOnly exchange for the given service, interface and/or operation (any of which can be null). */ public InOnly createInOnlyExchange(QName service, QName interfaceName, QName operation) throws MessagingException { MessageExchangeFactory factory = null; if (service != null) { factory = getDeliveryChannel().createExchangeFactoryForService(service); } else if (interfaceName != null) { factory = getDeliveryChannel().createExchangeFactory(interfaceName); } else { factory = getExchangeFactory(); } InOnly outExchange = factory.createInOnlyExchange(); if (service != null) { outExchange.setService(service); } if (interfaceName != null) { outExchange.setInterfaceName(interfaceName); } if (operation != null) { outExchange.setOperation(operation); } return outExchange; }
protected void sendAggregate(String processCorrelationId, String correlationId, Object aggregation, boolean timeout, boolean sync) throws Exception { InOnly me = getExchangeFactory().createInOnlyExchange(); if (processCorrelationId != null) { me.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId); } me.setProperty(getService().toString() + ":" + getEndpoint() + ":correlation", correlationId); target.configureTarget(me, getContext()); NormalizedMessage nm = me.createMessage(); me.setInMessage(nm); buildAggregate(aggregation, nm, me, timeout); closeAggregation(correlationId); if (sync) { sendSync(me); } else { send(me); } }
private void sendSyncToListenerAndTarget(MessageExchange source, MessageExchange dest, ExchangeTarget listener, String message, boolean copy) throws Exception { if (listener != null) { NormalizedMessage msg = MessageUtil.copy(source.getMessage(message)); InOnly lme = getExchangeFactory().createInOnlyExchange(); if (store.hasFeature(Store.CLUSTERED)) { lme.setProperty(JbiConstants.STATELESS_CONSUMER, Boolean.TRUE); } listener.configureTarget(lme, getContext()); MessageUtil.transferToIn(msg, lme); sendSync(lme); MessageUtil.transferTo(msg, dest, message); if (copy) { copyExchangeProperties(dest, "in", message); } sendSync(dest); } else { MessageUtil.transferTo(source, dest, message); if (copy) { copyExchangeProperties(dest, "in", message); } sendSync(dest); } }
private void sendToListenerAndTarget(MessageExchange source, MessageExchange dest, ExchangeTarget listener, String message, boolean copy) throws Exception { if (listener != null) { NormalizedMessage msg = MessageUtil.copy(source.getMessage(message)); InOnly lme = getExchangeFactory().createInOnlyExchange(); if (store.hasFeature(Store.CLUSTERED)) { lme.setProperty(JbiConstants.STATELESS_CONSUMER, Boolean.TRUE); } listener.configureTarget(lme, getContext()); MessageUtil.transferToIn(msg, lme); send(lme); MessageUtil.transferTo(msg, dest, message); if (copy) { copyExchangeProperties(dest, "in", message); } send(dest); } else { MessageUtil.transferTo(source, dest, message); if (copy) { copyExchangeProperties(dest, "in", message); } send(dest); } }
public void sendMessages(int messageCount, boolean sync) throws JBIException { ComponentContext context = getContext(); for (int i = 0; i < messageCount; i++) { InOnly exchange = context.getDeliveryChannel().createExchangeFactory().createInOnlyExchange(); NormalizedMessage msg = exchange.createMessage(); ServiceEndpoint destination = null; if (resolver != null) { destination = resolver.resolveEndpoint(getContext(), exchange, NullEndpointFilter.getInstance()); } if (destination != null) { // lets explicitly specify the destination - otherwise // we'll let the container choose for us exchange.setEndpoint(destination); } exchange.setInMessage(msg); // lets set the XML as a byte[], String or DOM etc msg.setContent(new StringSource(this.message)); if (sync) { boolean result = context.getDeliveryChannel().sendSync(exchange, 1000); if (!result) { throw new MessagingException("Message delivery using sendSync has timed out"); } } else { context.getDeliveryChannel().send(exchange); } } }