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); } }
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()); }
/** * Get the error messages as a DOMSource. * * @return * @throws MessagingException */ private DOMSource getDOMSource() throws MessagingException { try { return sourceTransformer.toDOMSource(getStringSource()); } catch (ParserConfigurationException e) { throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e); } catch (IOException e) { throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e); } catch (SAXException e) { throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e); } catch (TransformerException e) { throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e); } }
DOMSource src = sourceTransformer.toDOMSource(in.getContent()); .supportsMessageFormat(StringSource.class)) { fault.setContent(sourceTransformer .toDOMSource((StringSource) errorHandler .getMessagesAs(StringSource.class))); } else if (errorHandler.supportsMessageFormat(String.class)) { fault.setContent(sourceTransformer .toDOMSource(new StringSource( (String) errorHandler .getMessagesAs(String.class))));
/** * <p> * Converts the given {@link NormalizedMessage} instance's content to a re-readable {@link Source} This allows the * content to be read more than once (e.g. for XPath evaluation or auditing). * </p> * * @param message the {@link NormalizedMessage} to convert the content for. */ public static void enableContentRereadability(NormalizedMessage message) throws MessagingException { if (message.getContent() instanceof StreamSource || message.getContent() instanceof SAXSource) { try { DOMSource domSource = (DOMSource)sourceTransformer.toDOMSource(message); if (domSource != null) { message.setContent(domSource); } } catch (TransformerException e) { throw new MessagingException("Unable to convert message content into DOMSource", e); } catch (ParserConfigurationException e) { throw new MessagingException("Unable to convert message content into DOMSource", e); } catch (IOException e) { throw new MessagingException("Unable to convert message content into DOMSource", e); } catch (SAXException e) { throw new MessagingException("Unable to convert message content into DOMSource", e); } } }
/** * sends the given DOMSource as message to the given service (inOut) * * @param service * the service name to send the message to * @param source * the source to put in the in message content * @return the DOMSource of the out message or null * @throws MessagingException * on any messaging exception */ public Source sendRequest(QName service, Source source) throws MessagingException { InOut inOut = getChannel().createExchangeFactoryForService(service).createInOutExchange(); NormalizedMessage msg = inOut.createMessage(); msg.setContent(source); inOut.setInMessage(msg); if (getChannel().sendSync(inOut)) { try { Source result = sourceTransformer.toDOMSource(inOut.getOutMessage().getContent()); done(inOut); return result; } catch (Exception ex) { ex.printStackTrace(); return null; } } else { return null; } }
content = sourceTransformer.toDOMSource(from); } catch (TransformerException e) { throw new MessagingException(e);