Search in sources :

Example 1 with APIMgtBadRequestException

use of org.wso2.carbon.apimgt.api.APIMgtBadRequestException in project carbon-apimgt by wso2.

the class OnPremResolver method resolve.

@Override
public String resolve(Map<String, Object> properties) throws APIManagementException {
    ArrayList requestedTenantDomain = (ArrayList) ((TreeMap) (properties.get(APIConstants.PROPERTY_HEADERS_KEY))).get(HEADER_X_WSO2_TENANT);
    String tenantDomain = null;
    if (requestedTenantDomain != null) {
        String header = requestedTenantDomain.get(0).toString();
        if (StringUtils.isEmpty(header)) {
            tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        } else {
            tenantDomain = header;
        }
        try {
            if (!APIUtil.isTenantAvailable(tenantDomain)) {
                String errorMessage = "Provided tenant domain '" + tenantDomain + "' is invalid";
                throw new APIMgtBadRequestException(errorMessage);
            }
        } catch (UserStoreException e) {
            String errorMessage = "Error while checking availability of tenant " + tenantDomain;
            throw new APIMgtInternalException(errorMessage);
        }
    }
    if (StringUtils.isEmpty(tenantDomain)) {
        tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    }
    // Set "carbon.super" if tenantDomain is still not resolved.
    if (StringUtils.isEmpty(tenantDomain)) {
        tenantDomain = APIConstants.SUPER_TENANT_DOMAIN;
    }
    return tenantDomain;
}
Also used : APIMgtInternalException(org.wso2.carbon.apimgt.api.APIMgtInternalException) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) APIMgtBadRequestException(org.wso2.carbon.apimgt.api.APIMgtBadRequestException)

Example 2 with APIMgtBadRequestException

use of org.wso2.carbon.apimgt.api.APIMgtBadRequestException in project carbon-apimgt by wso2.

the class OrganizationInterceptor method handleMessage.

@Override
public void handleMessage(Message message) throws Fault {
    try {
        OrganizationResolver resolver = APIUtil.getOrganizationResolver();
        // populate properties needed for the resolver.
        HashMap<String, Object> properties = new HashMap<String, Object>();
        properties.put(APIConstants.PROPERTY_HEADERS_KEY, message.get(Message.PROTOCOL_HEADERS));
        properties.put(APIConstants.PROPERTY_QUERY_KEY, message.get(Message.QUERY_STRING));
        String organization = resolver.resolve(properties);
        message.put(RestApiConstants.ORGANIZATION, organization);
    } catch (APIManagementException e) {
        if (e instanceof APIMgtBadRequestException) {
            RestApiUtil.handleBadRequest(e.getMessage(), 901300L, logger);
        } else {
            RestApiUtil.handleInternalServerError("Error while resolving the organization resolver", e, logger);
        }
    }
    logger.debug("Organization :" + message.get(RestApiConstants.ORGANIZATION));
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HashMap(java.util.HashMap) OrganizationResolver(org.wso2.carbon.apimgt.api.OrganizationResolver) APIMgtBadRequestException(org.wso2.carbon.apimgt.api.APIMgtBadRequestException)

Aggregations

APIMgtBadRequestException (org.wso2.carbon.apimgt.api.APIMgtBadRequestException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIMgtInternalException (org.wso2.carbon.apimgt.api.APIMgtInternalException)1 OrganizationResolver (org.wso2.carbon.apimgt.api.OrganizationResolver)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1