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