private static OMElement loadConfigXML() throws ManagementConfigurationException {

    String carbonHome = System.getProperty(ServerConstants.CARBON_CONFIG_DIR_PATH);
    String path = carbonHome + File.separator + ConfigurationConstants.CEP_MANAGEMENT_XML;

    BufferedInputStream inputStream = null;
    try {
      inputStream = new BufferedInputStream(new FileInputStream(new File(path)));
      XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
      StAXOMBuilder builder = new StAXOMBuilder(parser);
      OMElement omElement = builder.getDocumentElement();
      omElement.build();
      return omElement;
    } catch (FileNotFoundException e) {
      throw new ManagementConfigurationException(
          ConfigurationConstants.CEP_MANAGEMENT_XML + "cannot be found in the path : " + path, e);
    } catch (XMLStreamException e) {
      throw new ManagementConfigurationException(
          "Invalid XML for "
              + ConfigurationConstants.CEP_MANAGEMENT_XML
              + " located in the path : "
              + path,
          e);
    } finally {
      try {
        if (inputStream != null) {
          inputStream.close();
        }
      } catch (IOException e) {
        log.error("Can not shutdown the input stream", e);
      }
    }
  }
  private void increaseSearchIndexStartTimeDelay() throws Exception {
    FileOutputStream fileOutputStream = null;
    XMLStreamWriter writer = null;
    OMElement documentElement = getRegistryXmlOmElement();
    try {
      AXIOMXPath xpathExpression =
          new AXIOMXPath("/wso2registry/indexingConfiguration/startingDelayInSeconds");
      OMElement indexConfigNode = (OMElement) xpathExpression.selectSingleNode(documentElement);
      indexConfigNode.setText("2");

      AXIOMXPath xpathExpression1 =
          new AXIOMXPath("/wso2registry/indexingConfiguration/indexingFrequencyInSeconds");
      OMElement indexConfigNode1 = (OMElement) xpathExpression1.selectSingleNode(documentElement);
      indexConfigNode1.setText("1");

      fileOutputStream = new FileOutputStream(getRegistryXMLPath());
      writer = XMLOutputFactory.newInstance().createXMLStreamWriter(fileOutputStream);
      documentElement.serialize(writer);
      documentElement.build();
      Thread.sleep(2000);

    } catch (Exception e) {
      log.error("registry.xml edit fails" + e.getMessage());
      throw new Exception("registry.xml edit fails" + e.getMessage());
    } finally {
      assert fileOutputStream != null;
      fileOutputStream.close();
      assert writer != null;
      writer.flush();
    }
  }
  public static OMElement read(String filePath) throws FileNotFoundException, XMLStreamException {
    OMElement documentElement = null;
    XMLStreamReader parser = null;
    InputStreamReader in = null;

    try {

      in = new InputStreamReader(new FileInputStream(filePath), Charset.defaultCharset());
      parser = XMLInputFactory.newInstance().createXMLStreamReader(in);
      // create the builder
      StAXOMBuilder builder = new StAXOMBuilder(parser);
      // get the root element
      documentElement = builder.getDocumentElement();
      documentElement.build();
    } finally {
      if (parser != null) {
        parser.close();
      }

      try {
        if (in != null) in.close();
      } catch (IOException e) {
        // ignore
      }
    }
    return documentElement;
  }
  public void registerCepPublisher(OMElement request) throws XMLStreamException {
    request.build();
    request.detach();

    OMElement tenantId =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_TENANT_ID));
    OMElement executionPlan =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_EXEC_PLAN));
    OMElement hostName =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_HOST_NAME));
    OMElement port =
        request.getFirstChildWithName(
            new QName(ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_PORT));

    String key = getKey(executionPlan.getText(), tenantId.getText());
    int portNumber = Integer.parseInt(port.getText());
    insertToCollection(
        cepPublishers,
        key,
        new Endpoint(portNumber, hostName.getText(), Endpoint.ENDPOINT_TYPE_CEP_PUBLISHER));
    log.info(
        "Registering CEP Publisher for "
            + key
            + " at "
            + hostName.getText()
            + ":"
            + port.getText());
  }
 public static OMElement buildOMElement(String payload) throws RegistryException {
   OMElement element;
   try {
     element = AXIOMUtil.stringToOM(payload);
     element.build();
   } catch (Exception e) {
     String message =
         "Unable to parse the XML configuration. Please validate the XML configuration";
     log.error(message, e);
     throw new RegistryException(message, e);
   }
   return element;
 }
  public OMElement getCEPPublisher(OMElement request) throws XMLStreamException {
    request.build();
    request.detach();

    OMElement tenantId =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_TENANT_ID));
    OMElement executionPlan =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_EXEC_PLAN));
    OMElement requesterIp =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_REQUESTER_IP));
    String key = getKey(executionPlan.getText(), tenantId.getText());
    log.info("CEP Publisher requested for  " + key);

    Set<Endpoint> endpointSet = cepPublishers.get(key);
    Endpoint selectedEndpoint = selectEndpoint(endpointSet, requesterIp.getText());
    OMElement response =
        factory.createOMElement(
            ManagerServiceConstants.ELEMENT_CEP_PUBLISHER_RESPONSE, OMNamespace);
    if (selectedEndpoint != null) {
      OMElement hostNameElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_HOST_NAME, OMNamespace);
      OMElement portElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_PORT, OMNamespace);

      OMText hostNameText = factory.createOMText(hostNameElement, selectedEndpoint.getHostName());
      OMText portText =
          factory.createOMText(portElement, Integer.toString(selectedEndpoint.getPort()));

      hostNameElement.addChild(hostNameText);
      portElement.addChild(portText);
      response.addChild(hostNameElement);
      response.addChild(portElement);
      log.info(
          "Returning CEP Publisher:"
              + selectedEndpoint.getHostName()
              + ":"
              + selectedEndpoint.getPort());
    } else {
      log.warn("No CEP publishers registered " + key);
    }

    return response;
  }
  public void testOMNS() {
    try {
      StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(originalXML.getBytes()));
      OMElement documentElement = builder.getDocumentElement();
      // assertXMLEqual(originalXML, documentElement.toString());
      documentElement.build();

      String outstr = documentElement.toString();
      assertTrue(outstr.indexOf("xmlns:saml=") > 0);
      assertTrue(outstr.indexOf("<Assertion") == 0);

    } catch (XMLStreamException e) {
      e.printStackTrace();
    }
  }
