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 boolean getIfSSLOnly() {

    if (sslOnly != null) {
      return sslOnly;
    }

    try {
      File confFile = new File(getQpidHome() + ANDES_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement connectorNode =
          docRootNode.getFirstChildWithName(new QName(QPID_CONF_CONNECTOR_NODE));
      OMElement sslNode = connectorNode.getFirstChildWithName(new QName(QPID_CONF_SSL_NODE));
      OMElement sslOnlyNode = sslNode.getFirstChildWithName(new QName(QPID_CONF_SSL_ONLY_NODE));

      sslOnly = Boolean.parseBoolean(sslOnlyNode.getText());

    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    return sslOnly;
  }
예제 #3
0
  public static Query fromOM(OMElement queryElement) {
    Query query = new Query();
    String name =
        queryElement.getAttribute(new QName(CEPConstants.CEP_CONF_ATTR_NAME)).getAttributeValue();
    query.setName(name);

    Iterator iterator = queryElement.getChildrenWithName(new QName(CEPConstants.CEP_CONF_QUERY_IP));

    while (iterator != null && iterator.hasNext()) {
      OMElement ipElement = (OMElement) iterator.next();
      String ip = ipElement.getText();
      query.addIP(ip);
    }

    OMElement expressionElement =
        queryElement.getFirstChildWithName(
            new QName(CEPConstants.CEP_CONF_NAMESPACE, CEPConstants.CEP_CONF_ELE_EXPRESSION));
    if (expressionElement != null) {
      query.setExpression(ExpressionHelper.fromOM(expressionElement));
    }

    OMElement outputOmElement =
        queryElement.getFirstChildWithName(
            new QName(CEPConstants.CEP_CONF_NAMESPACE, CEPConstants.CEP_CONF_ELE_OUTPUT));
    if (expressionElement != null && outputOmElement != null) {
      query.setOutput(OutputHelper.fromOM(outputOmElement));
    }
    return query;
  }
  @Override
  public String getCassandraConnectionString() {

    if (cassandraConnection != null) {
      return cassandraConnection.trim();
    }
    try {
      File confFile = new File(getQpidHome() + ANDES_VIRTUALHOST_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement virtualHostNode =
          docRootNode.getFirstChildWithName(new QName(QPID_VIRTUALHOST_NODE));
      OMElement virtualHostNameNode =
          virtualHostNode.getFirstChildWithName(new QName(QPID_VIRTUALHOST_NAME_NODE));
      String virtualHostName = virtualHostNameNode.getText();
      OMElement carbonVirtualHost =
          virtualHostNode.getFirstChildWithName(new QName(virtualHostName));
      OMElement storeElem =
          carbonVirtualHost.getFirstChildWithName(new QName(QPID_VIRTUALHOST_STORE_NODE));
      OMElement connectionStr =
          storeElem.getFirstChildWithName(new QName(QPID_VIRTUALHOST_STORE_CONNECTION_STRING_NODE));

      cassandraConnection = connectionStr.getText();
    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    return ((cassandraConnection != null) ? cassandraConnection.trim() : "");
  }
  @Override
  public String getZookeeperConnectionString() {

    if (zkConnection != null) {
      return zkConnection.trim();
    }

    try {
      File confFile = new File(getQpidHome() + ANDES_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement clusteringNode =
          docRootNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_NODE));
      OMElement coordinationNode =
          clusteringNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_COORDINATION_NODE));
      OMElement zkConnectionNode =
          coordinationNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_ZK_CONNECTION_NODE));

      zkConnection = zkConnectionNode.getText();
    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    return (zkConnection != null) ? zkConnection.trim() : "";
  }
  private boolean readClusterEnabledDisabledStatusFromQpidConfig() {
    String enabled = "";

    try {
      File confFile = new File(getQpidHome() + ANDES_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement clusteringNode =
          docRootNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_NODE));
      OMElement enabledNode =
          clusteringNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_ENABLE_NODE));

      if (enabledNode == null) {
        return false;
      }
      enabled = enabledNode.getText();
    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    if ("true".equals(enabled)) {
      return true;
    }

    return false;
  }
  private boolean readCassandraServerRequirementStatusFromQpidConfig() {
    String required = "";

    try {
      File confFile = new File(getQpidHome() + ANDES_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement clusteringNode =
          docRootNode.getFirstChildWithName(new QName(QPID_CONF_CLUSTER_NODE));
      OMElement statusNode =
          clusteringNode.getFirstChildWithName(new QName(QPID_CONF_EXTERNAL_CASSANDRA_SERVER));
      if (statusNode == null) {
        return false;
      }
      required = statusNode.getText();
    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    if ("true".equals(required)) {
      return true;
    }

    return false;
  }
  /**
   *
   *
   * <pre>
   * <loadBalancerConfig xmlns="http://ws.apache.org/ns/synapse">
   * <property name="ec2PrivateKey" value="/mnt/payload/pk.pem"/>
   * <property name="ec2Cert" value="/mnt/payload/cert.pem"/>
   * <property name="sshKey" value="stratos-1.0.0-keypair"/>
   * <property name="instanceMgtEPR" value="https://ec2.amazonaws.com/"/>
   * <property name="disableApiTermination" value="true"/>
   * <property name="enableMonitoring" value="true"/>
   * <loadBalancer>
   * <property name="securityGroups" value="stratos-appserver-lb"/>
   * <property name="instanceType" value="m1.large"/>
   * <property name="instances" value="1"/>
   * <property name="elasticIP" value="${ELASTIC_IP}"/>
   * <property name="availabilityZone" value="us-east-1c"/>
   * <property name="payload" value="/mnt/payload.zip"/>
   * </loadBalancer>
   * <p/>
   * <services>
   * <defaults>
   * <property name="payload" value="resources/cluster_node.zip"/>
   * <property name="availabilityZone" value="us-east-1c"/>
   * <property name="securityGroups" value="default-2011-02-23"/>
   * <property name="instanceType" value="m1.large"/>
   * <property name="minAppInstances" value="1"/>
   * <property name="maxAppInstances" value="5"/>
   * <property name="queueLengthPerNode" value="400"/>
   * <property name="roundsToAverage" value="10"/>
   * <property name="instancesPerScaleUp" value="1"/>
   * <property name="messageExpiryTime" value="60000"/>
   * <property name="preserveOldestInstance" value="true"/>
   * </defaults>
   * <service>
   * <hosts>
   * <host>cloud-test.wso2.com</host>
   * </hosts>
   * <domain>wso2.manager.domain</domain>
   * </service>
   * <service>
   * <hosts>
   * <host>appserver.cloud-test.wso2.com</host>
   * <host>as.cloud-test.wso2.com</host>
   * </hosts>
   * <domain>wso2.as.domain</domain>
   * <p/>
   * <property name="payload" value="resources/cluster_node.zip"/>
   * <property name="availabilityZone" value="us-east-1c"/>
   * </service>
   * <service>
   * <hosts>
   * <host>esb.cloud-test.wso2.com</host>
   * </hosts>
   * <domain>wso2.esb.domain</domain>
   * <p/>
   * <property name="payload" value="resources/cluster_node.zip"/>
   * <property name="minAppInstances" value="1"/>
   * <property name="maxAppInstances" value="5"/>
   * <property name="queueLengthPerNode" value="400"/>
   * <property name="roundsToAverage" value="10"/>
   * <property name="instancesPerScaleUp" value="1"/>
   * <property name="availabilityZone" value="us-east-1c"/>
   * <property name="securityGroups" value="ds-2011-02-23"/>
   * </service>
   * <service>
   * <hosts>
   * <host>governance.cloud-test.wso2.com</host>
   * </hosts>
   * <domain>wso2.governance.domain</domain>
   * </service>
   * <service>
   * <hosts>
   * <host>identity.cloud-test.wso2.com</host>
   * </hosts>
   * <domain>wso2.is.domain</domain>
   * </service>
   * </services>
   * </loadBalancerConfig>
   * </pre>
   *
   * @param configURL URL of the load balancer config
   */
  public void init(String configURL) {
    if (configURL.startsWith("$system:")) {
      configURL = System.getProperty(configURL.substring("$system:".length()));
    }
    StAXOMBuilder builder;
    try {
      builder = new StAXOMBuilder(new URL(configURL).openStream());
    } catch (Exception e) {
      throw new RuntimeException("Cannot read configuration file from URL " + configURL);
    }
    OMElement loadBalancerConfigEle = builder.getDocumentElement();

    // Set all properties
    try {
      for (Iterator<OMElement> iter = loadBalancerConfigEle.getChildrenWithLocalName("property");
          iter.hasNext(); ) {
        setProperty(this, iter.next());
      }
    } catch (Exception e) {
      throw new RuntimeException("Error setting values to " + this.getClass().getName(), e);
    }

    // Set load balancer config
    OMElement loadBalancerEle =
        loadBalancerConfigEle.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "loadBalancer"));
    createLoadBalancerConfig(loadBalancerEle);

    // Set services config
    OMElement servicesEle =
        loadBalancerConfigEle.getFirstChildWithName(
            new QName(SynapseConstants.SYNAPSE_NAMESPACE, "services"));
    createServicesConfig(servicesEle);
  }
 private void populateGetRequestProcessors() throws AxisFault {
   try {
     OMElement docEle = XMLUtils.toOM(ServerConfiguration.getInstance().getDocumentElement());
     if (docEle != null) {
       SimpleNamespaceContext nsCtx = new SimpleNamespaceContext();
       nsCtx.addNamespace("wsas", ServerConstants.CARBON_SERVER_XML_NAMESPACE);
       XPath xp = new AXIOMXPath("//wsas:HttpGetRequestProcessors/wsas:Processor");
       xp.setNamespaceContext(nsCtx);
       List nodeList = xp.selectNodes(docEle);
       for (Object aNodeList : nodeList) {
         OMElement processorEle = (OMElement) aNodeList;
         OMElement itemEle = processorEle.getFirstChildWithName(ITEM_QN);
         if (itemEle == null) {
           throw new ServletException("Required element, 'Item' not found!");
         }
         OMElement classEle = processorEle.getFirstChildWithName(CLASS_QN);
         org.wso2.carbon.core.transports.HttpGetRequestProcessor processor;
         if (classEle == null) {
           throw new ServletException("Required element, 'Class' not found!");
         } else {
           processor =
               (org.wso2.carbon.core.transports.HttpGetRequestProcessor)
                   Class.forName(classEle.getText().trim()).newInstance();
         }
         getRequestProcessors.put(itemEle.getText().trim(), processor);
       }
     }
   } catch (Exception e) {
     handleException("Error populating GetRequestProcessors", e);
   }
 }
