Java Code Examples for org.apache.axiom.om.OMElement#getFirstChildWithName()

The following examples show how to use org.apache.axiom.om.OMElement#getFirstChildWithName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamicSequenceTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Define a dynamic sequence defined in a proxy service")
public void testSequenceMediator() throws AxisFault {

    OMElement response;
    axis2Client.addHttpHeader("Sequence", "sendToStockQuoteServiceSequence");
    response = axis2Client
            .sendSimpleStockQuoteRequest(getProxyServiceURLHttp("sequenceMediatorDynamicSequenceTestProxy"), null,
                    "WSO2");

    assertNotNull(response, "Response message null");
    OMElement returnElement = response.getFirstElement();

    OMElement symbolElement = returnElement
            .getFirstChildWithName(new QName("http://services.samples/xsd", "symbol"));

    assertEquals(symbolElement.getText(), "WSO2", "Fault, invalid response");

}
 
Example 2
Source File: EventTriggerFactory.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static XPathEventTrigger createXPathEventTrigger(DataService dataService,
                                                            OMElement xpathEventEl) throws DataServiceFault {
	try {
	    String id = xpathEventEl.getAttributeValue(new QName(DBSFields.ID));
	    String expression = xpathEventEl.getFirstChildWithName(
	    		new QName(DBSFields.EXPRESSION)).getText();
	    String targetTopic = xpathEventEl.getFirstChildWithName(
	    		new QName(DBSFields.TARGET_TOPIC)).getText();
	    OMElement subsEl = xpathEventEl.getFirstChildWithName(
	    		new QName(DBSFields.SUBSCRIPTIONS));
	    OMElement subEl;
	    Iterator<OMElement> subElItr = subsEl.getChildrenWithName(
	    		new QName(DBSFields.SUBSCRIPTION));
	    List<String> endpointUrls = new ArrayList<String>();
	    while (subElItr.hasNext()) {
	    	subEl = subElItr.next();
	    	endpointUrls.add(subEl.getText());
	    }
	    return new XPathEventTrigger(dataService, id, expression, targetTopic, endpointUrls);
	} catch (Exception e) {
		throw new DataServiceFault(e, "Error in create XPathEventTrigger");
	}
}
 
Example 3
Source File: DiscoveryOMUtils.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static Probe getProbeFromOM(OMElement probeElement) throws DiscoveryException {
    validateTopElement(DiscoveryConstants.PROBE, probeElement);

    Probe probe = new Probe();
    probe.setTypes(getTypes(probeElement));
    probe.setScopes(getScopes(probeElement));

    OMElement scopesElement = probeElement.getFirstChildWithName(DiscoveryConstants.SCOPES);
    if (scopesElement != null) {
        OMAttribute attr = scopesElement.getAttribute(DiscoveryConstants.ATTR_MATCH_BY);
        if (attr != null && attr.getAttributeValue() != null) {
            try {
                probe.setMatchBy(new URI(attr.getAttributeValue()));
            } catch (URISyntaxException e) {
                throw new DiscoveryException("Invalid URI value for the MatchBy attribute", e);
            }
        }
    }
    return probe;
}
 
Example 4
Source File: EmailUserNameMigrationClient.java    From product-es with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks whether there is a overview_provider in the overview table.
 * @param governanceArtifactConfiguration
 * @return
 * @throws RegistryException
 * @throws XMLStreamException
 */
