Example usage for org.w3c.dom Document normalizeDocument

List of usage examples for org.w3c.dom Document normalizeDocument

Introduction

In this page you can find the example usage for org.w3c.dom Document normalizeDocument.

Prototype

public void normalizeDocument();

Source Link

Document

This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.

Usage

From source file:org.ojbc.processor.person.search.PersonSearchRequestProcessor.java

public String invokePersonSearchRequest(PersonSearchRequest personSearchRequest, String federatedQueryID,
        Element samlToken) throws Exception {
    String response = "";
    try {/*w ww.ja v  a 2s .c o  m*/
        if (allowQueriesWithoutSAMLToken) {
            if (samlToken == null) {
                //Add SAML token to request call
                samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
                        "https://idp.ojbc-local.org:9443/idp/shibboleth",
                        SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
                        SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1, true, true, null);

            }
        }

        if (samlToken == null) {
            throw new Exception("No SAML token provided. Unable to perform query.");
        }

        //POJO to XML Request
        Document personSearchRequestPayload = RequestMessageBuilderUtilities
                .createPersonSearchRequest(personSearchRequest);
        personSearchRequestPayload.normalizeDocument();

        //Create exchange
        Exchange senderExchange = new DefaultExchange(camelContext, ExchangePattern.InOnly);

        //Set exchange body to XML Request message
        senderExchange.getIn().setBody(personSearchRequestPayload);

        //Set reply to and WS-Addressing message ID
        senderExchange.getIn().setHeader("federatedQueryRequestGUID", federatedQueryID);
        senderExchange.getIn().setHeader("WSAddressingReplyTo", this.getReplyToAddress());

        //Set the token header so that CXF can retrieve this on the outbound call
        String tokenID = senderExchange.getExchangeId();
        senderExchange.getIn().setHeader("tokenID", tokenID);

        OJBSamlMap.putToken(tokenID, samlToken);

        personSearchMessageProcessor.sendResponseMessage(camelContext, senderExchange);

        //Put message ID and "noResponse" place holder.  
        putRequestInMap(federatedQueryID);

        response = pollMap(federatedQueryID);

        if (response.equals(NO_RESPONSE)) {
            log.debug("Endpoints timed out and no response recieved at web app, create error response");
            response = MergeNotificationErrorProcessor.returnMergeNotificationErrorMessage();
        }

        if (response.length() > 500) {
            log.debug("Here is the response (truncated): " + response.substring(0, 500));
        } else {
            log.debug("Here is the response: " + response);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw (ex);
    }

    //return response here
    return response;

}

From source file:org.ojbc.processor.policy.acknowledge.PolicyAcknowledgmentRecordingRequestProcessor.java

public String invokePolicyAcknowledgementRecordingRequest(String federatedQueryID, Element samlToken)
        throws Exception {
    String response = "";
    try {/*from  ww  w. j  av a2s .  c  o m*/
        if (allowQueriesWithoutSAMLToken) {
            if (samlToken == null) {
                // Add SAML token to request call
                samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
                        "https://idp.ojbc-local.org:9443/idp/shibboleth",
                        SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
                        SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1, true, true, null);

            }
        }

        if (samlToken == null) {
            throw new Exception("No SAML token provided. Unable to perform query.");
        }

        // POJO to XML Request
        Document policyAcknowledgementRecordingRequestDocument = RequestMessageBuilderUtilities
                .createPolicyAcknowledgementRecordingRequest();
        policyAcknowledgementRecordingRequestDocument.normalizeDocument();

        // Create exchange
        Exchange senderExchange = new DefaultExchange(camelContext, ExchangePattern.InOnly);

        // Set exchange body to XML Request message
        senderExchange.getIn().setBody(policyAcknowledgementRecordingRequestDocument);

        // Set reply to and WS-Addressing message ID
        senderExchange.getIn().setHeader("federatedQueryRequestGUID", federatedQueryID);
        senderExchange.getIn().setHeader("WSAddressingReplyTo", this.getReplyToAddress());

        // Set the token header so that CXF can retrieve this on the out
        // bound call
        String tokenID = senderExchange.getExchangeId();
        senderExchange.getIn().setHeader("tokenID", tokenID);

        OJBSamlMap.putToken(tokenID, samlToken);

        messageProcessor.sendResponseMessage(camelContext, senderExchange);

        // Put message ID and "noResponse" place holder.
        putRequestInMap(federatedQueryID);

        response = pollMap(federatedQueryID);

        if (response.equals(NO_RESPONSE)) {
            log.debug("Endpoints timed out and no response recieved at web app, create error response");
            response = MergeNotificationErrorProcessor.returnMergeNotificationErrorMessage();
        }

        if (response.length() > 500) {
            log.debug("Here is the response (truncated): " + response.substring(0, 500));
        } else {
            log.debug("Here is the response: " + response);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
        throw (ex);
    }

    // return response here
    return response;

}