예제 #10
0
  protected static Pair<Filter, ConstraintLanguage> parseConstraint(
      XMLAdapter adapter, OMElement omQueryElement) {
    Pair<Filter, ConstraintLanguage> pc = null;
    if (omQueryElement != null
        && new QName(CSWConstants.CSW_202_NS, "Constraint").equals(omQueryElement.getQName())) {
      Version versionConstraint =
          adapter.getRequiredNodeAsVersion(omQueryElement, new XPath("@version", nsContext));

      OMElement filterEl = omQueryElement.getFirstChildWithName(new QName(OGCNS, "Filter"));
      OMElement cqlTextEl = omQueryElement.getFirstChildWithName(new QName("", "CQLTEXT"));
      if ((filterEl != null) && (cqlTextEl == null)) {

        ConstraintLanguage constraintLanguage = ConstraintLanguage.FILTER;
        Filter constraint;
        try {
          // TODO remove usage of wrapper (necessary at the moment to work around problems
          // with AXIOM's

          XMLStreamReader xmlStream =
              new XMLStreamReaderWrapper(filterEl.getXMLStreamReaderWithoutCaching(), null);
          // skip START_DOCUMENT
          xmlStream.nextTag();

          if (versionConstraint.equals(new Version(1, 1, 0))) {

            constraint = Filter110XMLDecoder.parse(xmlStream);

          } else if (versionConstraint.equals(new Version(1, 0, 0))) {
            constraint = Filter100XMLDecoder.parse(xmlStream);
          } else {
            String msg =
                Messages.get(
                    "CSW_FILTER_VERSION_NOT_SPECIFIED",
                    versionConstraint,
                    Version.getVersionsString(new Version(1, 1, 0)),
                    Version.getVersionsString(new Version(1, 0, 0)));
            LOG.info(msg);
            throw new InvalidParameterValueException(msg);
          }
        } catch (XMLStreamException e) {
          String msg =
              "FilterParsingException: There went something wrong while parsing the filter expression, so please check this!";
          LOG.debug(msg);
          throw new XMLParsingException(adapter, filterEl, e.getMessage());
        }
        pc = new Pair<Filter, CSWConstants.ConstraintLanguage>(constraint, constraintLanguage);
      } else if ((filterEl == null) && (cqlTextEl != null)) {
        String msg = Messages.get("CSW_UNSUPPORTED_CQL_FILTER");
        LOG.info(msg);
        throw new NotImplementedError(msg);
      } else {
        String msg = Messages.get("CSW_MISSING_FILTER_OR_CQL");
        LOG.debug(msg);
        throw new InvalidParameterValueException(msg);
      }
    }
    return pc;
  }
