public String getBodyText() throws TransformerException { return TRANSFORMER.toString(getContent()); }
/** * Write to a Stream * * @param out * @throws IOException */ public void writeExternal(ObjectOutput out) throws IOException { try { convertAttachments(); out.writeObject(attachments); out.writeObject(properties); String src = TRANSFORMER.toString(content); out.writeObject(src); // We have read the source // so now, ensure that it can be re-read if ((content instanceof StreamSource || content instanceof SAXSource) && !(content instanceof StringSource) && !(content instanceof BytesSource) && !(content instanceof ResourceSource)) { content = new StringSource(src); } out.writeObject(securitySubject); } catch (TransformerException e) { throw (IOException) new IOException("Could not transform content to string").initCause(e); } }
/** * Intercepts the {@link MessageExchange} to output the message and its * properties for debugging purposes. * * @param exchange A JBI {@link MessageExchange} between two endpoints */ public void onMessageExchange(MessageExchange exchange) throws MessagingException { // lets dump the incoming message NormalizedMessage message = exchange.getMessage("in"); if (message == null) { LOGGER.warn("Received null message from exchange: {}", exchange); } else { LOGGER.info("Exchange: {} received IN message: {}", exchange, message); try { LOGGER.info("Body is: {}", sourceTransformer.toString(message.getContent())); } catch (TransformerException e) { LOGGER.error("Failed to turn message body into text: {}", e.getMessage(), e); } outputProperties(message); } done(exchange); }
SourceTransformer transform = new SourceTransformer(); XStream xstream = new XStream(new DomDriver()); String result = transform.toString(content);
Node node = st.toDOMNode(content); message.setContent(new DOMSource(node)); String str = st.toString(node); if (str.length() > MAX_MSG_DISPLAY_SIZE) { sb.append(str.substring(0, MAX_MSG_DISPLAY_SIZE)).append("...");
Node node = sourceTransformer.toDOMNode(message.getContent()); message.setContent(new DOMSource(node)); String str = sourceTransformer.toString(node); if (maxMsgDisplaySize < 0 || str.length() <= maxMsgDisplaySize) { sb.append(str); if (contents instanceof Source) { try { contents = sourceTransformer.toString((Source) contents); } catch (Exception e) { }
/** * Outputs the properties on the {@link NormalizedMessage}. Properties of * type {@link Source} are transformed to a {@link String} before * being output. * * @param message The {@link NormalizedMessage} to be processed */ @SuppressWarnings("unchecked") protected void outputProperties(NormalizedMessage message) { // Loop over all the properties on the normalized message for (Object o : message.getPropertyNames()) { // NormalizedMessage API does not use generics. This interface is // written in Java older than 5.0. On the basis of other methods and // the default implementation of this interface we can assume that // only String keys are allowed. String key = (String) o; try { Object contents = message.getProperty(key); // Is this the only value type that we would like to treat // differently? The default behavior is to invoke toString() on // the object. if (contents instanceof Source) { contents = getSourceTransformer().toString((Source) contents); } LOGGER.info("Value for property '{}' is: {}", key, contents); } catch (TransformerException e) { LOGGER.error("Failed to turn property '{}' value into text", key, e); } } }
protected void assertMessageBody(MessageList messageList, int index, String expectedXml) throws TransformerException { NormalizedMessage message = (NormalizedMessage) messageList.getMessages().get(index); assertNotNull("Message: " + index + " is null!", message); Source content = message.getContent(); assertNotNull("Message content: " + index + " is null!", content); String value = transformer.toString(content); assertEquals("message XML for: " + index, expectedXml, value); }
protected void assertMessageXPath(MessageList messageList, int index, String xpath, String expectedValue) throws TransformerException, ParserConfigurationException, IOException, SAXException { NormalizedMessage message = (NormalizedMessage) messageList.getMessages().get(index); assertNotNull("Message: " + index + " is null!", message); Source content = message.getContent(); assertNotNull("Message content: " + index + " is null!", content); Node node = transformer.toDOMNode(content); String value = textValueOfXPath(node, xpath); String xmlText = transformer.toString(node); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Message: " + index + " received XML: " + xmlText); } assertEquals("message XML: " + index + " for xpath: " + xpath + " body was: " + xmlText, expectedValue, value); } }
if (contents instanceof Source) { try { contents = sourceTransformer.toString((Source) contents); } catch (Exception e) { }
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)); } }
protected void assertExchangeWorked(MessageExchange me) throws Exception { if (me.getStatus() == ExchangeStatus.ERROR) { if (me.getError() != null) { throw me.getError(); } else { fail("Received ERROR status"); } } else if (me.getFault() != null) { fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent())); } }