private boolean hasOverviewProviderElement(GovernanceArtifactConfiguration governanceArtifactConfiguration)
        throws RegistryException, XMLStreamException {

    OMElement rxtContentOM = governanceArtifactConfiguration.getContentDefinition();
    Iterator tableNodes = rxtContentOM.getChildrenWithLocalName(Constants.TABLE);
    while (tableNodes.hasNext()) {
        OMElement tableOMElement = (OMElement) tableNodes.next();
        if (Constants.OVERVIEW.equalsIgnoreCase(tableOMElement.getAttributeValue(new QName(Constants.NAME)))) {
            Iterator fieldNodes = tableOMElement.getChildrenWithLocalName(Constants.FIELD);
            while (fieldNodes.hasNext()) {
                OMElement fieldElement = (OMElement) fieldNodes.next();
                OMElement nameElement = fieldElement.getFirstChildWithName(new QName(Constants.NAME));
                if (nameElement != null) {
                    if (Constants.PROVIDER.equalsIgnoreCase(nameElement.getText())) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 5
Source File: SSOConsentServiceImpl.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private void readSSOConsentEnabledConfig() {

        IdentityConfigParser identityConfigParser = IdentityConfigParser.getInstance();
        OMElement consentElement = identityConfigParser.getConfigElement(CONFIG_ELEM_CONSENT);

        if (consentElement != null) {

            OMElement ssoConsentEnabledElem = consentElement.getFirstChildWithName(
                    new QName(IDENTITY_DEFAULT_NAMESPACE, CONFIG_ELEM_ENABLE_SSO_CONSENT_MANAGEMENT));

            if (ssoConsentEnabledElem != null) {
                String ssoConsentEnabledElemText = ssoConsentEnabledElem.getText();
                if (isNotBlank(ssoConsentEnabledElemText)) {
                    ssoConsentEnabled = Boolean.parseBoolean(ssoConsentEnabledElemText);
                    if (isDebugEnabled()) {
                        logDebug("Consent management for SSO is set to " + ssoConsentEnabled + " from configurations.");
                    }
                    return;
                }
            }
        }
        ssoConsentEnabled = true;
    }
 
Example 6
Source File: FileBasedConfigurationBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void readSequenceConfigs(OMElement documentElement) {
    OMElement sequencesElem = documentElement.getFirstChildWithName(IdentityApplicationManagementUtil.
            getQNameWithIdentityApplicationNS(FrameworkConstants.Config.QNAME_SEQUENCES));

    if (sequencesElem != null) {
        // for each every application defined, create a ApplicationBean instance
        for (Iterator sequenceElements = sequencesElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_SEQUENCE);
             sequenceElements.hasNext(); ) {
            SequenceConfig sequenceConfig = processSequenceElement((OMElement) sequenceElements.next());

            if (sequenceConfig != null) {
                this.sequenceList.add(sequenceConfig);
            }
        }
    }
}
 
Example 7
Source File: LBService1.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public OMElement loadOperation(OMElement param) throws AxisFault {

        param.build();
        param.detach();

        OMElement loadElement = param.getFirstChildWithName(new QName("load"));
        String l = loadElement.getText();
        long load = Long.parseLong(l);

        for (long i = 0; i < load; i++) {
            System.out.println("Iteration: " + i);
        }

        String sName = System.getProperty("server_name");
        if (sName != null) {
            loadElement.setText("Response from server: " + sName);
        } else {
            loadElement.setText("Response from anonymous server");
        }
        return param;
    }
 
Example 8
Source File: AbstractEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public OMElement[] getStatusOMElement(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement[] decision = new OMElement[3];

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision[0] = result.getFirstChildWithName(new QName("Decision"));
        decision[1] = result.getFirstChildWithName(new QName("Obligations"));
        decision[2] = result.getFirstChildWithName(new QName("AssociatedAdvice"));
    }
    return decision;
}
 
Example 9
Source File: FileBasedConfigurationBuilder.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private void readAuthenticationEndpointMissingClaimsURL(OMElement documentElement) {
    OMElement authEndpointMissingClaimsURLElem = documentElement.getFirstChildWithName
            (IdentityApplicationManagementUtil.getQNameWithIdentityApplicationNS(FrameworkConstants.Config
                    .QNAME_AUTHENTICATION_ENDPOINT_MISSING_CLAIMS_URL));

    if (authEndpointMissingClaimsURLElem != null) {
        authenticationEndpointMissingClaimsURL = IdentityUtil.fillURLPlaceholders
                (authEndpointMissingClaimsURLElem.getText());
    }
}
 
Example 10
Source File: DiscoveryOMUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private static URI[] getXAddresses(OMElement parent) throws DiscoveryException {
    OMElement xAddrsElement = parent.getFirstChildWithName(DiscoveryConstants.XADDRESSES);
    if (xAddrsElement == null) {
        return null;
    }

    String xAddrsList = xAddrsElement.getText();
    if (xAddrsList == null || "".equals(xAddrsList)) {
        return null;
    }

    return parseURIList(xAddrsList);
}
 
Example 11
Source File: ClientUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to extract the boolean response
 *
 * @param xmlstring XACML resource as String
 * @return Decision
 * @throws Exception if fails
 */
public static String getStatus(String xmlstring) throws Exception {

    OMElement response = null;
    OMElement result = null;
    OMElement decision = null;
    response = AXIOMUtil.stringToOM(xmlstring);

    OMNamespace nameSpace = response.getNamespace();

    if (nameSpace != null) {
        result = response.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Result"));
    } else {
        result = response.getFirstElement();
    }
    if (result != null) {
        if (nameSpace != null) {
            decision = result.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Decision"));
        } else {
            decision = result.getFirstChildWithName(new QName("Decision"));
        }
        if (decision != null) {
            return decision.getText();
        }
    }

    return "Invalid Status";
}
 
Example 12
Source File: APIManagerConfiguration.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private void setRuntimeArtifactsSyncGatewayConfig (OMElement omElement){

        OMElement enableElement = omElement
                .getFirstChildWithName(new QName(APIConstants.GatewayArtifactSynchronizer.ENABLE_CONFIG));
        if (enableElement != null) {
            gatewayArtifactSynchronizerProperties.setRetrieveFromStorageEnabled(
                    JavaUtils.isTrueExplicitly(enableElement.getText()));
        } else {
            log.debug("Retrieve from storage is not set. Set to default false");
        }

        OMElement retrieverElement = omElement.getFirstChildWithName(
                new QName(APIConstants.GatewayArtifactSynchronizer.RETRIEVER_CONFIG));
        if (retrieverElement != null) {
            String artifactRetriever = retrieverElement.getText();
            gatewayArtifactSynchronizerProperties.setRetrieverName(artifactRetriever);
        } else {
            log.debug("Artifact retriever Element is not set. Set to default DB Retriever");
        }

        OMElement gatewayLabelElement = omElement
                .getFirstChildWithName(new QName(APIConstants.GatewayArtifactSynchronizer.GATEWAY_LABELS_CONFIG));
        if (gatewayLabelElement != null) {
            Iterator labelsIterator = gatewayLabelElement
                    .getChildrenWithLocalName(APIConstants.GatewayArtifactSynchronizer.LABEL_CONFIG);
            while (labelsIterator.hasNext()) {
                OMElement labelElement = (OMElement) labelsIterator.next();
                if (labelElement != null) {
                    gatewayArtifactSynchronizerProperties.getGatewayLabels().add(labelElement.getText());
                }
            }
        }
    }
 
Example 13
Source File: EnrichIntegrationAddDefinedPropertyToDefinedChildPropertyTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "Add defined property as a child of envelop (of out going message) ")
public void testEnrichMediator() throws Exception {
    OMElement response;

    response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp("enrichAddChildFromPropertyTestProxy"), null,
                                                       "WSO2");

    assertNotNull(response, "Response message null");
    OMElement newChild = response.getFirstChildWithName(
            new QName("http://services.samples", "NewChild"));
    OMElement newChildContent = newChild.getFirstElement();
    assertEquals(newChildContent.getLocalName(), "child", "Fault, new child property content not added.");
    assertEquals(newChildContent.getText(), "Child", "Fault, new child property content not added.");

}
 
Example 14
Source File: Sample600TestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(enabled = false,
      description = "Simple Message Transformation - Rule Mediator for Message Transformation - MSFT changed to IBM")
public void testSymbolMsftChangedToIBM() throws Exception {

    OMElement response = axis2Client.sendSimpleStockQuoteRequest(
        getMainSequenceURL(), null, "MSFT");
    Assert.assertNotNull(response, "Response is null");

    OMElement returnElement = response.getFirstElement();
    OMElement symbolElement = returnElement.getFirstChildWithName(
        new QName("http://services.samples/xsd", "symbol"));
    assertEquals(symbolElement.getText(), "IBM", "Fault, invalid response");
}
 
Example 15
Source File: ConfigurationLoader.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static void populateHandlers(OMElement apiElement, InternalAPI api) {

        List<InternalAPIHandler> handlerList = new ArrayList<>();
        OMElement handlersElement = apiElement.getFirstChildWithName(HANDLERS_Q);
        if (handlersElement != null) {
            Iterator<OMElement> handlers = handlersElement.getChildElements();

            while (handlers.hasNext()) {
                OMElement handlerElement = handlers.next();
                if (handlerElement.getAttribute(NAME_ATT) != null) {
                    String handlerName = handlerElement.getAttributeValue(NAME_ATT);
                    if (handlerElement.getAttribute(CLASS_Q) != null) {
                        String handlerClass = handlerElement.getAttributeValue(CLASS_Q);
                        OMElement resourcesElement = handlerElement.getFirstChildWithName(RESOURCES_Q);
                        List<String> resourcesList = new ArrayList<>();
                        if (Objects.nonNull(resourcesElement)) {
                            Iterator resources = resourcesElement.getChildElements();
                            while (resources.hasNext()) {
                                OMElement resource = (OMElement) resources.next();
                                resourcesList.add(resource.getText());
                            }
                        }
                        InternalAPIHandler handler = createHandler(handlerClass, api.getContext(), resourcesList);
                        handler.setName(handlerName);
                        handlerList.add(handler);
                    } else {
                        handleException(
                                "Class attribute is not defined in " + handlerElement.getAttributeValue(NAME_ATT));
                    }
                } else {
                    handleException("Name not defined in one or more handlers");
                }
            }
        }
        api.setHandlers(handlerList);
    }
 
Example 16
Source File: AbstractEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement[] getStatusOMElement(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement[] decision = new OMElement[3];

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision[0] = result.getFirstChildWithName(new QName("Decision"));
        decision[1] = result.getFirstChildWithName(new QName("Obligations"));
        decision[2] = result.getFirstChildWithName(new QName("AssociatedAdvice"));
    }
    return decision;
}
 