예제 #11
0
 private static OMElement getSAMLToken(OMElement resp) {
   OMElement rst =
       resp.getFirstChildWithName(
           new QName(
               RahasConstants.WST_NS_05_02,
               RahasConstants.IssuanceBindingLocalNames.REQUESTED_SECURITY_TOKEN));
   OMElement elem = rst.getFirstChildWithName(new QName(SAMLConstants.SAML20_NS, "Assertion"));
   return elem;
 }
예제 #12
0
 public static OMElement getChildWithName(OMElement head, String widgetName, String namespace) {
   String adjustedName = getDataElementName(widgetName);
   if (adjustedName == null) {
     return null;
   }
   OMElement child = head.getFirstChildWithName(new QName(namespace, adjustedName));
   if (child == null) {
     // this piece of code is for the backward compatibility
     child = head.getFirstChildWithName(new QName(null, widgetName.replaceAll(" ", "-")));
   }
   return child;
 }
예제 #13
0
 public static String getNameFromContent(OMElement head) {
   OMElement overview = head.getFirstChildWithName(new QName("Overview"));
   if (overview != null) {
     return overview.getFirstChildWithName(new QName("Name")).getText();
   }
   overview =
       head.getFirstChildWithName(new QName(UIGeneratorConstants.DATA_NAMESPACE, "overview"));
   if (overview != null) {
     return overview
         .getFirstChildWithName(new QName(UIGeneratorConstants.DATA_NAMESPACE, "name"))
         .getText();
   }
   return null;
 }
  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 static OutputMapping fromOM(OMElement mappingElement)
      throws EventPublisherConfigurationException {

    JSONOutputMapping jsonOutputMapping = new JSONOutputMapping();

    String customMappingEnabled =
        mappingElement.getAttributeValue(new QName(EventPublisherConstants.EF_ATTR_CUSTOM_MAPPING));
    if (customMappingEnabled == null
        || (customMappingEnabled.equals(EventPublisherConstants.ENABLE_CONST))) {
      jsonOutputMapping.setCustomMappingEnabled(true);
      if (!validateJsonEventMapping(mappingElement)) {
        throw new EventPublisherConfigurationException(
            "JSON Mapping is not valid, check the output mapping");
      }

      OMElement innerMappingElement =
          mappingElement.getFirstChildWithName(
              new QName(
                  EventPublisherConstants.EF_CONF_NS,
                  EventPublisherConstants.EF_ELE_MAPPING_INLINE));
      if (innerMappingElement != null) {
        jsonOutputMapping.setRegistryResource(false);
      } else {
        innerMappingElement =
            mappingElement.getFirstChildWithName(
                new QName(
                    EventPublisherConstants.EF_CONF_NS,
                    EventPublisherConstants.EF_ELE_MAPPING_REGISTRY));
        if (innerMappingElement != null) {
          jsonOutputMapping.setRegistryResource(true);
        } else {
          throw new EventPublisherConfigurationException(
              "XML Mapping is not valid, Mapping should be inline or from registry");
        }
      }

      if (innerMappingElement.getText() == null || innerMappingElement.getText().trim().isEmpty()) {
        throw new EventPublisherConfigurationException("There is no any mapping content available");

      } else {
        jsonOutputMapping.setMappingText(innerMappingElement.getText());
      }

    } else {
      jsonOutputMapping.setCustomMappingEnabled(false);
    }

    return jsonOutputMapping;
  }
