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

The following examples show how to use org.apache.axiom.om.OMElement#getNamespace() . 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: ReturnRequestStatusTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void deleteEmployeeById(String employeeNumber) throws AxisFault {
    OMElement result;
    OMElement payload = fac.createOMElement("deleteEmployeeById", omNs);

    OMElement empNo = fac.createOMElement("employeeNumber", omNs);
    empNo.setText(employeeNumber);
    payload.addChild(empNo);

    result = new AxisServiceClient().sendReceive(payload, serviceEndPoint, "deleteEmployeeById");

    assertTrue(result.toString().contains("SUCCESSFUL"), "Response Not Successful");
    OMNamespace nameSpace = result.getNamespace();
    Assert.assertNotNull(nameSpace.getPrefix(), "Invalid prefix. prefix value null");
    Assert.assertNotSame(nameSpace.getPrefix(), "", "Invalid prefix");
    Assert.assertEquals(nameSpace.getNamespaceURI(), "http://ws.wso2.org/dataservice", "Invalid NamespaceURI");
}
 
Example 2
Source File: ReturnRequestStatusTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private void deleteEmployeeById(String employeeNumber) throws AxisFault {
    OMElement result;
    OMElement payload = fac.createOMElement("deleteEmployeeById", omNs);

    OMElement empNo = fac.createOMElement("employeeNumber", omNs);
    empNo.setText(employeeNumber);
    payload.addChild(empNo);

    result = new AxisServiceClient().sendReceive(payload, serviceEndPoint, "deleteEmployeeById");

    Assert.assertTrue(result.toString().contains("SUCCESSFUL"), "Response Not Successful");
    OMNamespace nameSpace = result.getNamespace();
    Assert.assertNotNull(nameSpace.getPrefix(), "Invalid prefix. prefix value null");
    Assert.assertNotSame(nameSpace.getPrefix(), "", "Invalid prefix");
    Assert.assertEquals(nameSpace.getNamespaceURI(), "http://ws.wso2.org/dataservice", "Invalid NamespaceURI");
}
 
Example 3
Source File: SoapTransportCommandProcessorTest.java    From cougar with Apache License 2.0 6 votes vote down vote up
private void assertElement(OMElement expectedElement, OMElement actualElement) {
	Iterator expectedIt = expectedElement.getChildElements();
	Iterator actualIt = actualElement.getChildElements();
	assertEquals(expectedElement.getLocalName(), actualElement.getLocalName());
	if (expectedElement.getNamespace() == null) {
		assertNull(actualElement.getNamespace());
	} else {
		assertEquals(expectedElement.getNamespace().getNamespaceURI(), actualElement.getNamespace().getNamespaceURI());
	}
	assertEquals(expectedElement.getText(), actualElement.getText());
	assertEquals(expectedElement.getType(), actualElement.getType());
	assertAttributes(expectedElement, actualElement);
	while (expectedIt.hasNext()) {
		assertTrue(actualIt.hasNext());
		OMElement expectedChildElement = (OMElement)expectedIt.next();
		OMElement actualChildElement = (OMElement)actualIt.next();
		assertElement(expectedChildElement, actualChildElement);
	}
	assertFalse(actualIt.hasNext());
}
 
Example 4
Source File: RegistryA.java    From openxds with Apache License 2.0 6 votes vote down vote up
protected void validateQueryTransaction(OMElement ahqr) throws XdsValidationException {
	OMNamespace ns = ahqr.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! 
			( ns_uri.equals(MetadataSupport.ebQns3.getNamespaceURI())  ||
					ns_uri.equals(MetadataSupport.ebQns2.getNamespaceURI())	 )) {
		throw new XdsValidationException("Invalid namespace on AdhocQueryRequest (" + ns_uri + ")");
	}


	String type = getRTransactionName(ahqr);


	if (type.startsWith("Unknown")) 
		throw new XdsValidationException("WS:Action indicates a Query, neither AdhocQuery or SQLQuery request found");
	if (type.startsWith("SubmitObjectsRequest")) 
		throw new XdsValidationException("WS:Action indicates a Query, SubmitObjectsRequest found");
	if (type.startsWith("SQL") &&
			!ns_uri.equals(MetadataSupport.ebQns2.getNamespaceURI()))
		throw new XdsValidationException("SQL query must have namespace " + MetadataSupport.ebQns2.getNamespaceURI());

	if (type.startsWith("SQ"))
		new StoredQueryRequestSoapValidator(getXdsVersion(), getMessageContext()).runWithException();
}
 
