/** * Send the file as a Source * * @param file * @param message * @throws IOException * @throws MessagingException */ public static final void copyFileToContent(final File file, final NormalizedMessage message) throws IOException, MessagingException { final StreamSource source = new StreamSource(new FileInputStream(file)); message.setContent(source); }
/** * A helper method to reply to a given message exchange with a given Source * * @param exchange the message exchange * @param answer the answer as an XML source * @throws MessagingException */ public void answer(MessageExchange exchange, Source answer) throws MessagingException { NormalizedMessage message = exchange.createMessage(); message.setContent(answer); answer(exchange, message); }
protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException { getMessageTransformer().transform(exchange, in, out); out.setContent(getResponseContent()); Map map = getResponseProperties(); if (map != null) { for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); out.setProperty(name, value); } } return true; } }
/** * Extract the content as a jaxp Source */ private void getContent(NormalizedMessage nm, Message message) throws MessagingException { Exception e = message.getContent(Exception.class); if (e == null) { nm.setContent(message.getContent(Source.class)); /* * } else if (e instanceof SoapFault) { SoapFault fault = * (SoapFault) e; nm.setContent(fault.getDetails()); * nm.setProperty(JbiConstants.SOAP_FAULT_CODE, fault.getCode()); * nm.setProperty(JbiConstants.SOAP_FAULT_NODE, fault.getNode()); * nm.setProperty(JbiConstants.SOAP_FAULT_REASON, * fault.getReason()); nm.setProperty(JbiConstants.SOAP_FAULT_ROLE, * fault.getRole()); nm.setProperty(JbiConstants.SOAP_FAULT_SUBCODE, * fault.getSubcode()); */ } }
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()); }
public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException { if (useDOM) { try { Document document = transformer.createDocument(); getXStream().marshal(body, new DomWriter(document)); message.setContent(new DOMSource(document)); } catch (ParserConfigurationException e) { throw new MessagingException("Failed to marshal: " + body + " to DOM document: " + e, e); } } else { String xml = getXStream().toXML(body); message.setContent(new StringSource(xml)); } }
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()); }
public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception { MessageExchange me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep()); NormalizedMessage in = me.createMessage(); in.setContent(new StreamSource(getRequestEncodingStream(request.getHeader(HttpHeaders.CONTENT_ENCODING), request.getInputStream()))); me.setMessage(in, "in"); return me; }
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); } }
public WrappedRequestToProviderMessage(ServiceConfiguration serviceConfiguration, QName operation, URI mep, InputStream inMessageContentStream, FlowAttributes flowAttributes) { super(serviceConfiguration, operation, mep, flowAttributes); try { setRole(Role.CONSUMER); NormalizedMessage inNm = this.messageExchange.createMessage(); inNm.setContent(new StreamSource(inMessageContentStream)); this.messageExchange.setMessage(inNm, Exchange.IN_MESSAGE_NAME); setRole(Role.PROVIDER); } catch (MessagingException e) { throw new UncheckedException("Impossible to create a message exchange", e); } }
@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); } }
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; }
private static void copyContent(NormalizedMessage from, NormalizedMessage to) throws MessagingException { String str = null; try { str = new SourceTransformer().toString(from.getContent()); } catch (Exception e) { throw new MessagingException(e); } if (str != null) { to.setContent(new StringSource(str)); } }
public MessageExchange createExchange(HttpServletRequest request, ComponentContext context) throws Exception { MessageExchange me = context.getDeliveryChannel().createExchangeFactory().createExchange(getDefaultMep()); NormalizedMessage in = me.createMessage(); in.setContent(marshal(request.getInputStream())); me.setMessage(in, "in"); return me; }
protected void populateMessage(Message message, NormalizedMessage normalizedMessage) throws Exception { if (message instanceof TextMessage) { PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsInInterceptor()); chain.add(new StaxInInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(InputStream.class, new ByteArrayInputStream(((TextMessage) message).getText().getBytes())); if (message.propertyExists(CONTENT_TYPE_PROPERTY)) { msg.put(org.apache.servicemix.soap.api.Message.CONTENT_TYPE, message.getStringProperty(CONTENT_TYPE_PROPERTY)); } chain.doIntercept(msg); XMLStreamReader xmlReader = msg.getContent(XMLStreamReader.class); normalizedMessage.setContent(new StaxSource(xmlReader)); for (Map.Entry<String, DataHandler> attachment : msg.getAttachments().entrySet()) { normalizedMessage.addAttachment(attachment.getKey(), attachment.getValue()); } } else { throw new UnsupportedOperationException("JMS message is not a TextMessage"); } }
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 Message createOut(MessageExchange exchange, NormalizedMessage outMsg, Session session, JmsContext context) throws Exception { Source source = outMsg.getContent(); if (!(source instanceof DOMSource)) { source = sourceTransformer.toDOMSource(source); outMsg.setContent(source); } org.apache.servicemix.soap.api.Message in = ((Context) context).msg; org.apache.servicemix.soap.api.Message msg = binding.createMessage(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); msg.setContent(OutputStream.class, baos); msg.setContent(MessageExchange.class, exchange); msg.setContent(NormalizedMessage.class, outMsg); msg.put(SoapVersion.class, in.get(SoapVersion.class)); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); InterceptorChain phase = getChain(Phase.ServerOut); phase.doIntercept(msg); return session.createTextMessage(baos.toString()); }
public void populateMessage(Message message, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception { if (message instanceof TextMessage) { PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsInInterceptor()); chain.add(new StaxInInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(InputStream.class, new ByteArrayInputStream(((TextMessage) message).getText().getBytes())); if (message.propertyExists(CONTENT_TYPE_PROPERTY)) { msg.put(org.apache.servicemix.soap.api.Message.CONTENT_TYPE, message.getStringProperty(CONTENT_TYPE_PROPERTY)); } chain.doIntercept(msg); XMLStreamReader xmlReader = msg.getContent(XMLStreamReader.class); normalizedMessage.setContent(new StaxSource(xmlReader)); for (Map.Entry<String, DataHandler> attachment : msg.getAttachments().entrySet()) { normalizedMessage.addAttachment(attachment.getKey(), attachment.getValue()); } if (isCopyProperties()) { copyPropertiesFromJMS(message, normalizedMessage); } } else { throw new UnsupportedOperationException("JMS message is not a TextMessage"); } }
/** * Extract the content as a jaxp Source */ private void getContent(NormalizedMessage nm, Message message) throws MessagingException { Exception e = message.getContent(Exception.class); if (e == null) { nm.setContent(message.getContent(Source.class)); } else if (e instanceof SoapFault) { SoapFault fault = (SoapFault) e; nm.setContent(fault.getDetails()); nm.setProperty(JbiConstants.SOAP_FAULT_CODE, fault.getCode()); nm.setProperty(JbiConstants.SOAP_FAULT_NODE, fault.getNode()); nm.setProperty(JbiConstants.SOAP_FAULT_REASON, fault.getReason()); nm.setProperty(JbiConstants.SOAP_FAULT_ROLE, fault.getRole()); nm.setProperty(JbiConstants.SOAP_FAULT_SUBCODE, fault.getSubcode()); } }
/** * 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; } }