예제 #16
0
 public Property[] getProperties(QName parameter) throws IllegalArgumentException {
   OMElement e = _element.getFirstChildWithName(parameter);
   if (e == null) throw new IllegalArgumentException("Missing properties parameter: " + parameter);
   Iterator<OMElement> iter = e.getChildElements();
   ArrayList<Property> props = new ArrayList<Property>();
   while (iter.hasNext()) {
     OMElement prop = iter.next();
     OMElement name = prop.getFirstChildWithName(Constants.NAME);
     if (name == null) throw new IllegalArgumentException("Missing property name: " + prop);
     OMElement value = prop.getFirstChildWithName(Constants.VALUE);
     if (value == null) throw new IllegalArgumentException("Missing property value: " + prop);
     props.add(new Property(name.getText(), value.getText()));
   }
   return props.toArray(new Property[props.size()]);
 }
  public RealmConfiguration buildRealmConfiguration(InputStream inStream)
      throws UserStoreException {
    OMElement realmElement;
    try {
      inStream = CarbonUtils.replaceSystemVariablesInXml(inStream);
      StAXOMBuilder builder = new StAXOMBuilder(inStream);
      OMElement documentElement = builder.getDocumentElement();

      realmElement =
          documentElement.getFirstChildWithName(
              new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_REALM));

      RealmConfiguration realmConfig = buildRealmConfiguration(realmElement);

      if (inStream != null) {
        inStream.close();
      }
      return realmConfig;
    } catch (RuntimeException e) {
      String message = "An unexpected error occurred while building the realm configuration.";
      log.error(message, e);
      throw new UserStoreException(message, e);
    } catch (Exception e) {
      String message = "Error while reading realm configuration from file";
      log.error(message, e);
      throw new UserStoreException(message, e);
    }
  }
