Search in sources :

Example 46 with URL

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

the class SolaceAdminApis method deleteRegisteredAPI.

/**
 * Delete registered API from Solace
 *
 * @param organization name of the Organization
 * @param title        name of the API
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse deleteRegisteredAPI(String organization, String title) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpDelete httpDelete = new HttpDelete(baseUrl + "/" + organization + "/apis/" + title);
    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 47 with URL

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

the class SolaceAdminApis method renameApplication.

/**
 * Rename application in Solace Broker
 *
 * @param organization name of the Organization
 * @param application  Application object to be renamed
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse renameApplication(String organization, Application application) {
    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 = buildRequestBodyForRenamingApp(application);
    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 48 with URL

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

the class SolaceAdminApis method deleteApiProduct.

/**
 * Delete API Product from Solace Broker
 *
 * @param organization   name of the Organization
 * @param apiProductName name of the API product
 * @return CloseableHttpResponse of the DELETE call
 */
public CloseableHttpResponse deleteApiProduct(String organization, String apiProductName) {
    URL serviceEndpointURL = new URL(baseUrl);
    HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
    HttpDelete httpDelete = new HttpDelete(baseUrl + "/" + organization + "/apiProducts/" + apiProductName);
    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 49 with URL

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

the class SolaceAdminApis method developerGet.

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

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

the class SolaceAdminApis method applicationPatchAddSubscription.

/**
 * Add subscriptions to application in Solace and update the application
 *
 * @param organization name of the Organization
 * @param application  Application to be checked in solace
 * @param apiProducts  API products to add as subscriptions
 * @return CloseableHttpResponse of the PATCH call
 */
public CloseableHttpResponse applicationPatchAddSubscription(String organization, Application application, ArrayList<String> apiProducts) {
    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
    try {
        apiProducts = retrieveApiProductsInAnApplication(applicationGet(organization, application.getUUID(), "default"), apiProducts);
    } catch (IOException e) {
        log.error(e.getMessage());
    }
    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) IOException(java.io.IOException) URL(org.apache.axis2.util.URL) HttpPatch(org.apache.http.client.methods.HttpPatch)

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