Example 17
Source File: ClaimBuilder.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @param claimElement
 * @throws ClaimBuilderException
 */
private void validateSchema(OMElement claimElement) throws ClaimBuilderException {
    String message = null;

    if (claimElement.getFirstChildWithName(new QName(LOCAL_NAME_CLAIM_URI)) == null) {
        message = "In valid schema <ClaimUri> element not present";
        if (log.isDebugEnabled()) {
            log.debug(message);
        }
        throw new ClaimBuilderException(message);
    }

    if (claimElement.getFirstChildWithName(new QName(LOCAL_NAME_DESCRIPTION)) == null) {
        message = "In valid schema <Description> element not present";
        if (log.isDebugEnabled()) {
            log.debug(message);
        }
        throw new ClaimBuilderException(message);
    }

    if (claimElement.getFirstChildWithName(new QName(LOCAL_NAME_ATTR_ID)) == null) {
        message = "In valid schema <AttributeId> element not present";
        if (log.isDebugEnabled()) {
            log.debug(message);
        }
        throw new ClaimBuilderException(message);
    }
}
 
Example 18
Source File: Sample601TestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
public void testLocalEntryWithCorrectInput() throws Exception {


        OMElement response;

        response = axis2Client.sendSimpleStockQuoteRequest(getMainSequenceURL(), null,
                                                           "IBM");
        assertNotNull(response, "Response message null");
        OMElement returnElement = response.getFirstElement();

        OMElement symbolElement = returnElement.getFirstChildWithName(
                new QName("http://services.samples/xsd", "symbol"));

        assertEquals(symbolElement.getText(), "IBM", "Fault, invalid response");


    }
 