예제 #18
0
  /**
   * Creates endpoint element for REST service
   *
   * @param requestContext information about current request.
   * @param wadlElement wadl document.
   * @param version wadl version.
   * @return Endpoint Path.
   * @throws RegistryException If fails to create endpoint element.
   */
  private String createEndpointElement(
      RequestContext requestContext, OMElement wadlElement, String version)
      throws RegistryException {
    OMNamespace wadlNamespace = wadlElement.getNamespace();
    String wadlNamespaceURI = wadlNamespace.getNamespaceURI();
    String wadlNamespacePrefix = wadlNamespace.getPrefix();
    OMElement resourcesElement =
        wadlElement.getFirstChildWithName(
            new QName(wadlNamespaceURI, "resources", wadlNamespacePrefix));
    if (resourcesElement != null) {
      String endpointUrl = resourcesElement.getAttributeValue(new QName("base"));
      if (endpointUrl != null) {
        String endpointPath = EndpointUtils.deriveEndpointFromUrl(endpointUrl);
        String endpointName = EndpointUtils.deriveEndpointNameFromUrl(endpointUrl);
        String endpointContent =
            EndpointUtils.getEndpointContentWithOverview(
                endpointUrl, endpointPath, endpointName, version);
        OMElement endpointElement;
        try {
          endpointElement = AXIOMUtil.stringToOM(endpointContent);
        } catch (XMLStreamException e) {
          throw new RegistryException("Error in creating the endpoint element. ", e);
        }

        return RESTServiceUtils.addEndpointToRegistry(
            requestContext, endpointElement, endpointPath);
      } else {
        log.warn("Base path does not exist. endpoint creation may fail. ");
      }
    } else {
      log.warn("Resources element is null. ");
    }
    return null;
  }
예제 #19
0
 private void processKeyStoreElement(
     OMElement bamServerConfig, BAMServerProfile bamServerProfile) {
   OMElement keyStoreElement =
       bamServerConfig.getFirstChildWithName(
           new QName(BPELConstants.BAM_SERVER_PROFILE_NS, "KeyStore"));
   if (keyStoreElement != null) {
     OMAttribute locationAttr = keyStoreElement.getAttribute(new QName("location"));
     OMAttribute passwordAttr = keyStoreElement.getAttribute(new QName("password"));
     if (locationAttr != null
         && passwordAttr != null
         && !locationAttr.getAttributeValue().equals("")
         && !passwordAttr.getAttributeValue().equals("")) {
       bamServerProfile.setKeyStoreLocation(locationAttr.getAttributeValue());
       bamServerProfile.setKeyStorePassword(passwordAttr.getAttributeValue());
     } else {
       String errMsg =
           "Key store details location or password not found for BAM "
               + "server profile: "
               + profileLocation;
       handleError(errMsg);
     }
   } else {
     String errMsg = "Key store element not found for BAM server profile: " + profileLocation;
     handleError(errMsg);
   }
 }
