X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fdatarouter%2Futil%2FSearchServiceAgent.java;h=b62237d46834ec94ae9b51bbb94bfd801544c127;hb=093deaf4738d56602f94e6a4193993a77e053a51;hp=42861b423f234aa7387e90ca7d8bc7ff9f546cab;hpb=bf99eb77b31a4cfbc590762cc6ba669820c21439;p=aai%2Fdata-router.git diff --git a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java index 42861b4..b62237d 100644 --- a/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java +++ b/src/main/java/org/onap/aai/datarouter/util/SearchServiceAgent.java @@ -37,13 +37,15 @@ import org.eclipse.jetty.util.security.Password; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.mdc.MdcContext; import org.onap.aai.datarouter.logging.DataRouterMsgs; -import org.onap.aai.datarouter.policy.EntityEventPolicy; 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.slf4j.MDC; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.Resource; import com.sun.jersey.core.util.MultivaluedMapImpl; @@ -56,6 +58,7 @@ public class SearchServiceAgent { private String searchUrl = null; private String documentEndpoint = null; + private String schemaHomeDir = null; /** @@ -96,19 +99,20 @@ public class SearchServiceAgent { String documentEndpoint, Logger logger) { + String deobfuscatedCertPassword = keystorePwd.startsWith("OBF:")?Password.deobfuscate(keystorePwd):keystorePwd; // Create REST client for search service searchClient = new RestClient() .authenticationMode(RestAuthenticationMode.SSL_CERT) .validateServerHostname(false) - .validateServerCertChain(true) + .validateServerCertChain(false) .clientCertFile(DataRouterConstants.DR_HOME_AUTH + certName) - .clientCertPassword(Password.deobfuscate(keystorePwd)) - .trustStore(DataRouterConstants.DR_HOME_AUTH + keystore); + .clientCertPassword(deobfuscatedCertPassword); this.searchUrl = searchUrl; this.documentEndpoint = documentEndpoint; this.logger = logger; + this.schemaHomeDir = DataRouterConstants.DR_SEARCH_SCHEMA_HOME; } @@ -320,8 +324,7 @@ public class SearchServiceAgent { * Removes a document from the Search Service. * * @param index - The index to create the document in. - * @param id - The identifier for the document. - * @param payload - The document contents. + * @param documentId - The identifier for the document. * @param headers - HTTP headers. */ public void deleteDocument(String index, String documentId, Map> headers) { @@ -339,21 +342,42 @@ public class SearchServiceAgent { * @throws Exception */ protected String loadFileData(String filename) throws Exception { - StringBuilder data = new StringBuilder(); - try { - BufferedReader in = new BufferedReader(new InputStreamReader( - EntityEventPolicy.class.getClassLoader().getResourceAsStream("/" + filename), - StandardCharsets.UTF_8)); - String line; + Resource fileResource = getSchemaResource(filename); + if (fileResource == null) { + throw new Exception("Could not find file = " + filename + "."); + } - while ((line = in.readLine()) != null) { + try ( + InputStreamReader inputStreamReader = new InputStreamReader(fileResource.getInputStream(), StandardCharsets.UTF_8); + BufferedReader in = new BufferedReader(inputStreamReader); + ){ + String line; + StringBuilder data = new StringBuilder(); + while((line = in.readLine()) != null) { data.append(line); } + return data.toString(); } catch (Exception e) { throw new Exception("Failed to read from file = " + filename + ".", e); } + } + + private Resource getSchemaResource(String filename) { + Resource fileResource = null; + + if(filename == null) { + return null; + } + + if ((schemaHomeDir != null) && (fileResource = new FileSystemResource(schemaHomeDir + "/" + filename)).isReadable()) { + return fileResource; + } + + if ((fileResource = new ClassPathResource(filename)).isReadable()) { + return fileResource; + } - return data.toString(); + return null; }