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.net.ssl.TrustManager;
52 import javax.ws.rs.HttpMethod;
54 import org.apache.commons.codec.binary.Base64;
55 import org.onap.ccsdk.sli.adaptors.aai.AAIService.TransactionIdTracker;
56 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
57 import org.onap.ccsdk.sli.adaptors.aai.data.ErrorResponse;
58 import org.onap.ccsdk.sli.adaptors.aai.data.RequestError;
59 import org.onap.ccsdk.sli.adaptors.aai.data.ResourceVersion;
60 import org.onap.ccsdk.sli.adaptors.aai.data.ServiceException;
61 import org.onap.ccsdk.sli.core.sli.MetricLogger;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
65 import com.fasterxml.jackson.databind.DeserializationFeature;
66 import com.fasterxml.jackson.databind.ObjectMapper;
67 import com.sun.jersey.api.client.config.DefaultClientConfig;
68 import com.sun.jersey.client.urlconnection.HTTPSProperties;
70 public class AAIClientRESTExecutor implements AAIExecutorInterface {
72 private final String truststorePath;
73 private final String truststorePassword;
74 private final String keystorePath;
75 private final String keystorePassword;
76 private final Boolean ignoreCertificateHostError;
77 // authentication credentials
78 private String userName;
79 private String userPassword;
80 private final String applicationId;
82 public AAIClientRESTExecutor(Properties props) {
85 userName = props.getProperty(AAIService.CLIENT_NAME);
86 userPassword = props.getProperty(AAIService.CLIENT_PWWD);
88 if(userName == null || userName.isEmpty()){
89 LOG.debug("Basic user name is not set");
91 if(userPassword == null || userPassword.isEmpty()) {
92 LOG.debug("Basic password is not set");
95 truststorePath = props.getProperty(AAIService.TRUSTSTORE_PATH);
96 truststorePassword = props.getProperty(AAIService.TRUSTSTORE_PSSWD);
97 keystorePath = props.getProperty(AAIService.KEYSTORE_PATH);
98 keystorePassword = props.getProperty(AAIService.KEYSTORE_PSSWD);
99 // this.read_timeout = read_timeout;
101 String tmpApplicationId =props.getProperty(AAIService.APPLICATION_ID);
102 if(tmpApplicationId == null || tmpApplicationId.isEmpty()) {
103 tmpApplicationId = "SDNC";
105 applicationId = tmpApplicationId;
107 String iche = props.getProperty(AAIService.CERTIFICATE_HOST_ERROR);
108 boolean host_error = false;
109 if(iche != null && !iche.isEmpty()) {
110 host_error = Boolean.valueOf(iche);
113 ignoreCertificateHostError = host_error;
115 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
116 public boolean verify(String string,SSLSession ssls) {
117 return ignoreCertificateHostError;
121 if(truststorePath != null && truststorePassword != null && (new File(truststorePath)).exists()) {
122 System.setProperty("javax.net.ssl.trustStore", truststorePath);
123 System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
126 // MyX509ExtendedTrustManager trustManager = null;
128 // trustManager = new MyX509ExtendedTrustManager();
129 // } catch (Exception e1) {
130 // // TODO Auto-generated catch block
131 // e1.printStackTrace();
134 // TrustManager[] trustManagers = {trustManager};
136 if(keystorePath != null && keystorePassword != null && (new File(keystorePath)).exists())
138 DefaultClientConfig config = new DefaultClientConfig();
139 //both jersey and HttpURLConnection can use this
140 SSLContext ctx = null;
142 ctx = SSLContext.getInstance("TLS");
144 KeyManagerFactory kmf = null;
146 String def = "SunX509";
147 String storeType = "PKCS12";
148 def = KeyStore.getDefaultType();
149 kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
150 FileInputStream fin = new FileInputStream(keystorePath);
151 // KeyStore ks = KeyStore.getInstance("PKCS12");
153 String extension = keystorePath.substring(keystorePath.lastIndexOf(".") + 1);
155 if(extension != null && !extension.isEmpty() && extension.equalsIgnoreCase("JKS")) {
158 KeyStore ks = KeyStore.getInstance(storeType);
160 char[] pwd = keystorePassword.toCharArray();
163 } catch (Exception ex) {
164 LOG.error("AAIResource", ex);
167 ctx.init(kmf.getKeyManagers(), null, null);
168 config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( new HostnameVerifier() {
170 public boolean verify( String s, SSLSession sslSession ) {
171 return ignoreCertificateHostError;
176 LOG.debug("SSLContext created");
178 } catch (KeyManagementException | NoSuchAlgorithmException exc) {
179 LOG.error("AAIResource", exc);
184 Field methodsField = HttpURLConnection.class.getDeclaredField("methods");
185 methodsField.setAccessible(true);
186 // get the methods field modifiers
187 Field modifiersField = Field.class.getDeclaredField("modifiers");
188 // bypass the "private" modifier
189 modifiersField.setAccessible(true);
191 // remove the "final" modifier
192 modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);
194 /* valid HTTP methods */
196 "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE", "PATCH"
198 // set the new methods - including patch
199 methodsField.set(null, methods);
201 } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) {
204 LOG.info("AAIResource.ctor initialized.");
208 private static final Logger LOG = LoggerFactory.getLogger(AAIService.class);
209 private final MetricLogger ml = new MetricLogger();
211 private SSLContext CTX;
214 private int connection_timeout = 300000;
216 private int read_timeout = 300000;
219 * Returns an String that contains JSON data returned from the AAI Server.
221 * This method always returns immediately, whether or not the
224 * @param request an instance of AAIRequiest representing
225 * the request made by DirectedGraph node.
226 * @return the JSON based representation of data instance requested.
230 public String get(AAIRequest request) throws AAIServiceException {
231 String response = null;
232 InputStream inputStream = null;
233 HttpURLConnection con = null;
234 URL requestUrl = null;
236 StringBuilder errorStringBuilder = new StringBuilder();
240 if(request.getRequestObject() != null) {
241 requestUrl = request.getRequestUrl(HttpMethod.POST, null);
242 requestUrl = appendDepth(requestUrl, request);
243 con = getConfiguredConnection(requestUrl, HttpMethod.POST);
244 String json_text = request.toJSONString();
245 LOGwriteDateTrace("data", json_text);
246 logMetricRequest("POST "+requestUrl.getPath(), json_text, requestUrl.getPath());
247 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
248 osw.write(json_text);
251 requestUrl = request.getRequestUrl(HttpMethod.GET, null);
252 requestUrl = appendDepth(requestUrl, request);
253 con = getConfiguredConnection(requestUrl, HttpMethod.GET);
254 logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
258 String responseMessage = con.getResponseMessage();
259 int responseCode = con.getResponseCode();
260 if (responseCode == HttpURLConnection.HTTP_OK) {
261 inputStream = con.getInputStream();
263 inputStream = con.getErrorStream();
266 // Process the response
267 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
268 logMetricResponse(responseCode, responseMessage);
270 if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
271 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
273 ObjectMapper mapper = AAIService.getObjectMapper();
275 if (responseCode == HttpURLConnection.HTTP_OK) {
276 StringBuilder stringBuilder = new StringBuilder();
278 while( ( line = reader.readLine() ) != null ) {
279 stringBuilder.append( line );
281 response = stringBuilder.toString();
283 Object object = mapper.readValue(response, Object.class);
284 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, responseMessage, mapper.writeValueAsString(object));
285 } catch(Exception exc) {
286 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, responseMessage, mapper.writeValueAsString(response));
288 } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
289 LOGwriteEndingTrace(responseCode, responseMessage, "Entry does not exist.");
290 ErrorResponse errorresponse = null;
292 errorresponse = mapper.readValue(reader, ErrorResponse.class);
293 } catch(Exception exc) {
294 errorresponse = new ErrorResponse();
295 RequestError requestError = new RequestError();
296 ServiceException serviceException = new ServiceException();
297 serviceException.setText("Entry does not exist.");
298 requestError.setServiceException(serviceException);
299 errorresponse.setRequestError(requestError );
301 throw new AAIServiceException(responseCode, errorresponse);
302 } else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
303 StringBuilder stringBuilder = new StringBuilder();
305 while( ( line = reader.readLine() ) != null ) {
306 stringBuilder.append( line );
308 LOGwriteEndingTrace(responseCode, responseMessage, stringBuilder.toString());
309 ServiceException serviceException = new ServiceException();
310 serviceException.setMessageId("HTTP_UNAUTHORIZED");
311 serviceException.setText(stringBuilder.toString());
312 RequestError requestError = new RequestError();
313 requestError.setServiceException(serviceException);
314 ErrorResponse errorresponse = new ErrorResponse();
315 errorresponse.setRequestError(requestError);
316 throw new AAIServiceException(responseCode, errorresponse);
318 // StringBuilder errorStringBuilder = new StringBuilder();
320 while( ( line = reader.readLine() ) != null ) {
321 errorStringBuilder.append("\n").append( line );
324 ErrorResponse errorresponse = mapper.readValue(errorStringBuilder.toString(), ErrorResponse.class);
325 // ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
326 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
327 throw new AAIServiceException(responseCode, errorresponse);
330 } catch(AAIServiceException aaiexc) {
332 } catch (Exception exc) {
333 LOG.warn(errorStringBuilder.toString(), exc);
334 throw new AAIServiceException(exc);
336 if(inputStream != null){
339 } catch(Exception exc) {
348 public String post(AAIRequest request) throws AAIServiceException {
349 InputStream inputStream = null;
352 String resourceVersion = null;
353 AAIDatum instance = request.getRequestObject();
356 Method getResourceVersionMethod = instance.getClass().getMethod("getResourceVersion");
357 if(getResourceVersionMethod != null){
359 Object object = getResourceVersionMethod.invoke(instance);
361 resourceVersion = object.toString();
362 } catch (InvocationTargetException x) {
363 Throwable cause = x.getCause();
366 } catch(Exception exc) {
370 URL requestUrl = null;
371 HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.PUT, resourceVersion), HttpMethod.PUT);
372 ObjectMapper mapper = AAIService.getObjectMapper();
373 String json_text = request.toJSONString();
375 LOGwriteDateTrace("data", json_text);
376 logMetricRequest("PUT "+requestUrl.getPath(), json_text, requestUrl.getPath());
378 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
379 osw.write(json_text);
383 String responseMessage = con.getResponseMessage();
384 int responseCode = con.getResponseCode();
385 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
386 inputStream = con.getInputStream();
388 inputStream = con.getErrorStream();
391 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
392 logMetricResponse(responseCode, responseMessage);
394 // Process the response
395 BufferedReader reader;
397 reader = new BufferedReader( new InputStreamReader( inputStream ) );
398 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
400 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
401 StringBuilder stringBuilder = new StringBuilder();
403 while( ( line = reader.readLine() ) != null ) {
404 stringBuilder.append( line );
406 LOGwriteEndingTrace(responseCode, responseMessage, (stringBuilder != null) ? stringBuilder.toString() : "{no-data}");
407 return stringBuilder.toString();
409 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
410 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
412 throw new AAIServiceException(responseCode, errorresponse);
414 } catch(AAIServiceException aaiexc) {
416 } catch (Exception exc) {
417 LOG.warn("AAIRequestExecutor.post", exc);
418 throw new AAIServiceException(exc);
421 if(inputStream != null)
423 } catch (Exception exc) {
430 public Boolean delete(AAIRequest request, String resourceVersion) throws AAIServiceException {
431 Boolean response = null;
432 InputStream inputStream = null;
434 if(resourceVersion == null) {
435 throw new AAIServiceException("resource-version is required for DELETE request");
439 URL requestUrl = null;
440 HttpURLConnection conn = getConfiguredConnection(requestUrl = request.getRequestUrl(HttpMethod.DELETE, resourceVersion), HttpMethod.DELETE);
441 logMetricRequest("DELETE "+requestUrl.getPath(), "", requestUrl.getPath());
442 conn.setDoOutput(true);
443 // if(request.isDeleteDataRequired()) {
444 // String json_text = request.toJSONString();
446 // LOGwriteDateTrace("data", json_text);
447 // OutputStream os = con.getOutputStream();
448 // OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
449 // osw.write(json_text);
454 String responseMessage = conn.getResponseMessage();
455 int responseCode = conn.getResponseCode();
456 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
457 inputStream = conn.getInputStream();
459 inputStream = conn.getErrorStream();
462 // Process the response
463 LOG.debug("HttpURLConnection result:" + responseCode + " : " + responseMessage);
464 logMetricResponse(responseCode, responseMessage);
466 if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
467 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
470 ObjectMapper mapper = AAIService.getObjectMapper();
472 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
473 StringBuilder stringBuilder = new StringBuilder();
475 while( ( line = reader.readLine() ) != null ) {
476 stringBuilder.append( line );
478 LOGwriteEndingTrace(responseCode, responseMessage, stringBuilder.toString());
480 } else if(responseCode == HttpURLConnection.HTTP_NOT_FOUND ) {
481 LOGwriteEndingTrace(responseCode, responseMessage, "Entry does not exist.");
484 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
485 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
486 throw new AAIServiceException(responseCode, errorresponse);
488 } catch(AAIServiceException aaiexc) {
490 } catch (Exception exc) {
491 LOG.warn("delete", exc);
492 throw new AAIServiceException(exc);
494 if(inputStream != null){
497 } catch(Exception exc) {
506 public Object query(AAIRequest request, Class clas) throws AAIServiceException {
507 Object response = null;
508 InputStream inputStream = null;
509 HttpURLConnection con = null;
510 URL requestUrl = null;
513 con = getConfiguredConnection(requestUrl = request.getRequestQueryUrl(HttpMethod.GET), HttpMethod.GET);
514 logMetricRequest("GET "+requestUrl.getPath(), "", requestUrl.getPath());
517 String responseMessage = con.getResponseMessage();
518 int responseCode = con.getResponseCode();
519 if (responseCode == HttpURLConnection.HTTP_OK) {
520 inputStream = con.getInputStream();
522 inputStream = con.getErrorStream();
525 logMetricResponse(responseCode, responseMessage);
526 ObjectMapper mapper = AAIService.getObjectMapper();
528 if (responseCode == HttpURLConnection.HTTP_OK) {
529 // Process the response
530 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
531 response = mapper.readValue(reader, clas);
532 LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, "SUCCESS", mapper.writeValueAsString(response));
533 } else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
534 LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist.");
537 BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) );
538 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
539 LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse));
540 throw new AAIServiceException(responseCode, errorresponse);
543 } catch(AAIServiceException aaiexc) {
545 } catch (Exception exc) {
546 LOG.warn("GET", exc);
547 throw new AAIServiceException(exc);
549 if(inputStream != null){
552 } catch(Exception exc) {
562 public Boolean patch(AAIRequest request, String resourceVersion) throws AAIServiceException {
563 InputStream inputStream = null;
566 AAIDatum instance = request.getRequestObject();
567 if(instance instanceof ResourceVersion) {
568 resourceVersion = ((ResourceVersion)instance).getResourceVersion();
571 URL requestUrl = null;
572 HttpURLConnection con = getConfiguredConnection(requestUrl = request.getRequestUrl("PATCH", resourceVersion), "PATCH");
573 ObjectMapper mapper = AAIService.getObjectMapper();
574 String json_text = request.toJSONString();
576 LOGwriteDateTrace("data", json_text);
577 logMetricRequest("PATCH "+requestUrl.getPath(), json_text, requestUrl.getPath());
579 OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream());
580 osw.write(json_text);
584 String responseMessage = con.getResponseMessage();
585 int responseCode = con.getResponseCode();
586 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
587 inputStream = con.getInputStream();
589 inputStream = con.getErrorStream();
592 LOG.info("HttpURLConnection result: " + responseCode + " : " + responseMessage);
593 logMetricResponse(responseCode, responseMessage);
595 // Process the response
596 BufferedReader reader;
598 reader = new BufferedReader( new InputStreamReader( inputStream ) );
599 mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
601 if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_ACCEPTED || responseCode == HttpURLConnection.HTTP_NO_CONTENT) {
602 StringBuilder stringBuilder = new StringBuilder();
604 while( ( line = reader.readLine() ) != null ) {
605 stringBuilder.append( line );
607 LOGwriteEndingTrace(responseCode, responseMessage, (stringBuilder != null) ? stringBuilder.toString() : "{no-data}");
610 StringBuilder stringBuilder = new StringBuilder();
612 while( ( line = reader.readLine() ) != null ) {
613 stringBuilder.append("\n").append( line );
615 LOG.info(stringBuilder.toString());
618 ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class);
619 LOGwriteEndingTrace(responseCode, responseMessage, mapper.writeValueAsString(errorresponse));
621 throw new AAIServiceException(responseCode, errorresponse);
623 } catch(AAIServiceException aaiexc) {
625 } catch (Exception exc) {
626 LOG.warn("AAIRequestExecutor.patch", exc);
627 throw new AAIServiceException(exc);
630 if(inputStream != null)
632 } catch (Exception exc) {
645 protected HttpURLConnection getConfiguredConnection(URL httpReqUrl, String method) throws Exception {
646 HttpURLConnection con = (HttpURLConnection) httpReqUrl.openConnection();
648 // Set up the connection properties
649 con.setRequestProperty("Connection", "close");
650 con.setDoInput(true);
651 con.setDoOutput(true);
652 con.setUseCaches(false);
653 con.setConnectTimeout(connection_timeout);
654 con.setReadTimeout(read_timeout);
655 con.setRequestMethod(method);
656 con.setRequestProperty("Accept", "application/json");
657 // con.setRequestProperty( "Accept-Encoding", "gzip,compress" );
658 con.setRequestProperty("Transfer-Encoding","chunked");
659 con.setRequestProperty("Content-Type",
660 "PATCH".equalsIgnoreCase(method) ? "application/merge-patch+json" : "application/json");
661 con.setRequestProperty("X-FromAppId", applicationId);
662 con.setRequestProperty("X-TransactionId", TransactionIdTracker.getNextTransactionId());
663 String mlId = ml.getRequestID();
664 if (mlId != null && !mlId.isEmpty()) {
665 LOG.debug(String.format("MetricLogger requestId = %s", mlId));
666 con.setRequestProperty(MetricLogger.REQUEST_ID, mlId);
668 LOG.debug("MetricLogger requestId is null");
671 if (userName != null && !userName.isEmpty() && userPassword != null && !userPassword.isEmpty()) {
672 String basicAuth = "Basic " + new String(Base64.encodeBase64((userName + ":" + userPassword).getBytes()));
673 con.setRequestProperty("Authorization", basicAuth);
676 if (con instanceof HttpsURLConnection && CTX != null) {
677 SSLSocketFactory sockFact = CTX.getSocketFactory();
678 HttpsURLConnection.class.cast(con).setSSLSocketFactory(sockFact);
683 private URL appendDepth(URL requestUrl, AAIRequest request) throws MalformedURLException {
685 String depth = request.requestProperties.getProperty("depth", "1");
686 String path = requestUrl.toString();
687 if(path.contains("?depth=") || path.contains("&depth=")) {
690 if(path.contains("?")) {
691 path = String.format("%s&depth=%s", path, depth);
693 path = String.format("%s?depth=%s", path, depth);
695 return new URL(path);
699 public void logMetricRequest(String targetServiceName, String msg, String path){
700 String svcInstanceId = "";
701 String svcName = null;
702 String partnerName = null;
703 String targetEntity = "A&AI";
704 String targetVirtualEntity = null;
706 targetServiceName = "";
708 ml.logRequest(svcInstanceId, svcName, partnerName, targetEntity, targetServiceName, targetVirtualEntity, msg);
711 public void logMetricResponse(int responseCode, String responseDescription){
712 ml.logResponse(responseCode < 400 ? "SUCCESS" : "FAILURE", Integer.toString(responseCode), responseDescription);
715 protected void LOGwriteFirstTrace(String method, String url) {
716 String time = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(System.currentTimeMillis());
717 LOG.info("A&AI transaction :");
718 LOG.info("Request Time : " + time + ", Method : " + method);
719 LOG.info("Request URL : "+ url);
722 protected void LOGwriteDateTrace(String name, String data) {
723 LOG.info("Input - " + name + " : " + data);
726 protected void LOGwriteEndingTrace(int response_code, String comment, String data) {
727 LOG.info("Response code : " + response_code +", " + comment);
728 LOG.info(String.format("Response data : %s", data));