예제 #20
0
 private void processCredentialElement(
     OMElement bamServerConfig, BAMServerProfile bamServerProfile) throws CryptoException {
   OMElement credentialElement =
       bamServerConfig.getFirstChildWithName(
           new QName(BPELConstants.BAM_SERVER_PROFILE_NS, "Credential"));
   if (credentialElement != null) {
     OMAttribute userNameAttr = credentialElement.getAttribute(new QName("userName"));
     OMAttribute passwordAttr = credentialElement.getAttribute(new QName("password"));
     // OMAttribute secureAttr = credentialElement.getAttribute(new QName("secure"));
     if (userNameAttr != null
         && passwordAttr != null
         && /*secureAttr != null &&*/ !userNameAttr.getAttributeValue().equals("")
         && !passwordAttr.getAttributeValue().equals("")
     /*&& !secureAttr.getAttributeValue().equals("")*/ ) {
       bamServerProfile.setUserName(userNameAttr.getAttributeValue());
       bamServerProfile.setPassword(
           new String(
               CryptoUtil.getDefaultCryptoUtil()
                   .base64DecodeAndDecrypt(passwordAttr.getAttributeValue())));
     } else {
       String errMsg = "Username or Password not found for BAM server profile: " + profileLocation;
       handleError(errMsg);
     }
   } else {
     String errMsg = "Credentials not found for BAM server profile: " + profileLocation;
     handleError(errMsg);
   }
 }
예제 #21
0
  /**
   * Make sure that the endpoints created by the factory has a name
   *
   * @param epConfig OMElement containing the endpoint configuration.
   * @param anonymousEndpoint false if the endpoint has a name. true otherwise.
   * @param properties bag of properties to pass in any information to the factory
   * @return Endpoint implementation for the given configuration.
   */
  private Endpoint createEndpointWithName(
      OMElement epConfig, boolean anonymousEndpoint, Properties properties) {

    Endpoint ep = createEndpoint(epConfig, anonymousEndpoint, properties);
    OMElement descriptionElem = epConfig.getFirstChildWithName(DESCRIPTION_Q);
    if (descriptionElem != null) {
      ep.setDescription(descriptionElem.getText());
    }

    // if the endpoint doesn't have a name we will generate a unique name.
    if (anonymousEndpoint && ep.getName() == null) {
      String uuid = UIDGenerator.generateUID();
      uuid = uuid.replace(':', '_');
      ep.setName(ENDPOINT_NAME_PREFIX + uuid);
      if (ep instanceof AbstractEndpoint) {
        ((AbstractEndpoint) ep).setAnonymous(true);
      }
    }

    OMAttribute onFaultAtt = epConfig.getAttribute(ON_FAULT_Q);
    if (onFaultAtt != null) {
      ep.setErrorHandler(onFaultAtt.getAttributeValue());
    }
    return ep;
  }
 public static String readOMElementValue(OMElement parentElement, String elementName) {
   OMElement element = parentElement.getFirstChildWithName(new QName(elementName));
   String elementValue = null;
   if (!element.getText().trim().isEmpty()) {
     elementValue = element.getText();
   }
   return elementValue;
 }
예제 #23
0
파일: Utils.java 프로젝트: Johanes/platform
  public static void readConfigFile() {

    InputStream in;
    try {
      String configFilePath =
          CarbonUtils.getCarbonConfigDirPath()
              + File.separator
              + "advanced"
              + File.separator
              + STREAMDEFN_XML;
      in = FileUtils.openInputStream(new File(configFilePath));
    } catch (Exception e) {
      in = Utils.class.getClassLoader().getResourceAsStream(STREAMDEFN_XML);
    }

    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(in);

    OMElement documentElement = builder.getDocumentElement();

    OMElement replicationFactorEl =
        documentElement.getFirstChildWithName(new QName("ReplicationFactor"));
    if (replicationFactorEl != null) {
      replicationFactor = Integer.parseInt(replicationFactorEl.getText());
    }

    OMElement readLevelEl =
        documentElement.getFirstChildWithName(new QName("ReadConsistencyLevel"));
    if (replicationFactorEl != null) {
      readConsistencyLevel = readLevelEl.getText();
    }

    OMElement writeLevelEl =
        documentElement.getFirstChildWithName(new QName("WriteConsistencyLevel"));
    if (writeLevelEl != null) {
      writeConsistencyLevel = writeLevelEl.getText();
    }

    globalConsistencyLevelPolicy =
        new StreamDefnConsistencyLevelPolicy(readConsistencyLevel, writeConsistencyLevel);

    OMElement strategyEl = documentElement.getFirstChildWithName(new QName("StrategyClass"));
    if (strategyEl != null) {
      strategyClass = strategyEl.getText();
    }
  }
