Refine search
public static void transfer(NormalizedMessage source, NormalizedMessage dest) throws MessagingException { dest.setContent(source.getContent()); for (Iterator it = source.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.setProperty(name, source.getProperty(name)); } for (Iterator it = source.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); dest.addAttachment(name, source.getAttachment(name)); } dest.setSecuritySubject(source.getSecuritySubject()); }
/** * Copies the subject from a message to another message * * @param from the message with the subject * @param to the message to which the subject is added * @throws MessagingException if an attachment could not be added */ public static void copySecuritySubject(NormalizedMessage from, NormalizedMessage to) throws MessagingException { to.setSecuritySubject(from.getSecuritySubject()); }
private static void copyProperties(NormalizedMessage from, NormalizedMessage to) { for (Object name : from.getPropertyNames()) { to.setProperty((String)name, from.getProperty((String)name)); } }
/** * Copies attachments from one message to another that do not already exist * * @param from the message with the attachments * @param to the destination message where the attachments are to be added * @throws javax.jbi.messaging.MessagingException if an attachment could not be added */ protected void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException { for (String attachmentName : (Set<String>) from.getAttachmentNames()) { // Do not copy existing attachments if (to.getAttachment(attachmentName) == null) { DataHandler value = from.getAttachment(attachmentName); to.addAttachment(attachmentName, value); } } }
if (out != null) { try { final XMLStreamWriter writer = getTransformer().getOutputFactory() .createXMLStreamWriter(out, message.getEncoding()); message.getSerializer().writeMessage(message, writer, context); me.setInterfaceName((QName) context.getService().getProperty(JBI_INTERFACE_NAME)); me.setOperation(context.getExchange().getOperation().getQName()); me.setService((QName) context.getService().getProperty(JBI_SERVICE_NAME)); me.setEndpoint((ServiceEndpoint) context.getService().getProperty(JBI_ENDPOINT)); NormalizedMessage msg = me.createMessage(); NormalizedMessage oldMsg = (oldMe != null) ? oldMe.getMessage("in") : null; if (oldMsg != null) { msg.setSecuritySubject(oldMsg.getSecuritySubject()); me.setOperation(context.getExchange().getOperation().getQName()); msg.setContent(getContent(context, message)); if (!channel.sendSync(me)) { throw new XFireException("Unable to send jbi exchange: sendSync returned false"); throw xfireFault; } else if (me.getMessage("out") != null) { Source outSrc = me.getMessage("out").getContent(); InMessage inMessage = new InMessage(getTransformer().toXMLStreamReader(outSrc), getUri()); getEndpoint().onReceive(context, inMessage);
protected MessageExchange createPart(URI pattern, NormalizedMessage srcMessage, Source content) throws Exception { MessageExchange me = getExchangeFactory().createExchange(pattern); NormalizedMessage in = me.createMessage(); in.setContent(content); me.setMessage(in, "in"); if (forwardAttachments) { Set names = srcMessage.getAttachmentNames(); for (Iterator iter = names.iterator(); iter.hasNext();) { String name = (String) iter.next(); in.addAttachment(name, srcMessage.getAttachment(name)); } } if (forwardProperties) { Set names = srcMessage.getPropertyNames(); for (Iterator iter = names.iterator(); iter.hasNext();) { String name = (String) iter.next(); in.setProperty(name, srcMessage.getProperty(name)); } } return me; }
/** * {@inheritDoc} */ public void exchangeSent(ExchangeEvent event) { try { MessageExchange exchange = event.getExchange(); if (exchange.getStatus() == ExchangeStatus.ACTIVE) { OutputStream os = getOutputStream(exchange); writeFileHeader(os, exchange); NormalizedMessage in = exchange.getMessage("in"); if (StreamSource.class.isAssignableFrom(in.getContent().getClass())) { StreamSource original = (StreamSource) exchange.getMessage("in").getContent(); TeeInputStream tis = new TeeInputStream(original.getInputStream(), os); exchange.getMessage("in").setContent(new StreamSource(tis)); } else { MessageUtil.enableContentRereadability(in); SourceTransformer transformer = new SourceTransformer(); transformer.toResult(in.getContent(), new StreamResult(os)); } } } catch (IOException e) { LOGGER.error("Error occured while storing message {}", event.getExchange().getExchangeId(), e); } catch (TransformerException e) { LOGGER.error("Error occurred while storing message {}", event.getExchange().getExchangeId(), e); } catch (MessagingException e) { LOGGER.error("Error occurred while storing message {}", event.getExchange().getExchangeId(), e); } }
exchange = createExchange(message); if (operation != null) { exchange.setOperation(operation.getName()); nm = exchange.createMessage(); exchange.setMessage(nm, "in"); message.setContent(MessageExchange.class, exchange); } else { nm.setSecuritySubject(message.get(Subject.class));
/** * Copies content, headers, security subject and attachments from the JBI NormalizedMessage to the Camel Message. * * @param from the source {@link NormalizedMessage} * @param to the target {@link Message} */ public void copyFromJbiToCamel(NormalizedMessage from, Message to) { to.setBody(from.getContent()); Subject securitySubject = from.getSecuritySubject(); if (securitySubject != null) { to.setHeader(SECURITY_SUBJECT, securitySubject); } Exchange exchange = to.getExchange(); for (Object object : from.getPropertyNames()) { String key = object.toString(); Object value = from.getProperty(key); if (!strategies.applyFilterToCamelHeaders(key, value, exchange)) { to.setHeader(key, value); } } for (Object id : from.getAttachmentNames()) { to.addAttachment(id.toString(), from.getAttachment(id.toString())); } }
protected MessageExchange[] createParts(MessageExchange exchange) throws Exception { NormalizedMessage in = MessageUtil.copyIn(exchange); Source[] srcParts = split(in.getContent()); MessageExchange[] parts = new MessageExchange[srcParts.length]; for (int i = 0; i < srcParts.length; i++) { parts[i] = createPart(exchange.getPattern(), in, srcParts[i]); NormalizedMessage msg = parts[i].getMessage("in"); msg.setProperty(SPLITTER_COUNT, new Integer(srcParts.length)); msg.setProperty(SPLITTER_INDEX, new Integer(i)); msg.setProperty(SPLITTER_CORRID, exchange.getExchangeId()); } return parts; }
public WrappedStatusFromConsumerMessage(ServiceConfiguration serviceConfiguration, QName operation, URI mep, InputStream outMessageContentStream, FlowAttributes flowAttributes, ExchangeStatus status) { super(serviceConfiguration, operation, mep, flowAttributes); try { setRole(Role.PROVIDER); NormalizedMessage outNm = this.messageExchange.createMessage(); outNm.setContent(new StreamSource(outMessageContentStream)); this.messageExchange.setMessage(outNm, Exchange.OUT_MESSAGE_NAME); closeExchangeAsConsumer(status); } catch (MessagingException e) { throw new UncheckedException("Impossible to create a message exchange", e); } }
if (fake instanceof javax.jbi.messaging.Fault) { concrete = concreteME.createFault(); } else { concrete = concreteME.createMessage(); concrete.setContent(fake.getContent()); concrete.setProperty((String) property, fake.getProperty((String) property)); concrete.setSecuritySubject(fake.getSecuritySubject()); concrete.addAttachment((String) attachmentName, fake.getAttachment((String) attachmentName));
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { String str = new SourceTransformer().contentToString(message); if (str != null) { this.content = new StringSource(str); } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
/** * A utility method to copy properties from the input of the original * exchange to the output of the original exchange. * * @param exchange * @param srcMessage * @param @dstMessage * @throws Exception */ private void copyExchangeProperties(MessageExchange exchange, String srcMessage, String dstMessage) { NormalizedMessage src = exchange.getMessage(srcMessage); NormalizedMessage dst = exchange.getMessage(dstMessage); for (Iterator iter = src.getPropertyNames().iterator(); iter.hasNext();) { String name = (String) iter.next(); if (dst.getProperty(name) == null) { Object prop = src.getProperty(name); dst.setProperty(name, prop); } } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { DOMSource domSource = (DOMSource)sourceTransformer.toDOMSource(message); if (domSource != null) { this.content = domSource; } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
nm = exchange.createMessage(); exchange.setMessage(nm, "in"); message.setContent(MessageExchange.class, exchange); } else { nm = exchange.createMessage(); exchange.setMessage(nm, "out"); } else { nm.setSecuritySubject(message.get(Subject.class));
public void copyFromCamelToJbi(Exchange exchange, MessageExchange messageExchange) throws MessagingException { // add Exchange properties to the MessageExchange without overwriting any existing properties copyPropertiesFromCamelToJbi(exchange, messageExchange); NormalizedMessage in = messageExchange.getMessage("in"); for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) { in.setProperty(entry.getKey(), entry.getValue()); } if (isOutCapable(messageExchange)) { if (exchange.hasOut()) { NormalizedMessage out = messageExchange.createMessage(); copyFromCamelToJbi(exchange.getOut(), out); messageExchange.setMessage(out, "out"); } else { //JBI MEP requires a reply and the Camel exchange failed to produce one -- echoing back the request NormalizedMessage out = messageExchange.createMessage(); copyFromCamelToJbi(exchange.getIn(), out); messageExchange.setMessage(out, "out"); } } }
public void handleMessage(Message message) { List<Attachment> attachmentList = new ArrayList<Attachment>(); MessageExchange exchange = message.get(MessageExchange.class); NormalizedMessage norMessage = null; if (isRequestor(message)) { norMessage = (NormalizedMessage) exchange.getMessage("out"); } else { norMessage = (NormalizedMessage) exchange.getMessage("in"); } if (norMessage == null) { norMessage = (NormalizedMessage) exchange.getFault(); } if (norMessage ==null) { return; } Set names = norMessage.getAttachmentNames(); for (Object obj : names) { String id = (String)obj; DataHandler dh = norMessage.getAttachment(id); attachmentList.add(new AttachmentImpl(id, dh)); } message.setAttachments(attachmentList); }
public void copyFromCamelToJbi(Message message, NormalizedMessage normalizedMessage) throws MessagingException { if (message != null && message.getBody() != null) { Source body = message.getBody(Source.class); if (body == null) { logger.warn("Unable to convert message body of type {} into an XML Source", message.getBody().getClass()); } else { normalizedMessage.setContent(body); } } Subject securitySubject = getSecuritySubject(message); if (securitySubject != null) { normalizedMessage.setSecuritySubject(securitySubject); } Exchange exchange = message.getExchange(); for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value != null && !strategies.applyFilterToCamelHeaders(key, value, exchange)) { normalizedMessage.setProperty(key, value); } } for (String id : message.getAttachmentNames()) { normalizedMessage.addAttachment(id, message.getAttachment(id)); } }
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; }