Beispiel #8
0
 public OMParser(OMElement element) {
   _element = element;
   _element.build();
   if (_element.getParent() != null) _element.detach();
 }
Beispiel #9
0
 /**
  * @param sor
  * @return
  */
 public OMElement run(OMElement sor) {
   try {
     sor.build();
     // AUDIT:POINT
     // call to audit message for document registry
     // for Transaction id = ITI-42. (Register Document set-b)
     // NOTE!!: Moved above "SubjectObjectsRequestInternal()" method call since the "sor" instance
     // is changed during the execution of "SubjectObjectsRequestInternal() method.  Otherwise,
     // we would need to pay the penalty for a deep copy of the "sor" instance.
     this.auditSubmitObjectsRequest(sor);
     // performAudit(
     //        XATNALogger.TXN_ITI42,
     //        sor,
     //        null,
     //        XATNALogger.ActorType.REGISTRY,
     //        XATNALogger.OutcomeIndicator.SUCCESS);
     this.handleSubmitObjectsRequest(sor);
   } catch (XdsDeprecatedException e) {
     response.add_error(
         "XDSRegistryDeprecatedDocumentError",
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (XdsUnknownPatientIdException e) {
     response.add_error(
         MetadataSupport.XDSUnknownPatientId,
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (XdsPatientIdDoesNotMatchException e) {
     response.add_error(
         MetadataSupport.XDSPatientIdDoesNotMatch,
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (XDSNonIdenticalHashException e) {
     response.add_error(
         MetadataSupport.XDSNonIdenticalHash,
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (MetadataException e) {
     response.add_error(
         MetadataSupport.XDSRegistryMetadataError,
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (MetadataValidationException e) {
     response.add_error(
         MetadataSupport.XDSRegistryMetadataError,
         e.getMessage(),
         this.getClass().getName(),
         log_message);
     logger.warn(logger_exception_details(e));
   } catch (XdsInternalException e) {
     response.add_error(
         MetadataSupport.XDSRegistryError, e.getMessage(), this.getClass().getName(), log_message);
     logger.warn(logger_exception_details(e));
   } catch (XdsException e) {
     response.add_error(
         MetadataSupport.XDSRegistryError, e.getMessage(), this.getClass().getName(), log_message);
     logger.warn(logger_exception_details(e));
   } catch (Exception e) {
     response.add_error(
         MetadataSupport.XDSRegistryError, e.getMessage(), this.getClass().getName(), log_message);
     logger.warn(logger_exception_details(e));
   }
   OMElement res = null;
   try {
     res = response.getResponse();
     this.log_response();
   } catch (XdsInternalException e) {
   }
   return res;
 }
 private static OMElement buildResponse(OMElement omElement) {
   omElement.build();
   return omElement;
 }
Beispiel #11
0
  /**
   * Creates a DOM Document using the SOAP Envelope.
   *
   * @param env An org.apache.axiom.soap.SOAPEnvelope instance
   * @return Returns the DOM Document of the given SOAP Envelope.
   * @throws Exception
   */
  public static Document getDocumentFromSOAPEnvelope(SOAPEnvelope env, boolean useDoom)
      throws WSSecurityException {
    try {
      if (env instanceof Element) {
        return ((Element) env).getOwnerDocument();
      }

      if (useDoom) {
        env.build();

        // Workaround to prevent a bug in AXIOM where
        // there can be an incomplete OMElement as the first child body
        OMElement firstElement = env.getBody().getFirstElement();
        if (firstElement != null) {
          firstElement.build();
        }

        // Get processed headers
        SOAPHeader soapHeader = env.getHeader();
        ArrayList processedHeaderQNames = new ArrayList();
        if (soapHeader != null) {
          Iterator headerBlocs = soapHeader.getChildElements();
          while (headerBlocs.hasNext()) {
            SOAPHeaderBlock element = (SOAPHeaderBlock) headerBlocs.next();
            if (element.isProcessed()) {
              processedHeaderQNames.add(element.getQName());
            }
          }
        }

        // Check the namespace and find SOAP version and factory
        String nsURI = null;
        SOAPFactory factory;
        if (env.getNamespace()
            .getNamespaceURI()
            .equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
          nsURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
          factory = DOOMAbstractFactory.getSOAP11Factory();
        } else {
          nsURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
          factory = DOOMAbstractFactory.getSOAP12Factory();
        }

        StAXSOAPModelBuilder stAXSOAPModelBuilder =
            new StAXSOAPModelBuilder(env.getXMLStreamReader(), factory, nsURI);
        SOAPEnvelope envelope = (stAXSOAPModelBuilder).getSOAPEnvelope();
        ((OMNode) envelope.getParent()).build();

        // Set the processed flag of the processed headers
        SOAPHeader header = envelope.getHeader();
        for (Iterator iter = processedHeaderQNames.iterator(); iter.hasNext(); ) {
          QName name = (QName) iter.next();
          Iterator omKids = header.getChildrenWithName(name);
          if (omKids.hasNext()) {
            ((SOAPHeaderBlock) omKids.next()).setProcessed();
          }
        }

        Element envElem = (Element) envelope;
        return envElem.getOwnerDocument();
      } else {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        env.build();
        env.serialize(baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        return factory.newDocumentBuilder().parse(bais);
      }
    } catch (Exception e) {
      throw new WSSecurityException("Error in converting SOAP Envelope to Document", e);
    }
  }
Beispiel #12
0
 /**
  * This will build a DOOM Element that is of the same <code>Document</code>
  *
  * @param factory
  * @param element
  * @return
  */
 public static OMElement toDOOM(OMFactory factory, OMElement element) {
   StAXOMBuilder builder = new StAXOMBuilder(factory, element.getXMLStreamReader());
   OMElement elem = builder.getDocumentElement();
   elem.build();
   return elem;
 }
Beispiel #13
0
 /**
  * Creates a new OMElement from the given element and build it and return.
  *
  * @param result The object to be cloned and built
  * @return The new cloned and built OMElement
  */
 public static OMElement cloneAndReturnBuiltElement(OMElement result) {
   StAXOMBuilder builder = new StAXOMBuilder(result.getXMLStreamReaderWithoutCaching());
   result = builder.getDocumentElement();
   result.build();
   return result;
 }