Search in sources :

Example 1 with OrganizationResolver

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

the class RestApiUtil method resolveOrganization.

/**
 * Method to resolve the organization
 * @param message Message
 * @return organization
 */
public static String resolveOrganization(Message message) throws APIManagementException {
    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);
    return organization;
}
Also used : HashMap(java.util.HashMap) OrganizationResolver(org.wso2.carbon.apimgt.api.OrganizationResolver) JSONObject(org.json.simple.JSONObject)

Example 2 with OrganizationResolver

use of org.wso2.carbon.apimgt.api.OrganizationResolver 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)

Example 3 with OrganizationResolver

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

the class RestApiUtil method resolveOrganization.

public static String resolveOrganization(HashMap<String, Object> message) throws APIManagementException {
    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);
    return organization;
}
Also used : HashMap(java.util.HashMap) OrganizationResolver(org.wso2.carbon.apimgt.api.OrganizationResolver) JSONObject(org.json.simple.JSONObject)

Aggregations

HashMap (java.util.HashMap)3 OrganizationResolver (org.wso2.carbon.apimgt.api.OrganizationResolver)3 JSONObject (org.json.simple.JSONObject)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 APIMgtBadRequestException (org.wso2.carbon.apimgt.api.APIMgtBadRequestException)1