Example 5
Source File: RepositoryBopt.java    From openxds with Apache License 2.0 6 votes vote down vote up
public OMElement RetrieveDocumentSetRequest(OMElement rdsr) {
	try {
		OMElement startup_error = beginTransaction("RET.b", rdsr, AppendixV.REPOSITORY_ACTOR);
		if (startup_error != null)
			return startup_error;
		log_message.setTestMessage("RET.b");

		OMNamespace ns = rdsr.getNamespace();
		String ns_uri =  ns.getNamespaceURI();
		if (ns_uri == null || ! ns_uri.equals(MetadataSupport.xdsB.getNamespaceURI())) {
			OMElement res = this.start_up_error(rdsr, "RepositoryB.java", AppendixV.REPOSITORY_ACTOR, "Invalid namespace on RetrieveDocumentSetRequest (" + ns_uri + ")", true);
			endTransaction(false);
			return res;
		}

		RetrieveDocumentSet s = new RetrieveDocumentSet(log_message, XdsCommon.xds_b, getMessageContext());
		
		OMElement result = s.retrieveDocumentSet(rdsr, this, true /* optimize */, this);
		endTransaction(s.getStatus());
		return result;
	} catch (Exception e) {
		return endTransaction(rdsr, e, AppendixV.REPOSITORY_ACTOR, "");
	}
}
 
Example 6
Source File: AttributeCallbackHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * This method loads claim according to the claim dialect that is defined in the request
 *
 * @param claimsElement
 * @param userIdentifier
 * @throws IdentityProviderException
 */
private void loadClaims(OMElement claimsElement, String userIdentifier) throws IdentityProviderException {
    IdentityClaimManager claimManager = null;
    Claim[] claims = null;
    String claimDialect = null;

    if (claimsElement.getNamespace() != null) {
        claimDialect = claimsElement
                .getAttributeValue(new QName(claimsElement.getNamespace().getNamespaceURI(), "Dialect"));
    }

    if (claimDialect == null || claimDialect.trim().length() == 0) {
        claimDialect = UserCoreConstants.DEFAULT_CARBON_DIALECT;
    }

    if (log.isDebugEnabled()) {
        log.debug("Loading claims");
    }

    try {
        claimManager = IdentityClaimManager.getInstance();
        claims =
                claimManager.getAllSupportedClaims(claimDialect, IdentityTenantUtil.getRealm(null, userIdentifier));
        for (int i = 0; i < claims.length; i++) {
            Claim temp = claims[i];
            supportedClaims.put(temp.getClaimUri(), temp);
        }
    } catch (IdentityException e) {
        log.error("Error while loading claims", e);
        throw new IdentityProviderException("Error while loading claims", e);
    }
}
 
Example 7
Source File: ReturnRequestStatusTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void addEmployee(String serviceEndPoint, String employeeNumber) throws AxisFault {
    OMElement result;

    result = new AxisServiceClient()
            .sendReceive(getAddEmployeePayload(employeeNumber), serviceEndPoint, "addEmployee");
    assertTrue(result.toString().contains("SUCCESSFUL"), "Response Not Successful");
    OMNamespace nameSpace = result.getNamespace();
    Assert.assertNotNull(nameSpace, "Response Message NameSpace not qualified");
    Assert.assertNotNull(nameSpace.getPrefix(), "Invalid prefix. prefix value null");
    Assert.assertNotSame(nameSpace.getPrefix(), "", "Invalid prefix");
    Assert.assertEquals(nameSpace.getNamespaceURI(), "http://ws.wso2.org/dataservice", "Invalid NamespaceURI");

}
 
