I'm working on a spring boot project in which I'm sending a client certificate with every request. I have placed the client certificate inside resources/keystore/certificate.jks folder. However, when I deploy the application in wildfly I got the following error
java.io.FileNotFoundException: class path resource [keystore/certificate.jks] cannot be resolved to absolute file path because it does not reside in the file system: vfs:/content/ProjectName.war/WEB-INF/classes/keystore/certificate.jks
I'm reading the file in the following way
public RestTemplate getTemplate(RestTemplateBuilder builder) throws Exception{
char[] password = "changeit".toCharArray();
final SSLContext sslContext = SSLContextBuilder.create()
.loadKeyMaterial(keyStore("classpath:keystore/certificate.jks", password,"KeyStore"), password)
.build();
HttpClient client = HttpClients.custom().setSSLContext(sslContext).build();
return builder
.requestFactory(new HttpComponentsClientHttpRequestFactory(client))
.build();
}
private KeyStore keyStore(String file, char[] password,String type) throws Exception {
KeyStore keyStore = KeyStore.getInstance("JKS");
File key = ResourceUtils.getFile(file);
try (InputStream in = new FileInputStream(key)) {
keyStore.load(in, password);
}catch(Exception e) {
e.printStackTrace();
}
return keyStore;
}
When I run this application as spring boot app it runs successfully however when I package this app and deploys it in wildfly server It gives me FileNotFoundError
though I don't get the intent behind sending a certificate in this way. In the context of wildfly understand things, it's via modules. you can create custom modules and load them in WildFly. You can refer : https://kb.novaordis.com/index.php/Writing_a_Custom_WildFly_Module
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.