use of javax.xml.transform.dom.DOMResult in project webservices-axiom by apache.
the class SoapActionTest method runTest.
@Override
protected void runTest() throws Throwable {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document requestDocument = documentBuilder.newDocument();
Element request = requestDocument.createElementNS("urn:test", "p:Echo");
request.setTextContent("Hello");
Document responseDocument = documentBuilder.newDocument();
context.getBean(WebServiceTemplate.class).sendSourceAndReceiveToResult(new DOMSource(request), new SoapActionCallback("http://www.example.com/echo"), new DOMResult(responseDocument));
Element response = responseDocument.getDocumentElement();
assertEquals("urn:test", response.getNamespaceURI());
assertEquals("Echo", response.getLocalName());
assertEquals("Hello", response.getTextContent());
}
use of javax.xml.transform.dom.DOMResult in project webservices-axiom by apache.
the class WSAddressingDOMTest method runTest.
@Override
protected void runTest() throws Throwable {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document requestDocument = documentBuilder.newDocument();
Element request = requestDocument.createElementNS("urn:test", "p:testRequest");
request.setTextContent("test");
Document responseDocument = documentBuilder.newDocument();
context.getBean(WebServiceTemplate.class).sendSourceAndReceiveToResult(new DOMSource(request), new ActionCallback(EchoEndpoint.ACTION), new DOMResult(responseDocument));
Element response = responseDocument.getDocumentElement();
assertEquals("urn:test", response.getNamespaceURI());
assertEquals("testRequest", response.getLocalName());
assertEquals("test", response.getTextContent());
}
use of javax.xml.transform.dom.DOMResult in project webservices-axiom by apache.
the class TestTransformerWithIdentityStylesheet method runTest.
protected void runTest() throws Throwable {
DocumentBuilder builder = dbf.newDocumentBuilder();
Document document = builder.newDocument();
Element root = document.createElementNS("", "root");
Element element = document.createElementNS("urn:mynamespace", "element1");
element.setAttribute("att", "testValue");
element.appendChild(document.createTextNode("test"));
root.appendChild(element);
document.appendChild(root);
Document stylesheet = builder.parse(TestTransformerWithIdentityStylesheet.class.getResourceAsStream("identity.xslt"));
Document output = builder.newDocument();
Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer(new DOMSource(stylesheet));
transformer.transform(new DOMSource(document), new DOMResult(output));
assertAbout(xml()).that(xml(Document.class, output)).ignoringNamespaceDeclarations().hasSameContentAs(xml(Document.class, document));
}
use of javax.xml.transform.dom.DOMResult in project ddf by codice.
the class XacmlClient method addNamespaceAndPrefixes.
/**
* Adds namespaces and namespace prefixes to the XACML response returned by the XACML PDP. The
* XACML PDP returns a response with no namespaces, so we need to add them to unmarshal the
* response.
*
* @param xacmlResponse The XACML response as a string.
* @return DOM representation of the XACML response with namespaces and namespace prefixes.
* @throws PdpException
*/
private DOMResult addNamespaceAndPrefixes(String xacmlResponse) throws PdpException {
XMLReader xmlReader = null;
try {
XMLReader xmlParser = XMLReaderFactory.createXMLReader();
xmlParser.setFeature("http://xml.org/sax/features/external-general-entities", false);
xmlParser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
xmlParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
xmlReader = new XMLFilterImpl(xmlParser) {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
super.startElement(XACML30_NAMESPACE, localName, XACML_PREFIX + ":" + qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
super.endElement(XACML30_NAMESPACE, localName, XACML_PREFIX + ":" + qName);
}
};
} catch (SAXException e) {
String message = "Unable to read XACML response:\n" + xacmlResponse;
LOGGER.info(message);
throw new PdpException(message, e);
}
DOMResult domResult;
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(XacmlClient.class.getClassLoader());
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
domResult = new DOMResult();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(new SAXSource(xmlReader, new InputSource(new StringReader(xacmlResponse))), domResult);
} catch (TransformerException e) {
String message = "Unable to transform XACML response:\n" + xacmlResponse;
LOGGER.info(message);
throw new PdpException(message, e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
return domResult;
}
use of javax.xml.transform.dom.DOMResult in project ddf by codice.
the class XacmlClient method evaluate.
/**
* Evaluates the XACML request and returns a XACML response.
*
* @param xacmlRequestType XACML request
* @return XACML response
* @throws PdpException
*/
public ResponseType evaluate(RequestType xacmlRequestType) throws PdpException {
String xacmlRequest = this.marshal(xacmlRequestType);
String xacmlResponse = this.callPdp(xacmlRequest);
LOGGER.debug("\nXACML 3.0 Response from XACML PDP:\n {}", xacmlResponse);
DOMResult domResult = addNamespaceAndPrefixes(xacmlResponse);
return unmarshal(domResult);
}
Aggregations