Refine search
protected void generateDocument(HttpServletResponse response, Node node) throws Exception { if (node == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to find requested resource"); return; } response.setStatus(200); response.setContentType("text/xml"); new SourceTransformer().toResult(new DOMSource(node), new StreamResult(response.getOutputStream())); }
protected void assertMessagesReceived(MessageList messageList, int count) throws MessagingException, TransformerException, ParserConfigurationException, IOException, SAXException { messageList.assertMessagesReceived(count); List list = messageList.getMessages(); int counter = 0; for (Iterator iter = list.iterator(); iter.hasNext();) { NormalizedMessage message = (NormalizedMessage) iter.next(); LOGGER.info("Message {} is: {}", counter++, message); LOGGER.info(transformer.contentToString(message)); } }
public void buildAggregate(Object aggregation, NormalizedMessage message, MessageExchange exchange, boolean doTimeout) throws Exception { NormalizedMessage[] messages = ((SplitterAggregation) aggregation).messages; String correlationId = ((SplitterAggregation) aggregation).correlationId; SourceTransformer st = new SourceTransformer(); Document doc = st.createDocument(); Element root = createChildElement(aggregateElementName, doc); root.setAttribute(countAttribute, Integer.toString(messages.length)); for (int i = 0; i < messages.length; i++) { if (messages[i] != null) { Element elem = st.toDOMElement(messages[i]); if (messageElementName != null) { Element msg = createChildElement(messageElementName, root); msg.setAttribute(indexAttribute, Integer.toString(i)); msg.appendChild(doc.importNode(elem, true)); } else { root.appendChild(doc.importNode(elem, true)); } if (isCopyProperties()) { copyProperties(messages[i], message); } if (isCopyAttachments()) { copyAttachments(messages[i], message); } } } message.setContent(new DOMSource(doc)); message.setProperty(AbstractSplitter.SPLITTER_CORRID, correlationId); }
private Node getDOMNode(Source source) throws Exception { SourceTransformer sourceTransformer = new SourceTransformer(); Node node = sourceTransformer.toDOMNode(source); if (node.getNodeType() == Node.DOCUMENT_NODE) { node = ((Document) node).getDocumentElement(); } return node; }
protected Source[] split(Source main) throws Exception { Node doc = sourceTransformer.toDOMNode(main); NodeList nodes = (NodeList) xpathExpression.evaluateXPath(doc); Source[] parts = new Source[nodes.getLength()]; for (int i = 0; i < parts.length; i++) { Document part = sourceTransformer.toDOMDocument(nodes.item(i)); parts[i] = new DOMSource(part); } return parts; }
protected void validateMessage(SoapMessage message) throws Fault { Service service = ServiceModelUtil.getService(message.getExchange()); if (service != null) { Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0)); if (schema != null) { javax.xml.validation.Validator validator = schema.newValidator(); try { Element sourceMessage = new SourceTransformer().toDOMElement(message.getContent(Source.class)); message.setContent(Source.class, new DOMSource(sourceMessage)); if (!useJBIWrapper && !useSOAPEnvelope) { validator.validate(new DOMSource(sourceMessage)); } else { Element partWrapper = DomUtil .getFirstChildElement(sourceMessage); while (partWrapper != null) { Element partContent = DomUtil .getFirstChildElement(partWrapper); validator.validate(new DOMSource(partContent)); partWrapper = DomUtil .getNextSiblingElement(partWrapper); } } } catch (Exception e) { throw new Fault(e); } } } }
sb.append(" content: "); try { if (message.getContent() != null) { 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) { }
sb.append(" ").append(msg).append(": "); try { Set<?> propertyNames = message.getPropertyNames(); if (propertyNames.size() > 0) { sb.append("\n ").append(msg).append(" properties: [").append('\n'); for (Object propertyName : propertyNames) { sb.append(" ").append(propertyName).append(" = "); Object propertyValue = message.getProperty((String) propertyName); if (propertyValue != null && propertyValue.getClass().getName().startsWith("java.lang")) { sb.append(propertyValue); Source content = message.getContent(); if (content != null) { if (PRESERVE_CONTENT) { sb.append(content.getClass()); } else { 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("...");
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)); } }
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)))); out.setContent(new DOMSource(result.getNode(), result .getSystemId()));
public Object unmarshal(MessageExchange exchange, NormalizedMessage message) throws MessagingException { Source content = message.getContent(); if (content != null) { if (content instanceof StreamSource) { StreamSource source = (StreamSource) content; return getXStream().fromXML(source.getReader()); } Document document = null; if (content instanceof DOMSource) { DOMSource domSource = (DOMSource) content; document = (Document) domSource.getNode(); } else { DOMResult result = new DOMResult(); try { transformer.toResult(content, result); } catch (TransformerException e) { throw new MessagingException("Failed to transform content: " + content + " to DOMResult: " + e, e); } document = (Document) result.getNode(); } return getXStream().unmarshal(new DomReader(document)); } return super.unmarshal(exchange, message); }
/** * <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); } } }
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); } }
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); } }
if (out != null) { try { final XMLStreamWriter writer = getTransformer().getOutputFactory() .createXMLStreamWriter(out, message.getEncoding()); message.getSerializer().writeMessage(message, writer, context); NormalizedMessage oldMsg = (oldMe != null) ? oldMe.getMessage("in") : null; if (oldMsg != null) { msg.setSecuritySubject(oldMsg.getSecuritySubject()); msg.setContent(getContent(context, message)); if (!channel.sendSync(me)) { throw new XFireException("Unable to send jbi exchange: sendSync returned false"); if (me.getFault() != null) { JDOMResult result = new JDOMResult(); String str = getTransformer().contentToString(me.getFault()); getTransformer().toResult(new StringSource(str), result); Element e = result.getDocument().getRootElement(); e = (Element) e.clone(); } else if (me.getMessage("out") != null) { Source outSrc = me.getMessage("out").getContent(); InMessage inMessage = new InMessage(getTransformer().toXMLStreamReader(outSrc), getUri()); getEndpoint().onReceive(context, inMessage); me.setStatus(ExchangeStatus.DONE);
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)); } }
/** * Convert 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). * * @param message * the {@link NormalizedMessage} to convert the content for * @throws MessagingException */ public static void enableContentRereadability(NormalizedMessage message) throws MessagingException { if (message.getContent() instanceof StreamSource) { try { String content = new SourceTransformer().contentToString(message); if (content != null) { message.setContent(new StringSource(content)); } } catch (TransformerException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (ParserConfigurationException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (IOException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (SAXException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } } }
/** * {@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); } }
/** * 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); } } }
Element element = new SourceTransformer().toDOMElement(nm.getContent());