예제 #24
0
  /**
   * This static method will be used to build the Target from the specified element
   *
   * @param elem - OMElement describing the xml configuration of the target
   * @return Target built by parsing the given element
   */
  public static Target createTarget(OMElement elem) {

    if (!TARGET_Q.equals(elem.getQName())) {
      handleException("Element does not match with the target QName");
    }

    Target target = new Target();
    OMAttribute toAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "to"));
    if (toAttr != null && toAttr.getAttributeValue() != null) {
      target.setToAddress(toAttr.getAttributeValue());
    }

    OMAttribute soapAction =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "soapAction"));
    if (soapAction != null && soapAction.getAttributeValue() != null) {
      target.setSoapAction(soapAction.getAttributeValue());
    }

    OMAttribute sequenceAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "sequence"));
    if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
      target.setSequenceRef(sequenceAttr.getAttributeValue());
    }

    OMAttribute endpointAttr =
        elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "endpoint"));
    if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
      target.setEndpointRef(endpointAttr.getAttributeValue());
    }

    OMElement sequence =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "sequence"));
    if (sequence != null) {
      SequenceMediatorFactory fac = new SequenceMediatorFactory();
      target.setSequence(fac.createAnonymousSequence(sequence));
    }

    OMElement endpoint =
        elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
    if (endpoint != null) {
      target.setEndpoint(EndpointFactory.getEndpointFromElement(endpoint, true));
    }

    return target;
  }
  private static EventOutputProperty getOutputPropertyFromOM(OMElement omElement) {

    OMElement propertyFromElement =
        omElement.getFirstChildWithName(
            new QName(
                EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_FROM_PROPERTY));
    OMElement propertyToElement =
        omElement.getFirstChildWithName(
            new QName(
                EventFormatterConstants.EF_CONF_NS, EventFormatterConstants.EF_ELE_TO_PROPERTY));

    String name =
        propertyToElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_NAME));
    String valueOf =
        propertyFromElement.getAttributeValue(new QName(EventFormatterConstants.EF_ATTR_NAME));

    return new EventOutputProperty(name, valueOf);
  }
