2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.sli.adaptors.aai;
24 import java.io.BufferedReader;
25 import java.io.ByteArrayInputStream;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
30 import java.io.OutputStreamWriter;
31 import java.lang.reflect.Field;
32 import java.lang.reflect.InvocationTargetException;
33 import java.lang.reflect.Method;
34 import java.lang.reflect.Modifier;
35 import java.net.HttpURLConnection;
36 import java.net.MalformedURLException;
38 import java.nio.charset.StandardCharsets;
39 import java.security.KeyManagementException;
40 import java.security.KeyStore;
41 import java.security.NoSuchAlgorithmException;
42 import java.text.SimpleDateFormat;
43 import java.util.Properties;
45 import javax.net.ssl.HostnameVerifier;
46 import javax.net.ssl.HttpsURLConnection;
47 import javax.net.ssl.KeyManagerFactory;
48 import javax.net.ssl.SSLContext;
49 import javax.net.ssl.SSLSession;
50 import javax.net.ssl.SSLSocketFactory;
51 import javax.ws.rs.HttpMethod;
53 import org.apache.commons.codec.binary.Base64;
54 import org.onap.ccsdk.sli.adaptors.aai.AAIService.TransactionIdTracker;
55 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
56 import org.onap.ccsdk.sli.adaptors.aai.data.ErrorResponse;
57 import org.onap.ccsdk.sli.adaptors.aai.data.RequestError;
58 import org.onap.ccsdk.sli.adaptors.aai.data.ResourceVersion;
59 import org.onap.ccsdk.sli.adaptors.aai.data.ServiceException;
60 import org.onap.ccsdk.sli.core.sli.MetricLogger;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
64 import com.fasterxml.jackson.databind.DeserializationFeature;
65 import com.fasterxml.jackson.databind.ObjectMapper;
66 import com.sun.jersey.api.client.config.DefaultClientConfig;
67 import com.sun.jersey.client.urlconnection.HTTPSProperties;
70 * The AAIClientRESTExecutor class provides CRUD API for AAI Client service.
71 * @author richtabedzki
73 public class AAIClientRESTExecutor implements AAIExecutorInterface {
75 private final String truststorePath;
76 private final String truststorePassword;
77 private final String keystorePath;
78 private final String keystorePassword;
79 private final Boolean ignoreCertificateHostError;
80 // authentication credentials
81 private String userName;
82 private String userPassword;
83 private final String applicationId;
87 * @param props - properties to initialize an instance.
89 public AAIClientRESTExecutor(Properties props) {
92 userName = props.getProperty(AAIService.CLIENT_NAME);
93 userPassword = props.getProperty(AAIService.CLIENT_PWWD);
95 if(userName == null || userName.isEmpty()){
96 LOG.debug("Basic user name is not set");
98 if(userPassword == null || userPassword.isEmpty()) {
99 LOG.debug("Basic password is not set");
102 truststorePath = props.getProperty(AAIService.TRUSTSTORE_PATH);
103 truststorePassword = props.getProperty(AAIService.TRUSTSTORE_PSSWD);
104 keystorePath = props.getProperty(AAIService.KEYSTORE_PATH);
105 keystorePassword = props.getProperty(AAIService.KEYSTORE_PSSWD);
106 // this.read_timeout = read_timeout;
108 String tmpApplicationId =props.getProperty(AAIService.APPLICATION_ID);
109 if(tmpApplicationId == null || tmpApplicationId.isEmpty()) {
110 tmpApplicationId = "SDNC";
112 applicationId = tmpApplicationId;
114 String iche = props.getProperty(AAIService.CERTIFICATE_HOST_ERROR);
115 boolean host_error = false;
116 if(iche != null && !iche.isEmpty()) {
117 host_error = Boolean.valueOf(iche);
120 ignoreCertificateHostError = host_error;
122 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
123 public boolean verify(String string,SSLSession ssls) {
124 return ignoreCertificateHostError;
128 if(truststorePath != null && truststorePassword != null && (new File(truststorePath)).exists()) {
129 System.setProperty("javax.net.ssl.trustStore", truststorePath);
130 System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
133 if(keystorePath != null && keystorePassword != null && (new File(keystorePath)).exists())
135 DefaultClientConfig config = new DefaultClientConfig();
136 //both jersey and HttpURLConnection can use this
137 SSLContext ctx = null;
139 ctx = SSLContext.getInstance("TLS");
141 KeyManagerFactory kmf = null;
143 String storeType = "PKCS12";
144 String def = KeyStore.getDefaultType();
145 kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
146 FileInputStream fin = new FileInputStream(keystorePath);
148 String extension = keystorePath.substring(keystorePath.lastIndexOf(".") + 1);
150 if(extension != null && !extension.isEmpty() && extension.equalsIgnoreCase("JKS")) {
153 KeyStore ks = KeyStore.getInstance(storeType);
155 char[] pwd = keystorePassword.toCharArray();
158 } catch (Exception ex) {
159 LOG.error("AAIResource", ex);
162 ctx.init(kmf.getKeyManagers(), null, null);
163 config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( new HostnameVerifier() {
165 public boolean verify( String s, SSLSession sslSession ) {
166 return ignoreCertificateHostError;
171 LOG.debug("SSLContext created");
173 } catch (KeyManagementException | NoSuchAlgorithmException exc) {
174 LOG.error("AAIResource", exc);
179 Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
180 methodsField.setAccessible(true);
181 // get the methods field modifiers
182 Field modifiersField = Field.class.getDeclaredField("modifiers");
183 // bypass the "private" modifier
184 modifiersField.setAccessible(true);
186 // remove the "final" modifier
187 modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
189 /* valid HTTP methods */
191 "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
193 // set the new methods - including patch
194 methodsField.set(null, methods);
196 } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
197 LOG.warn("Adding PATCH method", e);
199 LOG.info("AAIResource.ctor initialized.");
203 private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
204 private final MetricLogger ml = new MetricLogger();
206 private SSLContext CTX;
209 private int connection_timeout = 300000;
211 private int read_timeout = 300000;
214 * Returns an String that contains JSON data returned from the AAI Server.
216 * This method always returns immediately, whether or not the
219 * @param request an instance of AAIRequiest representing
220 * the request made by DirectedGraph node.
221 * @return the JSON based representation of data instance requested.
225 public String get(AAIRequest request) throws AAIServiceException {
226 String response = null;
227 InputStream inputStream = null;
228 HttpURLConnection con = null;
229 URL requestUrl = null;
231 StringBuilder errorStringBuilder = new StringBuilder();
235 if(request.getRequestObject() != null) {
236 requestUrl = request.getRequestUrl(HttpMethod.POST, null);
237 requestUrl = appendDepth(requestUrl, request);
238 con = getConfiguredConnection(requestUrl, HttpMethod.POST);
239 String json_text = request.toJSONString();
240 LOGwriteDateTrace("data", json_text);
241 logMetricRequest("POST "+requestUrl.getPath(), json_text, requestUrl.getPath());
242 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
243 osw.write(json_text);
246 requestUrl = request.getRequestUrl(HttpMethod.GET, null);
247 requestUrl = appendDepth(requestUrl, request);
248 con = getConfiguredConnection(requestUrl, HttpMethod.GET);
249 logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
253 String responseMessage = con.getResponseMessage();
254 int responseCode = con.getResponseCode();
255 if (responseCode == HttpURLConnection.HTTP_OK) {
256 inputStream = con.getInputStream();
258 inputStream = con.getErrorStream();
261 // Process the response
262 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
263 logMetricResponse(responseCode, responseMessage);
265 if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
266 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
268 ObjectMapper mapper = AAIService.getObjectMapper();
270 if (responseCode == HttpURLConnection.HTTP_OK) {
271 StringBuilder stringBuilder = new StringBuilder();
273 while( ( line = reader.readLine() ) != null ) {
274 stringBuilder.append( line );
276 response = stringBuilder.toString();
278 Object object = mapper.readValue(response, Object.class);
279 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, responseMessage, mapper.writeValueAsString(object));
280 } catch(Exception exc) {
281 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, responseMessage, mapper.writeValueAsString(response));
283 } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
284 LOGwriteEndingTrace(responseCode, responseMessage, "Entry does not exist.");
285 ErrorResponse errorresponse = null;
287 errorresponse = mapper.readValue(reader, ErrorResponse.class);
288 } catch(Exception exc) {
289 errorresponse = new ErrorResponse();
290 RequestError requestError = new RequestError();
291 ServiceException serviceException = new ServiceException();
292 serviceException.setText("Entry does not exist.");
293 requestError.setServiceException(serviceException);
294 errorresponse.setRequestError(requestError );
296 throw new AAIServiceException(responseCode, errorresponse);
297 } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
298 StringBuilder stringBuilder = new StringBuilder();
300 while( ( line = reader.readLine() ) != null ) {
301 stringBuilder.append( line );
303 LOGwriteEndingTrace(responseCode, responseMessage, stringBuilder.toString());
304 ServiceException serviceException = new ServiceException();
305 serviceException.setMessageId("HTTP_UNAUTHORIZED");
306 serviceException.setText(stringBuilder.toString());
307 RequestError requestError = new RequestError();
308 requestError.setServiceException(serviceException);
309 ErrorResponse errorresponse = new ErrorResponse();
310 errorresponse.setRequestError(requestError);
311 throw new AAIServiceException(responseCode, errorresponse);
313 // StringBuilder errorStringBuilder = new StringBuilder();
315 while( ( line = reader.readLine() ) != null ) {
316 errorStringBuilder.append("\n").append( line );
319 ErrorResponse errorresponse = mapper.readValue(errorStringBuilder.toString(), ErrorResponse.class);
320 // ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
321 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
322 throw new AAIServiceException(responseCode, errorresponse);
325 } catch(AAIServiceException aaiexc) {
327 } catch (Exception exc) {
328 LOG.warn(errorStringBuilder.toString(), exc);
329 throw new AAIServiceException(exc);
331 if(inputStream != null){
334 } catch(Exception exc) {
343 * Returns an String that contains JSON data returned from the AAI Server.
345 * This method always returns immediately, whether or not the
348 * @param request an instance of AAIRequiest representing
349 * the request made by DirectedGraph node.
350 * @return the JSON based representation of data instance requested.
354 public String post(AAIRequest request) throws AAIServiceException {
355 InputStream inputStream = null;
358 String resourceVersion = null;
359 AAIDatum instance = request.getRequestObject();
362 Method getResourceVersionMethod = instance.getClass().getMethod("getResourceVersion");
363 if(getResourceVersionMethod != null){
365 Object object = getResourceVersionMethod.invoke(instance);
367 resourceVersion = object.toString();
368 } catch (InvocationTargetException x) {
369 Throwable cause = x.getCause();
372 } catch(Exception exc) {
376 URL requestUrl = null;
377 HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion), HttpMethod.PUT);
378 ObjectMapper mapper = AAIService.getObjectMapper();
379 String json_text = request.toJSONString();
381 LOGwriteDateTrace("data", json_text);
382 logMetricRequest("PUT "+requestUrl.getPath(), json_text, requestUrl.getPath());
384 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
385 osw.write(json_text);
389 String responseMessage = con.getResponseMessage();
390 int responseCode = con.getResponseCode();
391 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
392 inputStream = con.getInputStream();
394 inputStream = con.getErrorStream();
397 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
398 logMetricResponse(responseCode, responseMessage);
400 // Process the response
401 BufferedReader reader;
403 reader = new BufferedReader( new InputStreamReader( inputStream ) );
404 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
406 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
407 StringBuilder stringBuilder = new StringBuilder();
409 while( ( line = reader.readLine() ) != null ) {
410 stringBuilder.append( line );
412 LOGwriteEndingTrace(responseCode, responseMessage, (stringBuilder.length() > 0) ? stringBuilder.toString() : "{no-data}");
413 return stringBuilder.toString();
415 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
416 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
418 throw new AAIServiceException(responseCode, errorresponse);
420 } catch(AAIServiceException aaiexc) {
422 } catch (Exception exc) {
423 LOG.warn("AAIRequestExecutor.post", exc);
424 throw new AAIServiceException(exc);
427 if(inputStream != null)
429 } catch (Exception exc) {
436 * Returns Boolean that contains completion state of the command executed.
438 * This method always returns immediately, whether or not the
441 * @param request an instance of AAIRequiest representing
442 * @param resourceVersion a resource version of the data instacne to be deleted.
443 * the request made by DirectedGraph node.
444 * @return completion state of the command.
448 public Boolean delete(AAIRequest request, String resourceVersion) throws AAIServiceException {
449 Boolean response = null;
450 InputStream inputStream = null;
452 if(resourceVersion == null) {
453 throw new AAIServiceException("resource-version is required for DELETE request");
457 URL requestUrl = null;
458 HttpURLConnection conn = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion), HttpMethod.DELETE);
459 logMetricRequest("DELETE "+requestUrl.getPath(), "", requestUrl.getPath());
460 conn.setDoOutput(true);
463 String responseMessage = conn.getResponseMessage();
464 int responseCode = conn.getResponseCode();
465 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
466 inputStream = conn.getInputStream();
468 inputStream = conn.getErrorStream();
471 // Process the response
472 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
473 logMetricResponse(responseCode, responseMessage);
475 if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
476 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
479 ObjectMapper mapper = AAIService.getObjectMapper();
481 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
482 StringBuilder stringBuilder = new StringBuilder();
484 while( ( line = reader.readLine() ) != null ) {
485 stringBuilder.append( line );
487 LOGwriteEndingTrace(responseCode, responseMessage, stringBuilder.toString());
489 } else if(responseCode == HttpURLConnection.HTTP_NOT_FOUND ) {
490 LOGwriteEndingTrace(responseCode, responseMessage, "Entry does not exist.");
493 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
494 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
495 throw new AAIServiceException(responseCode, errorresponse);
497 } catch(AAIServiceException aaiexc) {
499 } catch (Exception exc) {
500 LOG.warn("delete", exc);
501 throw new AAIServiceException(exc);
503 if(inputStream != null){
506 } catch(Exception exc) {
515 * Returns an String that contains JSON data returned from the AAI Server.
517 * This method always returns immediately, whether or not the
520 * @param request an instance of AAIRequiest representing
521 * the request made by DirectedGraph node.
522 * @param clas an definition of the class for which data will be returned
523 * @return the instance of the class with data.
527 public Object query(AAIRequest request, Class clas) throws AAIServiceException {
528 Object response = null;
529 InputStream inputStream = null;
530 HttpURLConnection con = null;
531 URL requestUrl = null;
534 con = getConfiguredConnection(requestUrl = request.getRequestQueryUrl(HttpMethod.GET), HttpMethod.GET);
535 logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
538 String responseMessage = con.getResponseMessage();
539 int responseCode = con.getResponseCode();
540 if (responseCode == HttpURLConnection.HTTP_OK) {
541 inputStream = con.getInputStream();
543 inputStream = con.getErrorStream();
546 logMetricResponse(responseCode, responseMessage);
547 ObjectMapper mapper = AAIService.getObjectMapper();
549 if (responseCode == HttpURLConnection.HTTP_OK) {
550 // Process the response
551 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
552 response = mapper.readValue(reader, clas);
553 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, "SUCCESS", mapper.writeValueAsString(response));
554 } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
555 LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist.");
558 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
559 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
560 LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
561 throw new AAIServiceException(responseCode, errorresponse);
564 } catch(AAIServiceException aaiexc) {
566 } catch (Exception exc) {
567 LOG.warn("GET", exc);
568 throw new AAIServiceException(exc);
570 if(inputStream != null){
573 } catch(Exception exc) {
583 public Boolean patch(AAIRequest request, String resourceVersion) throws AAIServiceException {
584 InputStream inputStream = null;
587 AAIDatum instance = request.getRequestObject();
588 if(instance instanceof ResourceVersion) {
589 resourceVersion = ((ResourceVersion)instance).getResourceVersion();
592 URL requestUrl = null;
593 HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl("PATCH", resourceVersion), "PATCH");
594 ObjectMapper mapper = AAIService.getObjectMapper();
595 String json_text = request.toJSONString();
597 LOGwriteDateTrace("data", json_text);
598 logMetricRequest("PATCH "+requestUrl.getPath(), json_text, requestUrl.getPath());
600 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
601 osw.write(json_text);
605 String responseMessage = con.getResponseMessage();
606 int responseCode = con.getResponseCode();
607 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
608 inputStream = con.getInputStream();
610 inputStream = con.getErrorStream();
613 LOG.info("HttpURLConnection result: " + responseCode + " : " + responseMessage);
614 logMetricResponse(responseCode, responseMessage);
616 // Process the response
617 BufferedReader reader;
619 reader = new BufferedReader( new InputStreamReader( inputStream ) );
620 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
622 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
623 StringBuilder stringBuilder = new StringBuilder();
625 while( ( line = reader.readLine() ) != null ) {
626 stringBuilder.append( line );
628 LOGwriteEndingTrace(responseCode, responseMessage, (stringBuilder != null) ? stringBuilder.toString() : "{no-data}");
631 StringBuilder stringBuilder = new StringBuilder();
633 while( ( line = reader.readLine() ) != null ) {
634 stringBuilder.append("\n").append( line );
636 LOG.info(stringBuilder.toString());
639 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
640 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
642 throw new AAIServiceException(responseCode, errorresponse);
644 } catch(AAIServiceException aaiexc) {
646 } catch (Exception exc) {
647 LOG.warn("AAIRequestExecutor.patch", exc);
648 throw new AAIServiceException(exc);
651 if(inputStream != null)
653 } catch (Exception exc) {
666 protected HttpURLConnection getConfiguredConnection(URL httpReqUrl, String method) throws Exception {
667 HttpURLConnection con = (HttpURLConnection) httpReqUrl.openConnection();
669 // Set up the connection properties
670 con.setRequestProperty("Connection", "close");
671 con.setDoInput(true);
672 con.setDoOutput(true);
673 con.setUseCaches(false);
674 con.setConnectTimeout(connection_timeout);
675 con.setReadTimeout(read_timeout);
676 con.setRequestMethod(method);
677 con.setRequestProperty("Accept", "application/json");
678 con.setRequestProperty("Transfer-Encoding","chunked");
679 con.setRequestProperty("Content-Type",
680 "PATCH".equalsIgnoreCase(method) ? "application/merge-patch+json" : "application/json");
681 con.setRequestProperty("X-FromAppId", applicationId);
682 con.setRequestProperty("X-TransactionId", TransactionIdTracker.getNextTransactionId());
683 String mlId = ml.getRequestID();
684 if (mlId != null && !mlId.isEmpty()) {
685 LOG.debug(String.format("MetricLogger requestId = %s", mlId));
686 con.setRequestProperty(MetricLogger.REQUEST_ID, mlId);
688 LOG.debug("MetricLogger requestId is null");
691 if (userName != null && !userName.isEmpty() && userPassword != null && !userPassword.isEmpty()) {
692 String basicAuth = "Basic " + new String(Base64.encodeBase64((userName + ":" + userPassword).getBytes()));
693 con.setRequestProperty("Authorization", basicAuth);
696 if (con instanceof HttpsURLConnection && CTX != null) {
697 SSLSocketFactory sockFact = CTX.getSocketFactory();
698 HttpsURLConnection.class.cast(con).setSSLSocketFactory(sockFact);
703 private URL appendDepth(URL requestUrl, AAIRequest request) throws MalformedURLException {
705 String depth = request.requestProperties.getProperty("depth", "1");
706 String path = requestUrl.toString();
707 if(path.contains("?depth=") || path.contains("&depth=")) {
710 if(path.contains("?")) {
711 path = String.format("%s&depth=%s", path, depth);
713 path = String.format("%s?depth=%s", path, depth);
715 return new URL(path);
719 public void logMetricRequest(String targetServiceName, String msg, String path){
720 String svcInstanceId = "";
721 String svcName = null;
722 String partnerName = null;
723 String targetEntity = "A&AI";
724 String targetVirtualEntity = null;
726 targetServiceName = "";
728 ml.logRequest(svcInstanceId, svcName, partnerName, targetEntity, targetServiceName, targetVirtualEntity, msg);
731 public void logMetricResponse(int responseCode, String responseDescription){
732 ml.logResponse(responseCode < 400 ? "SUCCESS" : "FAILURE", Integer.toString(responseCode), responseDescription);
735 protected void LOGwriteFirstTrace(String method, String url) {
736 String time = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(System.currentTimeMillis());
737 LOG.info("A&AI transaction :");
738 LOG.info("Request Time : " + time + ", Method : " + method);
739 LOG.info("Request URL : "+ url);
742 protected void LOGwriteDateTrace(String name, String data) {
743 LOG.info("Input - " + name + " : " + data);
746 protected void LOGwriteEndingTrace(int response_code, String comment, String data) {
747 LOG.info("Response code : " + response_code +", " + comment);
748 LOG.info(String.format("Response data : %s", data));