/** * 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); }
public InputStream getStream() { byte[] capsDocAsBytes = DOMSerializer.createNew().serializeToBytes(m_capsDoc); ByteArrayInputStream inputStream = new ByteArrayInputStream(capsDocAsBytes); return inputStream; }
public static DOMSerializer createNew() { return createNew(null); }
/** * Converts the document to a String. * * @throws DOMSerializerException if error occurs. */ public String serializeToString(final Document document) throws DOMSerializerException { return serializeToString((Node) document); }
/** * Serializes the xml document to the writer. * * @throws DOMSerializerException if error occurs. */ public void serialize(final Document document, final Writer out) throws DOMSerializerException { serialize((Node) document, out); }
/** * Converts the document to a byte[]. * * @throws DOMSerializerException if error occurs. */ public byte[] serializeToBytes(final Document document) throws DOMSerializerException { return serializeToBytes((Node) document); }
/** * Serializes the document to the output stream. * * @throws DOMSerializerException if error occurs. */ public void serialize(final Document document, final OutputStream out) throws DOMSerializerException { serialize((Node) document, out); }
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); }
/** * Converts the node to a String. * * @throws DOMSerializerException if error occurs. */ public String serializeToString(final Node node) throws DOMSerializerException { StringWriter writer = new StringWriter(); serialize(node, writer); return writer.toString(); }
/** * 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); }
public ResponseDocument executeRequest(RequestDocument request) throws DecisionProcessingException { Document responseDoc; try { responseDoc = getDecisionServiceAdapter().evaluate((Document) request.getDomNode()); // The commented version is 50 per cent faster but fails with Xalan, // so we convert everything into byte[] :( ByteArrayOutputStream outStream = new ByteArrayOutputStream(); DOMSerializer.createNew().serialize(responseDoc, outStream); //return ResponseDocument.Factory.parse(responseDoc); return ResponseDocument.Factory.parse(new ByteArrayInputStream(outStream.toByteArray())); } catch (Exception e) { throw new DecisionProcessingException("Could not evaluate PolicyRequest.", e); } }
/** * Converts the node to a byte[]. * * @throws DOMSerializerException if error occurs. */ public byte[] serializeToBytes(final Node node) throws DOMSerializerException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); serialize(node, bout); return bout.toByteArray(); }
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(); }
public void handleChunkEnd(final List<QName> currentXPath, final QName handlerQName, final String xmlChunk) { Element request = DOMParser.createNew().parse(new InputSource(new StringReader(xmlChunk))).getDocumentElement(); if (LOG.isDebugEnabled()) { debugPDPRequest(request); } Element response = getDecisionService().evaluate(request); if (request.isDefaultNamespace(PDP_REQUEST_NAME_V2.getNamespaceURI())) { response.setAttribute(XMLConstants.XMLNS_ATTRIBUTE, PDP_REQUEST_NAME_V2.getNamespaceURI()); } if (LOG.isDebugEnabled()) { debugPDPResponse(response); } DOMSerializer.createNew(DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration().encodingUTF8()) .serialize(response, out); }
@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); }
/** * 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 AttributeValue getInstance(final Node node) throws Exception { return getInstance(DOMSerializer.createNew( DOMSerializerOptions.getDefaultOptions().omitXMLDeclaration()).serializeToString( getFirstChildElement(node))); }