import org.onap.aai.cl.api.Logger;\r
import org.onap.aai.cl.mdc.MdcContext;\r
import org.onap.aai.datarouter.logging.DataRouterMsgs;\r
-import org.onap.aai.datarouter.policy.EntityEventPolicy;\r
import org.onap.aai.restclient.client.Headers;\r
import org.onap.aai.restclient.client.OperationResult;\r
import org.onap.aai.restclient.client.RestClient;\r
import org.onap.aai.restclient.enums.RestAuthenticationMode;\r
import org.onap.aai.restclient.rest.HttpUtil;\r
import org.slf4j.MDC;\r
+import org.springframework.core.io.ClassPathResource;\r
+import org.springframework.core.io.FileSystemResource;\r
+import org.springframework.core.io.Resource;\r
\r
import com.sun.jersey.core.util.MultivaluedMapImpl;\r
\r
\r
private String searchUrl = null;\r
private String documentEndpoint = null;\r
+ private String schemaHomeDir = null;\r
\r
\r
/**\r
String documentEndpoint, \r
Logger logger) {\r
\r
+ String deobfuscatedCertPassword = keystorePwd.startsWith("OBF:")?Password.deobfuscate(keystorePwd):keystorePwd;\r
// Create REST client for search service\r
searchClient = new RestClient()\r
.authenticationMode(RestAuthenticationMode.SSL_CERT)\r
.validateServerHostname(false)\r
- .validateServerCertChain(true)\r
+ .validateServerCertChain(false)\r
.clientCertFile(DataRouterConstants.DR_HOME_AUTH + certName)\r
- .clientCertPassword(Password.deobfuscate(keystorePwd))\r
- .trustStore(DataRouterConstants.DR_HOME_AUTH + keystore);\r
+ .clientCertPassword(deobfuscatedCertPassword); \r
\r
this.searchUrl = searchUrl;\r
this.documentEndpoint = documentEndpoint;\r
\r
this.logger = logger;\r
+ this.schemaHomeDir = DataRouterConstants.DR_SEARCH_SCHEMA_HOME;\r
}\r
\r
\r
* Removes a document from the Search Service.\r
* \r
* @param index - The index to create the document in.\r
- * @param id - The identifier for the document.\r
- * @param payload - The document contents.\r
+ * @param documentId - The identifier for the document.\r
* @param headers - HTTP headers.\r
*/\r
public void deleteDocument(String index, String documentId, Map<String, List<String>> headers) {\r
* @throws Exception\r
*/\r
protected String loadFileData(String filename) throws Exception {\r
- StringBuilder data = new StringBuilder();\r
- try {\r
- BufferedReader in = new BufferedReader(new InputStreamReader(\r
- EntityEventPolicy.class.getClassLoader().getResourceAsStream("/" + filename),\r
- StandardCharsets.UTF_8));\r
- String line;\r
+ Resource fileResource = getSchemaResource(filename);\r
+ if (fileResource == null) {\r
+ throw new Exception("Could not find file = " + filename + ".");\r
+ }\r
\r
- while ((line = in.readLine()) != null) {\r
+ try (\r
+ InputStreamReader inputStreamReader = new InputStreamReader(fileResource.getInputStream(), StandardCharsets.UTF_8);\r
+ BufferedReader in = new BufferedReader(inputStreamReader);\r
+ ){\r
+ String line;\r
+ StringBuilder data = new StringBuilder();\r
+ while((line = in.readLine()) != null) {\r
data.append(line);\r
}\r
+ return data.toString();\r
} catch (Exception e) {\r
throw new Exception("Failed to read from file = " + filename + ".", e);\r
}\r
+ }\r
+\r
+ private Resource getSchemaResource(String filename) {\r
+ Resource fileResource = null;\r
+\r
+ if(filename == null) {\r
+ return null;\r
+ }\r
+ \r
+ if ((schemaHomeDir != null) && (fileResource = new FileSystemResource(schemaHomeDir + "/" + filename)).isReadable()) {\r
+ return fileResource;\r
+ }\r
+\r
+ if ((fileResource = new ClassPathResource(filename)).isReadable()) {\r
+ return fileResource;\r
+ }\r
\r
- return data.toString();\r
+ return null;\r
}\r
\r
\r