use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomInSequences1.
@Test
public void testGetCustomInSequences1() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, apiId);
List<String> sequenceList = apiProvider.getCustomInSequences();
Assert.assertNotNull(sequenceList);
Assert.assertEquals(1, sequenceList.size());
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomOutSequences(apiId);
// org.wso2.carbon.registry.api.RegistryException
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Error while processing the in in the registry";
try {
apiProvider.getCustomInSequences();
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
String msg1 = "Error while retrieving registry for tenant -1";
try {
apiProvider.getCustomInSequences();
} catch (APIManagementException e) {
Assert.assertEquals(msg1, e.getMessage());
}
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomFaultSequences.
/**
* Get stored custom fault sequences from governanceSystem registry
*
* @throws APIManagementException
*/
public List<String> getCustomFaultSequences(APIIdentifier apiIdentifier) throws APIManagementException {
List<String> sequenceList = new ArrayList<String>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION)) {
org.wso2.carbon.registry.api.Collection faultSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION);
if (faultSeqCollection != null) {
String[] faultSeqChildPaths = faultSeqCollection.getChildren();
Arrays.sort(faultSeqChildPaths);
for (String faultSeqChildPath : faultSeqChildPaths) {
Resource outSequence = registry.get(faultSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + faultSeqChildPath + "' from the registry.", e);
}
}
}
}
String customOutSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT);
if (registry.resourceExists(customOutSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection faultSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customOutSeqFileLocation);
if (faultSeqCollection != null) {
String[] faultSeqChildPaths = faultSeqCollection.getChildren();
Arrays.sort(faultSeqChildPaths);
for (String faultSeqChildPath : faultSeqChildPaths) {
Resource faultSequence = registry.get(faultSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(faultSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + faultSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + " sequences of " + apiIdentifier + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return sequenceList;
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomApiInSequences.
/**
* Get the list of Custom in sequences of API.
*
* @return List of in sequences
* @throws APIManagementException
*/
public List<String> getCustomApiInSequences(APIIdentifier apiIdentifier) throws APIManagementException {
Set<String> sequenceList = new TreeSet<>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
String customInSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN);
if (registry.resourceExists(customInSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection inSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customInSeqFileLocation);
if (inSeqCollection != null) {
String[] inSeqChildPaths = inSeqCollection.getChildren();
Arrays.sort(inSeqChildPaths);
for (String inSeqChildPath : inSeqChildPaths) {
Resource outSequence = registry.get(inSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + inSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN + " sequences of " + apiIdentifier + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return new ArrayList<>(sequenceList);
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomApiFaultSequences.
/**
* Get the list of Custom Fault Sequences of API.
*
* @return List of available fault sequences
* @throws APIManagementException
*/
public List<String> getCustomApiFaultSequences(APIIdentifier apiIdentifier) throws APIManagementException {
Set<String> sequenceList = new TreeSet<>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
String customOutSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT);
if (registry.resourceExists(customOutSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection faultSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customOutSeqFileLocation);
if (faultSeqCollection != null) {
String[] faultSeqChildPaths = faultSeqCollection.getChildren();
Arrays.sort(faultSeqChildPaths);
for (String faultSeqChildPath : faultSeqChildPaths) {
Resource faultSequence = registry.get(faultSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(faultSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + faultSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + " sequences of " + apiIdentifier + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return new ArrayList<>(sequenceList);
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomOutSequences.
/**
* Get stored custom outSequences from governanceSystem registry
*
* @throws APIManagementException
*/
public List<String> getCustomOutSequences(APIIdentifier apiIdentifier) throws APIManagementException {
List<String> sequenceList = new ArrayList<String>();
boolean isTenantFlowStarted = false;
try {
String tenantDomain = null;
if (apiIdentifier.getProviderName().contains("-AT-")) {
String provider = apiIdentifier.getProviderName().replace("-AT-", "@");
tenantDomain = MultitenantUtils.getTenantDomain(provider);
}
PrivilegedCarbonContext.startTenantFlow();
isTenantFlowStarted = true;
if (!StringUtils.isEmpty(tenantDomain)) {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
}
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION)) {
org.wso2.carbon.registry.api.Collection outSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION);
if (outSeqCollection != null) {
String[] outSeqChildPaths = outSeqCollection.getChildren();
Arrays.sort(outSeqChildPaths);
for (String childPath : outSeqChildPaths) {
Resource outSequence = registry.get(childPath);
try {
OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + childPath + "' from the registry.", e);
}
}
}
}
String customOutSeqFileLocation = APIUtil.getSequencePath(apiIdentifier, "out");
if (registry.resourceExists(customOutSeqFileLocation)) {
org.wso2.carbon.registry.api.Collection outSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(customOutSeqFileLocation);
if (outSeqCollection != null) {
String[] outSeqChildPaths = outSeqCollection.getChildren();
Arrays.sort(outSeqChildPaths);
for (String outSeqChildPath : outSeqChildPaths) {
Resource outSequence = registry.get(outSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + outSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (Exception e) {
handleException("Issue is in getting custom OutSequences from the Registry", e);
} finally {
if (isTenantFlowStarted) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return sequenceList;
}
Aggregations