In recently migrator from wso2esb to wso2mi and in Mediator class we are reading username/password and password is encrypted so we were using org.wso2.securevault.SecretResolver and code look like something like this
public static void main(String[] args) throws Exception {
File registryXML = null;
String secretAliasValue = "bss";
String secretAliasName = "OM.endpoint.username";
try {
ReadResouceFile sdd = new ReadResouceFile();
registryXML = sdd.readFile();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileInputStream fileInputStream = null;
if (registryXML.exists()) {
try {
fileInputStream = new FileInputStream(registryXML);
StAXOMBuilder builder = new StAXOMBuilder(fileInputStream);
OMElement configElement = builder.getDocumentElement();
// Initialize the SecretResolver providing the configuration element.
SecretResolver secretResolver = SecretResolverFactory.create(configElement, false);
// Resolved the secret alias key value.
if (secretResolver != null && secretResolver.isInitialized()) {
if (secretResolver.isTokenProtected(secretAliasName)) {
secretAliasValue = secretResolver.resolve(secretAliasName);
} else {
System.out.println("Something went Wrong");
}
}
} catch (XMLStreamException e) {
throw new Exception("Unable to parse " + e.getMessage());
} catch (IOException e) {
throw new Exception("Unable to read "+ e.getMessage());
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
throw new Exception(
"Failed to close the FileInputStream, file : " + ". " + e.getMessage());
}
}
}
}
}
But secretResolver.isInitialized() always coming false. Due to this i am not able to read the value and pass into the another API. Can someone please help me tell how to exactly initialize SecretResolver class?