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;
}
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));
}
Aggregations