public Jsr181Endpoint() { this.transformer = new SourceTransformer(); }
protected static SourceTransformer getTransformer() { SourceTransformer t = transformer.get(); if (t == null) { t = new SourceTransformer(); transformer.set(t); } return t; }
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 static DocumentFragment createWSAEPR(String uri) { Document doc; try { doc = new SourceTransformer().createDocument(); } catch (Exception e) { throw new RuntimeException(e); } DocumentFragment epr = doc.createDocumentFragment(); Element root = doc.createElement("epr"); Element address = doc.createElementNS(WSAddressingConstants.WSA_NAMESPACE_200508, WSAddressingConstants.WSA_PREFIX + ":" + WSAddressingConstants.EL_ADDRESS); Text txt = doc.createTextNode(uri); address.appendChild(txt); root.appendChild(address); epr.appendChild(root); return epr; }
protected void setUp() throws Exception { transformer = new SourceTransformer(); context = createBeanFactory(); jbi = (SpringJBIContainer) context.getBean("jbi"); assertNotNull("JBI Container not found in spring!", jbi); }
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); } }
SourceTransformer transform = new SourceTransformer(); XStream xstream = new XStream(new DomDriver()); String result = transform.toString(content);
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); }
protected Document createDocument(MessageExchange me) throws MessagingException { try { // This could be in a separated class (a LuceneDocumentProvider) SourceTransformer st = new SourceTransformer(); Document d = new Document(); d.add(Field.Keyword("org.apache.servicemix.exchangeid", me.getExchangeId())); d.add(Field.Keyword("org.apache.servicemix.exchangestatus", String.valueOf(me.getStatus()))); String[] types = {"in", "out", "fault" }; for (int i = 0; i < types.length; i++) { String type = types[i]; NormalizedMessage nm = me.getMessage(type); if (nm != null) { d.add(Field.UnStored("org.apache.servicemix." + type + ".contents", st.contentToString(nm))); addMessagePropertiesToDocument(nm, d, type); } } return d; } catch (MessagingException mse) { throw mse; } catch (Exception ex) { throw new MessagingException("Error while creating Lucene Document", ex); } }
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 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); } } } }
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); } }
if (url != null) { try { DocumentBuilder builder = new SourceTransformer().createDocumentBuilder(); Document doc = builder.parse(url.toString()); classLoader = getClassLoader(applicationContext, reader, doc);
/** * {@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); } }
element = new SourceTransformer().toDOMElement(source); } catch (Exception e) { throw new Fault(e);
element = new SourceTransformer().toDOMElement(source); } 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())); } }
/** * 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); } } }
throw FaultException.newInstance(me); } else if (me.getMessage("out") != null) { return new SourceTransformer().contentToString(me.getMessage("out"));