Search in sources :

Example 41 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class SolaceAdminApis method createApplication.

/**
 * Create new application in Solace
 *
 * @param organization name of the Organization
 * @param application  Application to be created in Solace
 * @param apiProducts  List of API products to add as subscriptions
 * @return CloseableHttpResponse of the POST call
 */
public CloseableHttpResponse createApplication(String organization, Application application, ArrayList<String> apiProducts) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPost httpPost = new HttpPost(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps");
    httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    StringEntity params = null;
    try {
        org.json.JSONObject requestBody = buildRequestBodyForCreatingApp(application, apiProducts);
        params = new StringEntity(requestBody.toString());
        httpPost.setEntity(params);
        return APIUtil.executeHTTPRequest(httpPost, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Example 42 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class SolaceAdminApis method environmentGET.

/**
 * Check whether the environment is available
 *
 * @param organization name of the Organization
 * @param environment  name of the Environment
 * @return CloseableHttpResponse of the GET call
 */
public CloseableHttpResponse environmentGET(String organization, String environment) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpGet httpGet = new HttpGet(baseUrl + "/" + organization + "/" + "environments" + "/" + environment);
    httpGet.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    try {
        return APIUtil.executeHTTPRequest(httpGet, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Example 43 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class SolaceAdminApis method registerAPI.

/**
 * Register API in Solace using AsyncAPI Definition
 *
 * @param organization  name of the Organization
 * @param title         name of the Solace API
 * @param apiDefinition Async definition of the Solace API
 * @return CloseableHttpResponse of the PUT call
 */
public CloseableHttpResponse registerAPI(String organization, String title, String apiDefinition) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPut httpPut = new HttpPut(baseUrl + "/" + organization + "/apis/" + title);
    httpPut.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPut.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain");
    JsonNode jsonNodeTree;
    String jsonAsYaml = null;
    // convert json to yaml
    try {
        jsonNodeTree = new ObjectMapper().readTree(apiDefinition);
        jsonAsYaml = new YAMLMapper().writeValueAsString(jsonNodeTree);
    } catch (JsonProcessingException e) {
        log.error(e.getMessage());
    }
    // add definition to request body
    if (jsonAsYaml != null) {
        StringEntity params = null;
        try {
            params = new StringEntity(jsonAsYaml);
        } catch (UnsupportedEncodingException e) {
            log.error(e.getMessage());
        }
        httpPut.setEntity(params);
        try {
            return APIUtil.executeHTTPRequest(httpPut, httpClient);
        } catch (IOException | APIManagementException e) {
            log.error(e.getMessage());
        }
    }
    return null;
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) URL(org.apache.axis2.util.URL) HttpPut(org.apache.http.client.methods.HttpPut) StringEntity(org.apache.http.entity.StringEntity) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 44 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class SolaceAdminApis method createAPIProduct.

/**
 * Create API Product in Solace using AsyncAPI Definition
 *
 * @param organization           name of the Organization
 * @param environment            name of the Environment
 * @param apiProductName         name of the API product
 * @param apiNameForRegistration name of the Solace API product
 * @param aai20Document          Async definition of the Solace API
 * @return CloseableHttpResponse of the POST call
 */
public CloseableHttpResponse createAPIProduct(String organization, String environment, Aai20Document aai20Document, String apiProductName, String apiNameForRegistration) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPost httpPost = new HttpPost(baseUrl + "/" + organization + "/apiProducts");
    httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    // setRequestBody
    org.json.JSONObject requestBody = buildAPIProductRequestBody(aai20Document, environment, apiProductName, apiNameForRegistration);
    try {
        StringEntity params2;
        params2 = new StringEntity(requestBody.toString());
        httpPost.setEntity(params2);
    } catch (UnsupportedEncodingException e) {
        log.error(e.getMessage());
    }
    try {
        return APIUtil.executeHTTPRequest(httpPost, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Example 45 with URL

use of org.apache.axis2.util.URL in project carbon-apimgt by wso2.

the class SolaceAdminApis method applicationGet.

/**
 * Check existence of application in Solace
 *
 * @param organization name of the Organization
 * @param uuid  Application UUID to be checked in solace
 * @param syntax       protocol type
 * @return CloseableHttpResponse of the GET call
 */
public CloseableHttpResponse applicationGet(String organization, String uuid, String syntax) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpGet httpGet;
    if ("MQTT".equalsIgnoreCase(syntax)) {
        httpGet = new HttpGet(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + uuid + "?topicSyntax=mqtt");
    } else {
        httpGet = new HttpGet(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + uuid);
    }
    httpGet.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    try {
        return APIUtil.executeHTTPRequest(httpGet, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Aggregations

IOException (java.io.IOException)31 EndpointReference (org.apache.axis2.addressing.EndpointReference)29 AxisFault (org.apache.axis2.AxisFault)27 URL (java.net.URL)21 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)19 URL (org.apache.axis2.util.URL)19 HttpClient (org.apache.http.client.HttpClient)19 Options (org.apache.axis2.client.Options)18 MalformedURLException (java.net.MalformedURLException)17 OMElement (org.apache.axiom.om.OMElement)17 MessageContext (org.apache.axis2.context.MessageContext)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 ServiceClient (org.apache.axis2.client.ServiceClient)13 SynapseException (org.apache.synapse.SynapseException)13 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)12 AxisService (org.apache.axis2.description.AxisService)10 StringEntity (org.apache.http.entity.StringEntity)9 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)9 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7