Ejemplo n.º 1
0
  @Test
  public void subscribeMessageTest() throws Exception {

    Subscription subscription = getSampleSubscriptionPojo();

    Document generatedSubscriptinDoc =
        RequestMessageBuilderUtilities.createSubscriptionRequest(subscription);

    String subQualId =
        XmlUtils.xPathStringSearch(
            generatedSubscriptinDoc,
            "//submsg-ext:SubscriptionQualifierIdentification/nc:IdentificationID");

    String sGeneratedSubscriptionDoc = XmlUtils.getStringFromNode(generatedSubscriptinDoc);

    String sExpectedXmlSubDoc =
        XmlUtils.getRootNodeAsString(
            "src/test/resources/xml/subscriptionRequest/Arrest_Subscription_Document.xml");
    sExpectedXmlSubDoc = sExpectedXmlSubDoc.replace("@SUB_QUAL_ID@", subQualId);

    Diff diff = new Diff(sExpectedXmlSubDoc, sGeneratedSubscriptionDoc);
    DetailedDiff detailDiff = new DetailedDiff(diff);
    List<Difference> diffList = detailDiff.getAllDifferences();
    int diffCount = diffList.size();

    Assert.assertEquals(detailDiff.toString(), 0, diffCount);
  }
  @Override
  public String invokeIncidentSearchRequest(
      IncidentSearchRequest incidentSearchRequest, String federatedQueryID, Element samlToken)
      throws Exception {

    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
    // When multiple operations are supported, we will call the appropriate POJO to XML Method
    Document incidentRequestPayload =
        RequestMessageBuilderUtilities.createIncidentSearchRequest(
            incidentSearchRequest, cityTownCodelistNamespace, cityTownCodelistElementName);

    incidentRequestPayload.normalizeDocument();

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

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

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

    // 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);

    incidentSearchMessageProcessor.sendResponseMessage(camelContext, senderExchange);

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

    String response = pollMap(federatedQueryID);

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

    // This is a defensive check in case the polling completes and the service has not yet returned
    // a response
    // In this case we send back an empty search result
    if (response.equals(NO_RESPONSE)) {
      log.debug("Endpoints timed out and no response recieved at web app, create error response");
      response = MergeNotificationErrorProcessor.returnMergeNotificationErrorMessage();
    }

    // return response here
    return response;
  }