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); } }
@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 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); } }
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(); }
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 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; }
private String extractStringResult(Message<?> replyMessage) throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); StringResult result = new StringResult(); Object payload = replyMessage.getPayload(); if (payload instanceof DOMSource) { transformer.transform(((DOMSource) replyMessage.getPayload()), result); } else if (payload instanceof Document) { transformer.transform(new DOMSource((Document) replyMessage.getPayload()), result); } else { throw new IllegalArgumentException("Unsupported payload type: " + payload.getClass().getName()); } return result.toString(); }
public static String docToString(Document doc) throws Exception { DOMSource source = new DOMSource(doc); StringResult stringResult = new StringResult(); transform(source, stringResult); return stringResult.toString(); }
public static String sourceToString(Source source) throws Exception { StringResult res = new StringResult(); transform(source, res); return res.toString(); } }
transformer.transform(requestMessage.getPayloadSource(), stringResult); assertEquals(request, stringResult.toString());
transformer.transform(requestMessage.getPayloadSource(), stringResult); assertEquals(request, stringResult.toString());
private String getSourceString() { if (source != null) { try { StringResult result = new StringResult(); Transformer transformer = createNonIndentingTransformer(); transformer.transform(source, result); return result.toString(); } catch (TransformerException ex) { // Ignore } } return null; }
private String getSourceString() { if (source != null) { try { StringResult result = new StringResult(); Transformer transformer = createNonIndentingTransformer(); transformer.transform(source, result); return result.toString(); } catch (TransformerException ex) { // Ignore } } return null; }
private String getSourceString() { if (source != null) { try { StringResult result = new StringResult(); Transformer transformer = createNonIndentingTransformer(); transformer.transform(source, result); return result.toString(); } catch (TransformerException ex) { // Ignore } } return null; }
public String serializeDocument(Source source) { StringResult result = new StringResult(); transform(source, result); return result.toString(); }
/** * Converts {@link Source} to {@link String}. * @param source * @return */ public static String serialize(Source source) { StringResult result = new StringResult(); transform(source, result); return result.toString(); }
/** * Marshals the given object to a {@link TextMessage}. * * @param object the object to be marshalled * @param session current JMS session * @param marshaller the marshaller to use * @return the resulting message * @throws JMSException if thrown by JMS methods * @throws IOException in case of I/O errors * @see Session#createTextMessage * @see Marshaller#marshal(Object, Result) */ protected TextMessage marshalToTextMessage(Object object, Session session, Marshaller marshaller) throws JMSException, IOException { StringResult result = new StringResult(); marshaller.marshal(object, result); return session.createTextMessage(result.toString()); }
/** * Does XSLT transformation. * @param template * @param source * @return * @throws TransformerException */ Source transform(Source template, Source source) { try { StringResult transformedExpectedDocument = new StringResult(); transform(template, source, transformedExpectedDocument); return new StringSource(transformedExpectedDocument.toString()); } catch (TransformerException e) { throw new IllegalArgumentException("Transformation error",e); } } /**
/** * Expect this message header data as model object which is marshalled to a character sequence * using the default object to xml mapper before validation is performed. * @param model * @param marshaller * @return */ public T headerFragment(Object model, Marshaller marshaller) { StringResult result = new StringResult(); try { marshaller.marshal(model, result); } catch (XmlMappingException e) { throw new CitrusRuntimeException("Failed to marshal object graph for message header data", e); } catch (IOException e) { throw new CitrusRuntimeException("Failed to marshal object graph for message header data", e); } return header(result.toString()); }