Example 19
Source File: APIManagerConfiguration.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * set workflow related configurations
 *
 * @param element
 */
private void setWorkflowProperties(OMElement element) {

    OMElement workflowConfigurationElement = element
            .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW));
    if (workflowConfigurationElement != null) {
        OMElement enableWorkflowElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_ENABLED));
        if (enableWorkflowElement != null) {
            workflowProperties.setEnabled(JavaUtils.isTrueExplicitly(enableWorkflowElement.getText()));
        }
        OMElement workflowServerUrlElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_SERVER_URL));
        if (workflowServerUrlElement != null) {
            workflowProperties.setServerUrl(APIUtil.replaceSystemProperty(workflowServerUrlElement.getText()));
        }
        OMElement workflowServerUserElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_SERVER_USER));
        if (workflowServerUserElement != null) {
            workflowProperties.setServerUser(APIUtil.replaceSystemProperty(workflowServerUserElement.getText()));
        }
        OMElement workflowDCRUserElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_DCR_EP_USER));
        if (workflowDCRUserElement != null) {
            workflowProperties.setdCREndpointUser(APIUtil.replaceSystemProperty(workflowDCRUserElement.getText()));
        }
        OMElement workflowCallbackElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_CALLBACK));
        if (workflowCallbackElement != null) {
            workflowProperties
                    .setWorkflowCallbackAPI(APIUtil.replaceSystemProperty(workflowCallbackElement.getText()));
        }

        OMElement workflowDCREPElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_DCR_EP));
        if (workflowDCREPElement != null) {
            workflowProperties.setdCREndPoint(APIUtil.replaceSystemProperty(workflowDCREPElement.getText()));
        }

        OMElement workflowTokenEpElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_TOKEN_EP));
        if (workflowTokenEpElement != null) {
            workflowProperties.setTokenEndPoint(APIUtil.replaceSystemProperty(workflowTokenEpElement.getText()));
        }
        OMElement workflowServerPasswordOmElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_SERVER_PASSWORD));
        String workflowServerPassword = MiscellaneousUtil.resolve(workflowServerPasswordOmElement, secretResolver);
        workflowServerPassword = APIUtil.replaceSystemProperty(workflowServerPassword);
        workflowProperties.setServerPassword(workflowServerPassword);

        OMElement dcrEPPasswordOmElement = workflowConfigurationElement
                .getFirstChildWithName(new QName(APIConstants.WorkflowConfigConstants.WORKFLOW_DCR_EP_PASSWORD));
        String dcrEPPassword = MiscellaneousUtil.resolve(dcrEPPasswordOmElement, secretResolver);
        dcrEPPassword = APIUtil.replaceSystemProperty(dcrEPPassword);
        workflowProperties.setdCREndpointPassword(dcrEPPassword);

    }
}
 