From source file:org.ojbc.processor.policy.query.IdentityBasedAccessControlRequestProcessor.java

public String invokeAccessControlRequest(String federatedQueryID, Element samlToken,
        String requestedResourceURI) {
    String response = null;//www  .  ja  va2  s  . c o  m
    try {
        if (allowQueriesWithoutSAMLToken) {
            if (samlToken == null) {
                // Add SAML token to request call
                samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
                        "https://idp.ojbc-local.org:9443/idp/shibboleth",
                        SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
                        SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1, true, true, null);

            }
        }

        if (samlToken == null) {
            throw new Exception("No SAML token provided. Unable to perform query.");
        }

        // POJO to XML Request
        Document policyBasedAccessControlRequest = RequestMessageBuilderUtilities
                .createPolicyBasedAccessControlRequest(samlToken, requestedResourceURI);
        policyBasedAccessControlRequest.normalizeDocument();

        // Create exchange
        Exchange senderExchange = new DefaultExchange(camelContext, ExchangePattern.InOnly);

        // Set exchange body to XML Request message
        String request = OJBUtils.getStringFromDocument(policyBasedAccessControlRequest);

        senderExchange.getIn().setBody(request);

        // Set reply to and WS-Addressing message ID
        senderExchange.getIn().setHeader("federatedQueryRequestGUID", federatedQueryID);
        senderExchange.getIn().setHeader("WSAddressingReplyTo", this.getReplyToAddress());

        // Set the token header so that CXF can retrieve this on the
        // out bound call
        String tokenID = senderExchange.getExchangeId();
        senderExchange.getIn().setHeader("tokenID", tokenID);

        OJBSamlMap.putToken(tokenID, samlToken);

        messageProcessor.sendResponseMessage(camelContext, senderExchange);

        // Put message ID and "noResponse" place holder.
        putRequestInMap(federatedQueryID);

        response = pollMap(federatedQueryID);

        if (response.equals(NO_RESPONSE)) {
            log.debug("Endpoints timed out and no response recieved at web app, create error response");
            response = MergeNotificationErrorProcessor.returnMergeNotificationErrorMessage();
        }

        if (response.length() > 500) {
            log.debug("Here is the response (truncated): " + response.substring(0, 500));
        } else {
            log.debug("Here is the response: " + response);
        }

    } catch (Exception ex) {
        log.error("Failed to get the Policy Based Access Control Response with federatedQueryID "
                + federatedQueryID + " , and samlTokan "
                + OJBUtils.getStringFromDocument(samlToken.getOwnerDocument()));
    }

    return response;

}

From source file:org.ojbc.processor.vehicle.search.VehicleSearchRequestProcessor.java

@Override
public String invokeVehicleSearchRequest(VehicleSearchRequest vehicleSearchRequest, String federatedQueryID,
        Element samlToken) throws Exception {

    String response = "";

    if (allowQueriesWithoutSAMLToken) {
        if (samlToken == null) {
            //Add SAML token to request call
            samlToken = SAMLTokenUtils.createStaticAssertionAsElement(
                    "https://idp.ojbc-local.org:9443/idp/shibboleth",
                    SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
                    SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1, true, true, null);

        }//from  w  ww . java  2  s.  c om
    }

    if (samlToken == null) {
        throw new Exception("No SAML token provided. Unable to perform query.");
    }

    //POJO to XML Request
    Document personSearchRequestPayload = RequestMessageBuilderUtilities
            .createVehicleSearchRequest(vehicleSearchRequest);
    personSearchRequestPayload.normalizeDocument();

    //Create exchange
    Exchange senderExchange = new DefaultExchange(camelContext, ExchangePattern.InOnly);

    //Set exchange body to XML Request message
    senderExchange.getIn().setBody(personSearchRequestPayload);

    //Set reply to and WS-Addressing message ID
    senderExchange.getIn().setHeader("federatedQueryRequestGUID", federatedQueryID);
    senderExchange.getIn().setHeader("WSAddressingReplyTo", this.getReplyToAddress());

    //Set the token header so that CXF can retrieve this on the outbound call
    String tokenID = senderExchange.getExchangeId();
    senderExchange.getIn().setHeader("tokenID", tokenID);

    OJBSamlMap.putToken(tokenID, samlToken);

    vehicleSearchMessageProcessor.sendResponseMessage(camelContext, senderExchange);

    //Put message ID and "noResponse" place holder.  
    putRequestInMap(federatedQueryID);

    response = pollMap(federatedQueryID);

    if (response.equals(NO_RESPONSE)) {
        log.debug("Endpoints timed out and no response recieved at web app, create error response");
        response = MergeNotificationErrorProcessor.returnMergeNotificationErrorMessage();
    }

    if (response.length() > 500) {
        log.debug("Here is the response (truncated): " + response.substring(0, 500));
    } else {
        log.debug("Here is the response: " + response);
    }

    //return response here
    return response;
}

