* Copyright (C) 2017 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
+ * Modifications Copyright (C) 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
-import javax.ws.rs.HttpMethod;
import org.apache.commons.codec.binary.Base64;
import org.onap.ccsdk.sli.adaptors.aai.AAIService.TransactionIdTracker;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
+import org.apache.http.impl.EnglishReasonPhraseCatalog;
/**
* The AAIClientRESTExecutor class provides CRUD API for AAI Client service.
* @author richtabedzki
*/
-public class AAIClientRESTExecutor implements AAIExecutorInterface {
+public class AAIClientRESTExecutor implements AAIExecutorInterface {
private final String truststorePath;
private final String truststorePassword;
private String userName;
private String userPassword;
private final String applicationId;
+ private static final String HTTP_URL_CONNECTION_RESULT="HttpURLConnection result: {} : {}";
/**
* class Constructor
ignoreCertificateHostError = host_error;
- HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
- public boolean verify(String string,SSLSession ssls) {
- return ignoreCertificateHostError;
- }
+ HttpsURLConnection.setDefaultHostnameVerifier( (String string,SSLSession ssls) -> {
+ return ignoreCertificateHostError;
+
});
if(truststorePath != null && truststorePassword != null && (new File(truststorePath)).exists()) {
if(keystorePath != null && keystorePassword != null && (new File(keystorePath)).exists())
{
- DefaultClientConfig config = new DefaultClientConfig();
//both jersey and HttpURLConnection can use this
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
KeyManagerFactory kmf = null;
- try {
+ try (FileInputStream fin = new FileInputStream(keystorePath)){
String storeType = "PKCS12";
String def = KeyStore.getDefaultType();
kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- FileInputStream fin = new FileInputStream(keystorePath);
String extension = keystorePath.substring(keystorePath.lastIndexOf(".") + 1);
}
ctx.init(kmf.getKeyManagers(), null, null);
- config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( new HostnameVerifier() {
- @Override
- public boolean verify( String s, SSLSession sslSession ) {
- return ignoreCertificateHostError;
- }
- }, ctx));
CTX = ctx;
LOG.debug("SSLContext created");
}
private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
+ private static final String NOT_PROVIDED = "NOT PROVIDED";
private final MetricLogger ml = new MetricLogger();
private SSLContext CTX;
}
// Check for errors
- String responseMessage = con.getResponseMessage();
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
+ String responseMessage = null;
+ try {
+ responseMessage = con.getResponseMessage();
+ } catch(Exception exc) {
+ responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+ } finally {
+ if(responseMessage == null)
+ responseMessage = NOT_PROVIDED;
+ }
// Process the response
- LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
+ LOG.info(HTTP_URL_CONNECTION_RESULT, responseCode, responseMessage);
logMetricResponse(responseCode, responseMessage);
if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
osw.flush();
// Check for errors
- String responseMessage = con.getResponseMessage();
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
+ String responseMessage = null;
+ try {
+ responseMessage = con.getResponseMessage();
+ } catch(Exception exc) {
+ responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+ } finally {
+ if(responseMessage == null)
+ responseMessage = NOT_PROVIDED;
+ }
- LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
+ LOG.info(HTTP_URL_CONNECTION_RESULT, responseCode, responseMessage);
logMetricResponse(responseCode, responseMessage);
// Process the response
conn.setDoOutput(true);
// Check for errors
- String responseMessage = conn.getResponseMessage();
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
inputStream = conn.getInputStream();
} else {
inputStream = conn.getErrorStream();
}
+ String responseMessage = null;
+ try {
+ responseMessage = conn.getResponseMessage();
+ } catch(Exception exc) {
+ responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+ } finally {
+ if(responseMessage == null)
+ responseMessage = NOT_PROVIDED;
+ }
// Process the response
- LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
+ LOG.info(HTTP_URL_CONNECTION_RESULT, responseCode, responseMessage);
logMetricResponse(responseCode, responseMessage);
if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
// Check for errors
- String responseMessage = con.getResponseMessage();
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
+ String responseMessage = null;
+ try {
+ responseMessage = con.getResponseMessage();
+ } catch(Exception exc) {
+ responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+ } finally {
+ if(responseMessage == null)
+ responseMessage = NOT_PROVIDED;
+ }
+ LOG.info(HTTP_URL_CONNECTION_RESULT, responseCode, responseMessage);
logMetricResponse(responseCode, responseMessage);
ObjectMapper mapper = AAIService.getObjectMapper();
osw.flush();
// Check for errors
- String responseMessage = con.getResponseMessage();
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
inputStream = con.getInputStream();
} else {
inputStream = con.getErrorStream();
}
+ String responseMessage = null;
+ try {
+ responseMessage = con.getResponseMessage();
+ } catch(Exception exc) {
+ responseMessage = EnglishReasonPhraseCatalog.INSTANCE.getReason(responseCode,null);
+ } finally {
+ if(responseMessage == null)
+ responseMessage = NOT_PROVIDED;
+ }
- LOG.info("HttpURLConnection result: " + responseCode + " : " + responseMessage);
+ LOG.info(HTTP_URL_CONNECTION_RESULT, responseCode, responseMessage);
logMetricResponse(responseCode, responseMessage);
// Process the response