Example 20
Source File: FaultyDataServiceTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Test(groups = "wso2.dss", dependsOnMethods = {"isFaultyService"}, description = "Fix the fault and redeploy")
public void editFaultyService()
        throws Exception {
    DataServiceAdminClient dataServiceAdminService =
            new DataServiceAdminClient(dssContext.getContextUrls().getBackEndUrl(),
                                      sessionCookie);
    String serviceContent;
    String newServiceContent;
    SqlDataSourceUtil dssUtil =
            new SqlDataSourceUtil(sessionCookie,
                                  dssContext.getContextUrls().getBackEndUrl());

    dssUtil.createDataSource(getSqlScript());

    serviceContent = dataServiceAdminService.getDataServiceContent(serviceName);

    try {
        OMElement dbsFile = AXIOMUtil.stringToOM(serviceContent);
        OMElement dbsConfig = dbsFile.getFirstChildWithName(new QName("config"));
        Iterator configElement1 = dbsConfig.getChildElements();
        while (configElement1.hasNext()) {
            OMElement property = (OMElement) configElement1.next();
            String value = property.getAttributeValue(new QName("name"));
            if ("org.wso2.ws.dataservice.protocol".equals(value)) {
                property.setText(dssUtil.getJdbcUrl());

            } else if ("org.wso2.ws.dataservice.driver".equals(value)) {
                property.setText(dssUtil.getDriver());

            } else if ("org.wso2.ws.dataservice.user".equals(value)) {
                property.setText(dssUtil.getDatabaseUser());

            } else if ("org.wso2.ws.dataservice.password".equals(value)) {
                property.setText(dssUtil.getDatabasePassword());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(dbsFile);
        }
        newServiceContent = dbsFile.toString();
    } catch (XMLStreamException e) {
        log.error("XMLStreamException while handling data service content ", e);
        throw new XMLStreamException("XMLStreamException while handling data service content ", e);
    }
    Assert.assertNotNull("Could not edited service content", newServiceContent);
    dataServiceAdminService.editDataService(serviceName, "", newServiceContent);
    log.info(serviceName + " edited");

}