public Source issueResponseFor(DOMSource request) { return new DomSourceFactory().createSource( "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">" + request.getNode().getTextContent() + "</echoResponse>"); } }
/** * Template method for handling {@code DOMSource}s. * <p>This implementation delegates to {@code unmarshalDomNode}. * If the given source is empty, an empty source {@code Document} * will be created as a placeholder. * @param domSource the {@code DOMSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if the {@code domSource} is empty * @see #unmarshalDomNode(org.w3c.dom.Node) */ protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException { if (domSource.getNode() == null) { domSource.setNode(buildDocument()); } try { return unmarshalDomNode(domSource.getNode()); } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new UnmarshallingFailureException("NPE while unmarshalling. " + "This can happen on JDK 1.6 due to the presence of DTD " + "declarations, which are disabled.", ex); } throw ex; } }
_hasDOMSource = true; DOMSource domsrc = (DOMSource)source; Node node = domsrc.getNode(); if (node instanceof Document) { _document = (Document)node;
public Object unmarshal( Source source ) throws JAXBException { if( source == null ) { throw new IllegalArgumentException( Messages.format( Messages.MUST_NOT_BE_NULL, "source" ) ); } if(source instanceof SAXSource) return unmarshal( (SAXSource)source ); if(source instanceof StreamSource) return unmarshal( streamSourceToInputSource((StreamSource)source)); if(source instanceof DOMSource) return unmarshal( ((DOMSource)source).getNode() ); // we don't handle other types of Source throw new IllegalArgumentException(); }
@Test public void readDOMSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); }
@Test public void readDOMSourceExternal() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(bodyExternal.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); converter.setSupportDtd(true); DOMSource result = (DOMSource) converter.read(DOMSource.class, inputMessage); Document document = (Document) result.getNode(); assertEquals("Invalid result", "root", document.getDocumentElement().getLocalName()); assertNotEquals("Invalid result", "Foo Bar", document.getDocumentElement().getTextContent()); }
m_pos=m_root = domSource.getNode();
m_pos=m_root = domSource.getNode();
/** * This class wraps an ErrorListener into a MessageHandler in order to * capture messages reported via xsl:message. */ static class MessageHandler extends org.apache.xalan.xsltc.runtime.MessageHandler { private ErrorListener _errorListener; public MessageHandler(ErrorListener errorListener) { _errorListener = errorListener; } public void displayMessage(String msg) { if(_errorListener == null) { System.err.println(msg); } else { try { _errorListener.warning(new TransformerException(msg)); } catch (TransformerException e) { // ignored } } } }
node = dsource.getNode(); baseID = dsource.getSystemId();
node = dsource.getNode(); baseID = dsource.getSystemId();
public Object unmarshal0( Source source, JaxBeanInfo expectedType ) throws JAXBException { if (source instanceof SAXSource) { SAXSource ss = (SAXSource) source; XMLReader locReader = ss.getXMLReader(); if (locReader == null) { locReader = getXMLReader(); } return unmarshal0(locReader, ss.getInputSource(), expectedType); } if (source instanceof StreamSource) { return unmarshal0(getXMLReader(), streamSourceToInputSource((StreamSource) source), expectedType); } if (source instanceof DOMSource) { return unmarshal0(((DOMSource) source).getNode(), expectedType); } // we don't handle other types of Source throw new IllegalArgumentException(); }
final DOMSource domsrc = (DOMSource) source; baseId = domsrc.getSystemId(); final org.w3c.dom.Node node = domsrc.getNode(); final DOM2SAX dom2sax = new DOM2SAX(node);
@Override public <T> JAXBElement<T> unmarshal( Source source, Class<T> expectedType ) throws JAXBException { if (source instanceof SAXSource) { SAXSource ss = (SAXSource) source; XMLReader locReader = ss.getXMLReader(); if (locReader == null) { locReader = getXMLReader(); } return unmarshal(locReader, ss.getInputSource(), expectedType); } if (source instanceof StreamSource) { return unmarshal(getXMLReader(), streamSourceToInputSource((StreamSource) source), expectedType); } if (source instanceof DOMSource) { return unmarshal(((DOMSource) source).getNode(), expectedType); } // we don't handle other types of Source throw new IllegalArgumentException(); }
/** * Emulate the Spring WS MessageDispatcherServlet by calling the gateway * with a DOMSource object representing the payload of the original SOAP * 'echoRequest' message. Expect an 'echoResponse' DOMSource object * to be returned in synchronous fashion, which the MessageDispatcherServlet * would in turn wrap in a SOAP envelope and return to the client. */ @Test public void testSendAndReceive() throws Exception { String xml = "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>"; DomPoxMessageFactory messageFactory = new DomPoxMessageFactory(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(new InputSource(new StringReader(xml))); Transformer transformer = TransformerFactory.newInstance().newTransformer(); DomPoxMessage request = new DomPoxMessage(document, transformer, "text/xml"); MessageContext messageContext = new DefaultMessageContext(request, messageFactory); gateway.invoke(messageContext); Object reply = messageContext.getResponse().getPayloadSource(); assertThat(reply, is(instanceOf(DOMSource.class))); DOMSource replySource = (DOMSource) reply; Element element = (Element) replySource.getNode().getFirstChild(); assertThat(element.getTagName(), equalTo("echoResponse")); } }
Node node = dsource.getNode();
new DOM2TO(domsrc.getNode(), handler).parse(); } else if (source instanceof XSLTCSource) { final DOM dom = ((XSLTCSource) source).getDOM(null, _translet);
Node node = dsource.getNode();
final Document dom = (Document)domsrc.getNode(); final DOM2SAX dom2sax = new DOM2SAX(dom); xsltc.setXMLReader(dom2sax);
Node node = ((DOMSource)source).getNode();