Example 8
Source File: RegistryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validateQueryTransaction(OMElement sor)
throws XdsValidationException, MetadataValidationException, XdsInternalException {
	forceForcedError();
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.ebQns3.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");

	String type = getRTransactionName(sor);

	if (!this.isSQ(sor))
		throw new XdsValidationException("Only StoredQuery is acceptable on this endpoint");
	
	SoapHeader sh = new SoapHeader(getMessageContext());
	ParamParser pp = new ParamParser(sor);
	if (MetadataSupport.SQ_action.equals(sh.getActionValue())) {
		if ( !MetadataSupport.isSQId(pp.getQueryid())) {
			throw new XdsValidationException("WS:Action is [" + sh.getActionValue() + 
					"] but query id [" + pp.getQueryid() + "] is not a Stored Query query id");
		}
	} else if (MetadataSupport.MPQ_action.equals(sh.getActionValue())) {
		if ( !MetadataSupport.isMPQId(pp.getQueryid())) {
			throw new XdsValidationException("WS:Action is [" + sh.getActionValue() + 
					"] but query id [" + pp.getQueryid() + "] is not a MPQ query id");
		}
	}

	new StoredQueryRequestSoapValidator(getXdsVersion(), getMessageContext()).runWithException();

}
 
Example 9
Source File: RegistryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validateSubmitTransaction(OMElement sor)
throws XdsValidationException {
	forceForcedError();
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.ebLcm3.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");

	String type = getRTransactionName(sor);

	if (!type.startsWith("SubmitObjectsRequest"))
		throw new XdsValidationException("Only SubmitObjectsRequest is acceptable on this endpoint, found " + sor.getLocalName());
}
 
Example 10
Source File: RepositoryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validateRetTransaction(OMElement rds) throws XdsValidationException {
	forceForcedError();
	OMNamespace ns = rds.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.xdsB.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + rds.getLocalName() + " (" + ns_uri + ")");
}
 
Example 11
Source File: RepositoryB.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validatePnRTransaction(OMElement sor) throws XdsValidationException {
	forceForcedError();
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.xdsB.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");
}
 
Example 12
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 13
Source File: RepositoryA.java    From openxds with Apache License 2.0 5 votes vote down vote up
protected void validatePnRTransaction(OMElement sor)
		throws XdsValidationException {
	OMNamespace ns = sor.getNamespace();
	String ns_uri =  ns.getNamespaceURI();
	if (ns_uri == null || ! ns_uri.equals(MetadataSupport.ebRSns2.getNamespaceURI())) 
		throw new XdsValidationException("Invalid namespace on " + sor.getLocalName() + " (" + ns_uri + ")");
}
 
Example 14
Source File: ReturnRequestStatusTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private void addEmployee(String serviceEndPoint, String employeeNumber) throws AxisFault {
    OMElement result;

    result = new AxisServiceClient().sendReceive(getAddEmployeePayload(employeeNumber), serviceEndPoint, "addEmployee");
    Assert.assertTrue(result.toString().contains("SUCCESSFUL"), "Response Not Successful");
    OMNamespace nameSpace = result.getNamespace();
    Assert.assertNotNull(nameSpace, "Response Message NameSpace not qualified");
    Assert.assertNotNull(nameSpace.getPrefix(), "Invalid prefix. prefix value null");
    Assert.assertNotSame(nameSpace.getPrefix(), "", "Invalid prefix");
    Assert.assertEquals(nameSpace.getNamespaceURI(), "http://ws.wso2.org/dataservice", "Invalid NamespaceURI");


}
 
Example 15
Source File: ClientUtil.java    From carbon-identity-framework 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 16
Source File: DOMHASHGenerator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This is an overloaded method for getting the expanded name as namespaceURI followed by the local name for
 * OMElement.
 *
 * @param element - OMElement of which the expanded name is retrieved
 * @return expanded name of OMElement as an String in the form {ns-uri:local-name}
 */
public String getExpandedName(OMElement element) {

    if (element.getNamespace() != null) {
        return element.getNamespace().getNamespaceURI() + ":" + element.getLocalName();
    } else {
        return element.getLocalName();
    }
}
 
Example 17
Source File: HttpRequestHashGenerator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This is an overloaded method for getting the expanded name as namespaceURI followed by the local name for
 * OMElement.
 *
 * @param element - OMElement of which the expanded name is retrieved
 * @return expanded name of OMElement as an String in the form {ns-uri:local-name}
 */
