public static String docAsString(Document doc) { try { StringResult res = new StringResult(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(new DOMSource(doc), res); return res.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
public static final void writeXml(Document document) { Transformer transformer = createIndentingTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); try { StringResult streamResult = new StringResult(); transformer.transform(new DOMSource(document), streamResult); } catch (Exception ex) { throw new IllegalStateException(ex); } } public static final Transformer createIndentingTransformer() {
StringResult stringResult= new StringResult(); Object requestParameters= arg0.getArguments()[0]; Class<?> requestParametersClass = requestParameters.getClass(); return getWebServiceTemplate().sendSourceAndReceive(new StringSource(stringResult.getWriter().toString()), new ItcbResponseExtractor(arg0.getMethod().getReturnType())); return getWebServiceTemplate().sendSourceAndReceive(new StringSource(stringResult.getWriter().toString()), webserviceMessageCallback, new ItcbResponseExtractor(arg0.getMethod().getReturnType()));
private Document createDocumentFromStringResult(StringResult stringResult) { try { return getDocumentBuilder().parse(new InputSource(new StringReader(stringResult.toString()))); } catch (Exception e) { throw new MessagingException("failed to create Document from StringResult payload", e); } }
@Override public void marshal(Object source, Result result) throws XmlMappingException, IOException { if (source instanceof Message) { this.messages.add((Message<?>) source); } else { this.payloads.add(source); } if (result instanceof StringResult) { ((StringResult) result).getWriter().write("hello " + source); } }
public Result createResult(Object payload) { return new StringResult(); }
/** Returns the written XML as a string. */ public String toString() { return getWriter().toString(); }
@Test public void testWebServiceRequestAndResponse() { StringResult result = new StringResult(); Source payload = new StringSource( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>"); template.sendSourceAndReceiveToResult(WS_URI, payload, result); logger.info("RESULT: " + result.toString()); assertThat(result.toString(), equalTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>")); } }
private Object transformSource(Source source, Object payload, Transformer transformer) throws TransformerException { Result result; if (!this.resultFactoryExplicitlySet && "text".equals(transformer.getOutputProperties().getProperty("method"))) { result = new StringResult(); } else { result = getResultFactory().createResult(payload); } transformer.transform(source, result); if (this.resultTransformer != null) { return this.resultTransformer.transformResult(result); } return result; }
/** Returns the written XML as a string. */ public String toString() { return getWriter().toString(); }
private String transformString(String stringPayload, Transformer transformer) throws TransformerException { StringResult result = new StringResult(); Source source; if (this.alwaysUseSourceFactory) { source = this.sourceFactory.createSource(stringPayload); } else { source = new StringSource(stringPayload); } transformer.transform(source, result); return result.toString(); }
@Override protected Object doHandle(String uri, final Message<?> requestMessage, final WebServiceMessageCallback requestCallback) { Object requestPayload = requestMessage.getPayload(); Result responseResultInstance = null; if (requestPayload instanceof String) { responseResultInstance = new StringResult(); } else if (requestPayload instanceof Document) { responseResultInstance = new DOMResult(); } return getWebServiceTemplate() .sendAndReceive(uri, new SimpleRequestMessageCallback(requestCallback, requestMessage), new SimpleResponseMessageExtractor(responseResultInstance)); }
/** Returns the written XML as a string. */ public String toString() { return getWriter().toString(); }
private StringSource createStringSourceForDocument(Document document) { try { StringResult result = new StringResult(); Transformer transformer = getTransformer(); transformer.transform(new DOMSource(document), result); return new StringSource(result.toString()); } catch (Exception e) { throw new MessagingException("failed to create StringSource from document", e); } }
public static StringResult getStringResultForString(String strDoc) throws Exception { StringResult res = new StringResult(); transform(getDomSourceForString(strDoc), res); return res; }
List<String> splitStrings = new ArrayList<>(items.size()); for (Node nodeFromList : items) { StringResult result = new StringResult(); transformer.transform(new DOMSource(nodeFromList), result); splitStrings.add(result.toString()); return new TransformFunctionIterator((Iterator<Node>) nodes, node -> { StringResult result = new StringResult(); try { transformer.transform(new DOMSource(node), result); throw new IllegalStateException("failed to create DocumentBuilder", e); return result.toString(); });
public void sendAndReceiveXMLPayload(String xmlFileNamePath) throws IOException { ClassPathResource classPathResource = new ClassPathResource(xmlFileNamePath); Source requestSource = new ResourceSource(classPathResource); StringResult result = new StringResult(); getWebServiceTemplate(). sendSourceAndReceiveToResult( requestSource, new WSSESecurityHeaderRequestWebServiceMessageCallback(), result ); }
public Object transformResult(Result result) { String returnString = null; if (result instanceof StringResult) { returnString = result.toString(); } else if (result instanceof DOMResult) { try { StringResult stringResult = new StringResult(); getNewTransformer().transform( new DOMSource(((DOMResult) result).getNode()), stringResult); returnString = stringResult.toString(); } catch (TransformerException e) { throw new MessagingException("failed to transform from DOMSource failed", e); } } if (returnString == null) { throw new MessagingException("failed to convert Result type [" + result.getClass().getName() + "] to string"); } return returnString; }
TransformerFactory.newInstance().newTransformer().transform(source, new StringResult()
public static String sourceToString(Source source) throws Exception { StringResult res = new StringResult(); transform(source, res); return res.toString(); } }