From source file:org.ojbc.web.model.firearm.search.FirearmSearchRequestTest.java

@Test
public void firearmSearchRequest() throws Exception {
    FirearmSearchRequest fsr = FirearmSearchRequestTestUtils
            .createFirearmSearchRequestModel(SearchFieldMetadata.ExactMatch);

    Assert.assertNotNull(fsr);// w w w.j  ava  2s  .  c  o m

    Document doc = RequestMessageBuilderUtilities.createFirearmSearchRequest(fsr);
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File("src/test/resources/xml/firearmSearchRequest/firearmSearchRequest.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(OJBUtils.getStringFromDocument(doc), expectedResponseAsString);
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}

From source file:org.ojbc.web.model.incident.search.IncidentSearchRequestTest.java

@Test
public void testIncidentSearchRequest() throws Exception {
    IncidentSearchRequest isr = IncidentSearchRequestTestUtils.createIncidentSearchRequestModel();

    Assert.assertNotNull(isr);/*from  w  w  w .  j ava2s .c o  m*/

    Document doc = RequestMessageBuilderUtilities.createIncidentSearchRequest(isr,
            "http://ojbc.org/IEPD/Extensions/DemostateLocationCodes/1.0", "LocationCityTownCode");
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File(
            "src/test/resources/xml/incidentSearchRequest/incidentSearchRequest.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //System.out.println(OJBUtils.getStringFromDocument(doc));

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(expectedResponseAsString, OJBUtils.getStringFromDocument(doc));
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}

From source file:org.ojbc.web.model.incident.search.IncidentSearchRequestTest.java

@Test
public void testIncidentSearchRequestSameDateRange() throws Exception {
    IncidentSearchRequest isr = IncidentSearchRequestTestUtils.createIncidentSearchRequestModelSameDate();

    Assert.assertNotNull(isr);//from w  ww.  ja v  a  2 s  .  c o m

    Document doc = RequestMessageBuilderUtilities.createIncidentSearchRequest(isr,
            "http://ojbc.org/IEPD/Extensions/DemostateLocationCodes/1.0", "LocationCityTownCode");
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File(
            "src/test/resources/xml/incidentSearchRequest/incidentSearchRequestSameDateRange.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //System.out.println(OJBUtils.getStringFromDocument(doc));

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(expectedResponseAsString, OJBUtils.getStringFromDocument(doc));
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}

From source file:org.ojbc.web.model.incident.search.IncidentSearchRequestTest.java

@Test
public void testIncidentSearchRequestOnlyStartDate() throws Exception {
    IncidentSearchRequest isr = IncidentSearchRequestTestUtils.createIncidentSearchRequestModelOnlyStartDate();

    Assert.assertNotNull(isr);//from  ww w  .  j  a va  2  s .c  o  m

    Document doc = RequestMessageBuilderUtilities.createIncidentSearchRequest(isr,
            "http://ojbc.org/IEPD/Extensions/DemostateLocationCodes/1.0", "LocationCityTownCode");
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File(
            "src/test/resources/xml/incidentSearchRequest/incidentSearchRequestOnlyStartDate.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //System.out.println(OJBUtils.getStringFromDocument(doc));

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(expectedResponseAsString, OJBUtils.getStringFromDocument(doc));
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}

From source file:org.ojbc.web.model.person.search.PersonSearchRequestTest.java

@Test
public void testPersonSearchRequest() throws Exception {

    PersonSearchRequest psr = PersonSearchRequestTestUtils.createPersonSearchRequestModel();

    Assert.assertNotNull(psr);//from ww w  . j av a2  s .co  m

    Document doc = RequestMessageBuilderUtilities.createPersonSearchRequest(psr);
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File("src/test/resources/xml/personSearchRequest/personSearchRequest.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(OJBUtils.getStringFromDocument(doc), expectedResponseAsString);
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}

From source file:org.ojbc.web.model.person.search.PersonSearchRequestTest.java

@Test
public void testPersonSearchRequestAbsoluteWeightHeight() throws Exception {

    PersonSearchRequest psr = PersonSearchRequestTestUtils.createPersonSearchRequestModelAbsoluteWeightHeight();

    Assert.assertNotNull(psr);/* ww w.j av  a 2s .  c  om*/

    Document doc = RequestMessageBuilderUtilities.createPersonSearchRequest(psr);
    doc.normalizeDocument();

    log.debug(OJBUtils.getStringFromDocument(doc));

    Assert.assertNotNull(doc);

    //Read the expected response into a string
    File expectedReponseFile = new File(
            "src/test/resources/xml/personSearchRequest/personSearchRequestHeightWeight.xml");
    String expectedResponseAsString = FileUtils.readFileToString(expectedReponseFile);

    //Use XML Unit to compare these files
    Diff myDiff = new Diff(OJBUtils.getStringFromDocument(doc), expectedResponseAsString);
    Assert.assertTrue("XML identical " + myDiff.toString(), myDiff.identical());
}