예제 #26
0
 public String getRequiredString(QName parameter) throws IllegalArgumentException {
   OMElement e = _element.getFirstChildWithName(parameter);
   if (e == null) throw new IllegalArgumentException("Missing parameter: " + parameter);
   String text = e.getText();
   if (text == null || text.trim().length() == 0)
     throw new IllegalArgumentException("Empty parameter: " + parameter);
   if (LOG.isDebugEnabled()) LOG.debug("Parameter " + parameter + ": " + text);
   return text;
 }
 public static String parseResponseFeedback(org.apache.axiom.soap.SOAPBody soapBody)
     throws FaultException {
   /*  Sample feedback response
   *   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body><part><axis2ns3:correlation xmlns:axis2ns3="http://wso2.org/humantask/feedback">
       <axis2ns3:taskid>10001</axis2ns3:taskid></axis2ns3:correlation></part></soapenv:Body></soapenv:Envelope>
   * */
   Iterator<OMElement> srcParts = soapBody.getChildElements();
   if (srcParts.hasNext()) {
     OMElement srcPart = srcParts.next();
     if (!srcPart.getQName().equals(new QName(null, "part"))) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     OMElement hifb =
         srcPart.getFirstChildWithName(
             new QName(
                 BPEL4PeopleConstants.B4P_NAMESPACE, BPEL4PeopleConstants.B4P_CORRELATION_HEADER));
     if (hifb == null) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     OMElement taskIDele =
         hifb.getFirstChildWithName(
             new QName(
                 BPEL4PeopleConstants.B4P_NAMESPACE,
                 BPEL4PeopleConstants.B4P_CORRELATION_HEADER_ATTRIBUTE));
     if (taskIDele == null) {
       throw new FaultException(
           BPEL4PeopleConstants.B4P_FAULT,
           "Unexpected element in SOAP body: " + srcPart.toString());
     }
     return taskIDele.getText();
     //            Document doc = DOMUtils.newDocument();
     //            Element destPart = doc.createElementNS(null, "part");
     //            destPart.appendChild(doc.importNode(OMUtils.toDOM(srcPart), true));
     //            message.setPart("part", destPart);
   }
   throw new FaultException(
       BPEL4PeopleConstants.B4P_FAULT, "TaskID not found in the feedback message");
 }
  private OMElement preProcessRealmConfig(InputStream inStream)
      throws CarbonException, XMLStreamException {
    inStream = CarbonUtils.replaceSystemVariablesInXml(inStream);
    StAXOMBuilder builder = new StAXOMBuilder(inStream);
    OMElement documentElement = builder.getDocumentElement();

    OMElement realmElement =
        documentElement.getFirstChildWithName(
            new QName(UserCoreConstants.RealmConfig.LOCAL_NAME_REALM));
    return realmElement;
  }
 /**
  * Process the following element
  *
  * @param servicesEle The services element
  */
 void createServicesConfig(OMElement servicesEle) {
   OMElement defaultsEle =
       servicesEle.getFirstChildWithName(
           new QName(SynapseConstants.SYNAPSE_NAMESPACE, "defaults"));
   if (defaultsEle != null) {
     createConfiguration(defaultsEle, defaultServiceConfig = new ServiceConfiguration(null));
   }
   for (Iterator<OMElement> iter = servicesEle.getChildrenWithLocalName("service");
       iter.hasNext(); ) {
     OMElement serviceEle = iter.next();
     OMElement domainEle =
         serviceEle.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "domain"));
     String domain;
     if (domainEle == null || (domain = domainEle.getText()).isEmpty()) {
       throw new RuntimeException(
           "The mandatory domain element child of the service element is not specified");
     }
     OMElement hostsEle =
         serviceEle.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "hosts"));
     if (hostsEle == null) {
       throw new RuntimeException(
           "The mandatory hosts element child of the service element is not specified");
     }
     for (Iterator<OMElement> hostsIter = hostsEle.getChildrenWithLocalName("host");
         hostsIter.hasNext(); ) {
       OMElement hostEle = hostsIter.next();
       String host;
       if ((host = hostEle.getText()).isEmpty()) {
         throw new RuntimeException("host cannot be empty");
       }
       if (hostDomainMap.containsKey(host)) {
         throw new RuntimeException("host " + host + " has been duplicated in the configuration");
       }
       hostDomainMap.put(host, domain);
     }
     ServiceConfiguration serviceConfig = new ServiceConfiguration(domain);
     createConfiguration(serviceEle, serviceConfig);
     serviceConfigMap.put(domain, serviceConfig);
   }
 }
  /**
   * Read port from andes-config.xml
   *
   * @return
   */
  private String readSSLPortFromQpidConfig() {
    String port = "";

    try {
      File confFile = new File(getQpidHome() + ANDES_CONF_FILE);

      OMElement docRootNode = new StAXOMBuilder(new FileInputStream(confFile)).getDocumentElement();
      OMElement connectorNode =
          docRootNode.getFirstChildWithName(new QName(QPID_CONF_CONNECTOR_NODE));
      OMElement portNode = connectorNode.getFirstChildWithName(new QName(QPID_CONF_SSL_PORT_NODE));

      port = portNode.getText();
    } catch (FileNotFoundException e) {
      log.error(getQpidHome() + ANDES_CONF_FILE + " not found");
    } catch (XMLStreamException e) {
      log.error("Error while reading " + getQpidHome() + ANDES_CONF_FILE + " : " + e.getMessage());
    } catch (NullPointerException e) {
      log.error("Invalid configuration : " + getQpidHome() + ANDES_CONF_FILE);
    }

    return ((port != null) ? port.trim() : "");
  }