/** * Converts the document to a String. * * @throws DOMSerializerException if error occurs. */ public String serializeToString(final Document document) throws DOMSerializerException { return serializeToString((Node) document); }
/** * Converts a document encapsulating a request into a string representation * for the payload * * @param doc request document * @return string representation of the request * @throws Exception is thrown in case an error occurs */ public static String getRequestStringFromDocument(Document doc) throws Exception { return DOMSerializer.createNew().serializeToString(doc); }
/** * Method evaluate is the entry point of the axis1 service. * * @param xacmlRequest the xacmlRequest. * @return Document. * @throws Exception if error occurs. */ public Document evaluate(final Document xacmlRequest) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("Process Request: " + DOMSerializer.createNew().serializeToString(xacmlRequest)); } Element root = xacmlRequest.getDocumentElement(); return evaluateBodyElement(root); }
private String convertLicenseReferencesToString(final Element licClientResp) { StringBuffer sb = new StringBuffer(); NodeList nl = licClientResp.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) { if (nl.item(0).getNodeType() == Node.ELEMENT_NODE) { DOMSerializerOptions lOptions = DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration(); String nodeString = DOMSerializer.createNew(lOptions).serializeToString(nl.item(i)); // what exactly is this? sb.append(nodeString); if (i < nl.getLength() - 1) { sb.append("\n"); } } } return sb.toString(); }
private void compareXml(byte[] body, InputStream in, String txtBody) { // xml comparing is not trivial and error prone // but here we simple parse and serialize both contents with the same algorithm // so normally both will produce the same content Document requestContent = toDom(new ByteArrayInputStream(body)); Document expectedContent = toDom(in); String requestString = DOMSerializer.createNew().serializeToString(requestContent); String expectedString = DOMSerializer.createNew().serializeToString(expectedContent); assertEquals("expected that xml content is equal to file '" + m_fileLocation + "' but they differ!", expectedString, requestString); }
private Document evaluateBodyElement(Element root) throws Exception { XACML1DecisionService decisionService = getXACML1DecisionService(); Document response; try { if ("Reset".equals(root.getLocalName())) { response = handleReset(decisionService); } else if ("Request".equals(root.getLocalName())) { // evaluate single xacml request response = handleXACMLRequest(root, decisionService); } else if ("RequestSet".equals(root.getLocalName())) { // evaluate a set of xacml requests response = handleRequestSet(root, decisionService); } else { throw new IllegalArgumentException( "Request with body node <" + root.getNodeName() + "> are not supported"); } if (LOG.isDebugEnabled()) { LOG.debug("Created Response: " + DOMSerializer.createNew().serializeToString(response)); } return response; } catch (Exception ex) { LOG.error("error occured during pdp request evaluation: " + ex, ex); throw ex; } }
/** * Checks the response document for allowed and denied values. * * @param subject * the authentication information * @param doc * Request * @param checkedBaseUrl * check base URL * @param serviceEndPointURL * SOS URL * @return Checked and transformed document. * @throws EnforcementServiceException */ private String tranformResponseDocument(Subject subject, Document doc, String checkedBaseUrl, String serviceEndPointURL) throws EnforcementServiceException { // check for all supported observation types NodeList members = null; if (doc.getDocumentElement().getLocalName().equals(SOSInterceptorGlobals.ELEMENT_OBSERVATION_COLLECTION)) { members = doc.getElementsByTagNameNS("http://www.opengis.net/om/1.0", SOSInterceptorGlobals.ELEMENT_MEMBER); } else { members = doc.getChildNodes(); } // check and restrict procedures doc = checkProcedureInResponse(subject, doc, checkedBaseUrl, serviceEndPointURL, members); // check and check for fois doc = checkFoisInResponse(subject, doc, checkedBaseUrl, serviceEndPointURL, members); return DOMSerializer.createNew().serializeToString(doc); }
public Payload replace(String pOldURL, Transferable res, String pEncoding, String pMimeType) { Document doc = DOMParser.createNew().parse(new InputSource(res.getPayload().getAsStream())); XMLPathCtx ctx = XMLPathCtx.createNew(); NodeList nodes = ctx.findIn(doc).all("//OnlineResource").get(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getParentNode().getParentNode().getLocalName().equals("HTTP")) { String name = node.getParentNode().getLocalName(); node.getParentNode().getParentNode().replaceChild(buildReplacement(name, doc), node.getParentNode()); } } // WMS 1.? // TODO extend XPath for POST nodes: //DCPType/HTTP/*[self::Get // or self::Post]/OnlineResource // WFS 1.1 // TODO extend XPath for POST nodes: // //ows:Operation/ows:DCP/ows:HTTP/*[self::ows:Get or // self::ows:Post] // WFS 1.0 // TODO add XPath for WFS 1.0.0: //DCPType/HTTP/*[self::Get or // self::Post]/@onlineResource DOMSerializer serializer = DOMSerializer.createNew(); String response = serializer.serializeToString(doc); Pattern lPattern = Pattern.compile(pOldURL.replaceAll("\\?", "\\\\?")); Matcher mMatcher = lPattern.matcher(response); response = mMatcher.replaceAll(m_gatekeeperURL); sLogger.debug("Modified ResponseDocument:\n" + response); return new TextualPayload(response, pEncoding); }
private String replaceUsingXPath(final String newURL, String message, String encoding) { // WMS 1.? // TODO extend XPath for POST nodes: //DCPType/HTTP/*[self::Get // or self::Post]/OnlineResource // WFS 1.1 // TODO extend XPath for POST nodes: // //ows:Operation/ows:DCP/ows:HTTP/*[self::ows:Get or // self::ows:Post] // WFS 1.0 // TODO add XPath for WFS 1.0.0: //DCPType/HTTP/*[self::Get or // self::Post]/@onlineResource final org.w3c.dom.Document doc = DOMParser.createNew().parse(new InputSource(new StringReader(message))); new DocumentTraverser().traverseDepthFirst(doc, new DocumentVisitorAdapter() { @Override public void visit(org.w3c.dom.Element element) { element.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", newURL); } public short acceptNode(final Node n) { return isOnlineResourceNode(n) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP; } }); return DOMSerializer.createNew().serializeToString(doc); }
@Override public String referenceAsString() { return DOMSerializer.createNew(DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration()).serializeToString(getReference()); }
public SAML2ResponseMessage insertRelayState(Element relayState) { String relayStateString = DOMSerializer.createNew(DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration()).serializeToString(relayState); return insertRelayState(relayStateString); }
public AttributeValue getInstance(final Node node) throws Exception { return getInstance(DOMSerializer.createNew( DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration()).serializeToString( getFirstChildElement(node))); }
private SAML2ResponseMessage requestAssertion(UsernamePasswordCredential cred, PAOSResponse paosResponse, String idpUrl) throws ServiceException { String authnRequestString = DOMSerializer.createNew( DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration()).serializeToString( paosResponse.getAuthnRequest()); String request = String.format(ASSERTION_SOAP_REQUEST_TEMPLATE, authnRequestString); PostMethod method = new PostMethod(idpUrl); try { SAML2ResponseMessage responseMsg = sendAssertionRequest(cred, request, method); if (method.getStatusCode() == 301 || method.getStatusCode() == 302 || method.getStatusCode() == 303) { responseMsg = requestAssertion(cred, paosResponse, method.getResponseHeader("Location").getValue()); } return responseMsg; } finally { method.releaseConnection(); } }
return DOMSerializer.createNew().serializeToString(document);
.serializeToString(m_requestDocument), ""));
capContent = DOMSerializer.createNew().serializeToString(doc); } else { capContent = tranformCapabilitiesDocument(subject, doc, checkedBaseUrl);
getObsResponse = DOMSerializer.createNew().serializeToString(doc); } else { getObsResponse = tranformResponseDocument(subject, doc, checkedBaseUrl, serviceEndPointURL);
foiResponse = DOMSerializer.createNew().serializeToString(doc); } else { foiResponse = tranformResponseDocument(subject, doc, checkedBaseUrl, serviceEndPointURL);
String capContent = DOMSerializer.createNew().serializeToString(filteredDoc);
return DOMSerializer.createNew().serializeToString(doc);