Update apache camel from 2.x to 3.x
[aai/router-core.git] / src / main / java / org / onap / aai / rest / RestClientProducer.java
index 579315d..ccb8b89 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.onap.aai.rest;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.support.DefaultProducer;
 import org.eclipse.jetty.util.security.Password;
-import org.onap.aai.event.EventBusConsumer;
 import org.onap.aai.restclient.client.Headers;
 import org.onap.aai.restclient.client.OperationResult;
 import org.onap.aai.restclient.client.RestClient;
+import org.onap.aai.restclient.enums.RestAuthenticationMode;
 import org.onap.aai.restclient.rest.HttpUtil;
 import org.onap.aai.cl.api.Logger;
 import org.onap.aai.cl.eelf.LoggerFactory;
@@ -87,7 +85,7 @@ public class RestClientProducer extends DefaultProducer {
     }
 
     // Now, invoke the REST client to perform the operation.
-    OperationResult result = null;
+    OperationResult result;
     switch (getOperation(exchange)) {
 
       case GET:
@@ -117,15 +115,16 @@ public class RestClientProducer extends DefaultProducer {
         break;
     }
 
-    // Populate the OUT message with our result.
-    exchange.getOut().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_CODE,
+    /** Just use IN headers as camel does not pass incoming headers from IN to OUT so they might be lost .
+    Reference : http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html **/
+    exchange.getIn().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_CODE,
         result.getResultCode());
     if (HttpUtil.isHttpResponseClassSuccess(result.getResultCode())) {
-      exchange.getOut().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_MSG,
+      exchange.getIn().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_MSG,
           responseStatusStringFromResult(result));
-      exchange.getOut().setBody(result.getResult());
+      exchange.getIn().setBody(result.getResult());
     } else {
-      exchange.getOut().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_MSG,
+      exchange.getIn().setHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_MSG,
           result.getFailureCause());
     }
 
@@ -232,20 +231,21 @@ public class RestClientProducer extends DefaultProducer {
   private RestClient getRestClient() {
 
     if (restClient == null) {
-
-      String keystoreFilename = endpoint.getEcompKeystore();
+      
       String keystorePassword = endpoint.getEcompKeystorePassword();
       String clientCertFilename = endpoint.getEcompClientCert();
 
       if (logger.isDebugEnabled()) {
         logger.debug("Instantiating REST Client with client_cert=" + clientCertFilename
-            + " keystore=" + keystoreFilename + " keystorePassword=" + keystorePassword);
+            + " keystorePassword=" + keystorePassword);
       }
 
+      String deobfuscatedCertPassword = keystorePassword.startsWith("OBF:")?Password.deobfuscate(keystorePassword):keystorePassword;
+      
       // Create REST client for search service
-      restClient = new RestClient().validateServerHostname(false).validateServerCertChain(true)
-          .clientCertFile(clientCertFilename)
-          .clientCertPassword(Password.deobfuscate(keystorePassword)).trustStore(keystoreFilename);
+      restClient = new RestClient().authenticationMode(RestAuthenticationMode.SSL_CERT).validateServerHostname(false)
+              .validateServerCertChain(false).clientCertFile(clientCertFilename)
+              .clientCertPassword(deobfuscatedCertPassword);
     }
 
     return restClient;