Search in sources :

Example 61 with URL

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

the class SolaceAdminApis method deleteApplication.

/**
 * Delete application from Solace Broker
 *
 * @param organization name of the Organization
 * @param uuid         UUID of Application object to be deleted
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse deleteApplication(String organization, String uuid) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpDelete httpDelete = new HttpDelete(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + uuid);
    httpDelete.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    try {
        return APIUtil.executeHTTPRequest(httpDelete, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) URL(org.apache.axis2.util.URL)

Example 62 with URL

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

the class SolaceAdminApis method patchClientIdForApplication.

/**
 * Patch client ID for Solace application
 *
 * @param organization name of the Organization
 * @param application  Application object to be renamed
 * @param consumerKey  Consumer key to be used when patching
 * @param consumerSecret Consumer secret to be used when patching
 * @return CloseableHttpResponse of the PATCH call
 */
public CloseableHttpResponse patchClientIdForApplication(String organization, Application application, String consumerKey, String consumerSecret) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPatch httpPatch = new HttpPatch(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + application.getUUID());
    httpPatch.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    org.json.JSONObject requestBody = buildRequestBodyForClientIdPatch(application, consumerKey, consumerSecret);
    StringEntity params = null;
    try {
        params = new StringEntity(requestBody.toString());
        httpPatch.setEntity(params);
        return APIUtil.executeHTTPRequest(httpPatch, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : 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) HttpPatch(org.apache.http.client.methods.HttpPatch)

Example 63 with URL

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

the class SolaceAdminApis method apiProductGet.

/**
 * Check existence of API Product in Solace
 *
 * @param organization   name of the Organization
 * @param apiProductName name of the API Product
 * @return CloseableHttpResponse of the GET call
 */
public CloseableHttpResponse apiProductGet(String organization, String apiProductName) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpGet httpGet = new HttpGet(baseUrl + "/" + organization + "/apiProducts/" + apiProductName);
    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 64 with URL

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

the class SolaceAdminApis method applicationPatchRemoveSubscription.

/**
 * Remove subscriptions to application in Solace and update the application
 *
 * @param organization        name of the Organization
 * @param application         Application to be checked in solace
 * @param apiProductsToRemove List of API products to remove from subscriptions
 * @return CloseableHttpResponse of the PATCH call
 */
public CloseableHttpResponse applicationPatchRemoveSubscription(String organization, Application application, List<String> apiProductsToRemove) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpPatch httpPatch = new HttpPatch(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + application.getUUID());
    httpPatch.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
    httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
    // retrieve existing API products in the app
    ArrayList<String> apiProducts = new ArrayList<>();
    try {
        apiProducts = retrieveApiProductsInAnApplication(applicationGet(organization, application.getUUID(), "default"), apiProducts);
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    // remove API product from arrayList
    apiProducts.removeAll(apiProductsToRemove);
    org.json.JSONObject requestBody = buildRequestBodyForApplicationPatchSubscriptions(apiProducts);
    StringEntity params = null;
    try {
        params = new StringEntity(requestBody.toString());
        httpPatch.setEntity(params);
        return APIUtil.executeHTTPRequest(httpPatch, httpClient);
    } catch (IOException | APIManagementException e) {
        log.error(e.getMessage());
    }
    return null;
}
Also used : StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpClient(org.apache.http.client.HttpClient) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(org.apache.axis2.util.URL) HttpPatch(org.apache.http.client.methods.HttpPatch)

Example 65 with URL

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

the class SolaceAdminApis method registeredAPIGet.

/**
 * Check existence of API in Solace
 *
 * @param organization name of the Organization
 * @param apiTitle     name of the API
 * @return CloseableHttpResponse of the GET call
 */
public CloseableHttpResponse registeredAPIGet(String organization, String apiTitle) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpGet httpGet = new HttpGet(baseUrl + "/" + organization + "/apis/" + apiTitle);
    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