public Source getResponseContent() { if (responseContent == null) { if (responseXml != null) { responseContent = new StringSource(responseXml); } else if (responseResource != null) { return new ResourceSource(responseResource); } } return responseContent; }
/** * Keep the getter/setter to keep xbean annotation * @org.apache.xbean.Map entryName="namespace" keyName="prefix" * @return Returns the namespaces. */ public Map<String, String> getNamespaces() { return super.getNamespaces(); }
/** * Map of namespaces. * @param namespaces The namespaces to set. */ public void setNamespaces(Map<String, String> namespaces) { super.setNamespaces(namespaces); }
/** * 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); } } }
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 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())); }
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; }
public Jsr181Endpoint() { this.transformer = new SourceTransformer(); }
private static Element toElement(Source src) throws Fault { try { SourceTransformer transformer = new SourceTransformer(); Element ret = transformer.toDOMElement(src); ret = removeEmptyDefaultTns(ret); return ret; } catch (Exception e) { throw new Fault(e); } }
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())); } }
/** * Read from a stream * * @param in * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { attachments = (Map) in.readObject(); properties = (Map) in.readObject(); String src = (String) in.readObject(); if (src != null) { content = new StringSource(src); } securitySubject = (Subject) in.readObject(); }
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)); } }
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; }
public void sendOut(MessageExchange exchange, NormalizedMessage outMsg, HttpServletRequest request, HttpServletResponse response) throws Exception { addResponseHeaders(exchange, request, response); response.setStatus(HttpServletResponse.SC_OK); XMLStreamReader reader = transformer.toXMLStreamReader(outMsg.getContent()); OutputStream encodingStream = getResponseEncodingStream(request.getHeader(HttpHeaders.ACCEPT_ENCODING), response.getOutputStream()); XMLStreamWriter writer = transformer.getOutputFactory().createXMLStreamWriter(encodingStream); writer.writeStartDocument(); XMLStreamHelper.copy(reader, writer); writer.writeEndDocument(); writer.close(); encodingStream.close(); }
public String getBodyText() throws TransformerException { return TRANSFORMER.toString(getContent()); }
protected Document parse(Resource res) throws Exception { URL url = null; try { url = res.getURL(); } catch (IOException e) { // Ignore } DocumentBuilder builder = sourceTransformer.createDocumentBuilder(); return builder.parse(res.getInputStream(), url != null ? url.toExternalForm() : null); }
protected static SourceTransformer getTransformer() { SourceTransformer t = transformer.get(); if (t == null) { t = new SourceTransformer(); transformer.set(t); } return t; }
/** * Get the error messages as a String Source. * * @return */ private StringSource getStringSource() { return new StringSource(getMessagesWithRootElement()); }
protected void setUp() throws Exception { transformer = new SourceTransformer(); context = createBeanFactory(); jbi = (SpringJBIContainer) context.getBean("jbi"); assertNotNull("JBI Container not found in spring!", jbi); }
public void setBodyText(String xml) { setContent(new StringSource(xml)); }