public String getExpandedName(OMElement element) {

    if (element.getNamespace() != null) {
        return element.getNamespace().getNamespaceURI() + ":" + element.getLocalName();
    } else {
        return element.getLocalName();
    }
}
 
Example 18
Source File: XMLComparator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static boolean isIgnorable(OMElement elt) {
    if (elt != null) {
        OMNamespace namespace = elt.getNamespace();
        if (namespace != null) {
            return ignorableNamespaceList.contains(namespace.getNamespaceURI());
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 19
Source File: DataServiceFault.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public static OMElement extractFaultMessage(Throwable throwable) {
    if (throwable instanceof DataServiceFault) {
        if (throwable.getCause() instanceof XMLStreamException) {
            return extractFaultMessage(((XMLStreamException) throwable.getCause()).getNestedException());
        }
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMElement root = fac.createOMElement(new QName(
                DBConstants.WSO2_DS_NAMESPACE, DBConstants.DS_FAULT_ELEMENT));
        OMNamespace ns = root.getNamespace();
        for (Map.Entry<String, Object> rootEntry : ((DataServiceFault) throwable).getPropertyMap().entrySet()) {
            OMElement keyElement = fac.createOMElement(rootEntry.getKey(), ns);
            if (rootEntry.getValue() instanceof Map) {
                for (Map.Entry dataServiceEntry : (Set<Map.Entry>) ((Map) rootEntry.getValue()).entrySet()) {
                    OMElement dataServiceKeyElement = fac.createOMElement(
                            dataServiceEntry.getKey().toString(), ns);
                    OMText dataServiceValueElement = fac.createOMText(
                            dataServiceKeyElement, dataServiceEntry.getValue().toString());
                    dataServiceKeyElement.addChild(dataServiceValueElement);
                    keyElement.addChild(dataServiceKeyElement);
                }
            } else {
                OMText valueElement = fac.createOMText(
                        keyElement, rootEntry.getValue().toString());
                keyElement.addChild(valueElement);
            }
            root.addChild(keyElement);
        }
        return root;
    } else if (throwable instanceof XMLStreamException) {
        return extractFaultMessage(((XMLStreamException) throwable).getNestedException());
    } else if (throwable != null) {
        Throwable cause = throwable.getCause();
        if (cause != null) {
            return extractFaultMessage(cause);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example 20
Source File: AbstractRepository.java    From openxds with Apache License 2.0 4 votes vote down vote up
public OMElement RetrieveDocumentSetRequest(OMElement rdsr) throws AxisFault {
	try {
		OMElement startup_error = beginTransaction(getRetTransactionName(), rdsr, AppendixV.REPOSITORY_ACTOR);
		if (startup_error != null)
			return startup_error;
		log_message.setTestMessage(getRetTransactionName());
		
		validateWS();
		
		mustBeMTOM();

		validateRetTransaction(rdsr);
		
		OMNamespace ns = rdsr.getNamespace();
		String ns_uri =  ns.getNamespaceURI();
		if (ns_uri == null || ! ns_uri.equals(MetadataSupport.xdsB.getNamespaceURI())) {
			OMElement res = this.start_up_error(rdsr, "AbstractRepository.java", AppendixV.REPOSITORY_ACTOR, "Invalid namespace on RetrieveDocumentSetRequest (" + ns_uri + ")", true);
			endTransaction(false);
			return res;
		}
		
		RegistryErrorList rel = new RegistryErrorList(RegistryErrorList.version_3,  true /* log */);
		
		validateRequest(rdsr, rel);
		
		if (rel.has_errors()) {
			OMElement response = new RetrieveDocumentSetResponse(new RegistryResponse(RegistryErrorList.version_3, rel)).getResponse();
			addOther("Response", response.toString());
			endTransaction(false);
			return response;
		}


		RetrieveDocumentSet s = new RetrieveDocumentSet(log_message, XdsCommon.xds_b, getMessageContext());
		
		OMElement result = processRetrieveDocumentSet(s, rdsr);
		
		endTransaction(s.getStatus());
		return result;
	} catch (Exception e) {
		return endTransaction(rdsr, e, AppendixV.REPOSITORY_ACTOR, "");
	}
}