Spring Boot SSL works only on RestController Contstructor











up vote
2
down vote

favorite












Since I'm moving old architecture to a new Spring Boot solution I'm implementing the calls through @RestController.



Now, the FE needs to pass data to my @RestController which handles it, and make an old RPC-call to an old SoapWs.



The Rpc Ws-Endpoint uses Https, and needs a certificate.
So I've put everything in the Keystore and set the System.Properties accordingly.
Now the interesting part.
If I define the System properties in main spring boot Application Startup Class:



    @Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> {


@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {

System.setProperty("javax.net.ssl.keyStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.ssl.trustStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.debug","ssl");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");

}


I can see them in the @RestController. I've checked them through System.getProperties(...) method and they are where they're supposed to be.
But the call to remote-rpc ws gives Handshake failure.



If set variables in the @RestController constructor....it works!
That's the only change.
I'm astonished, no clues at all.










share|improve this question
























  • isn't there a typo? C:/ prefix is missing from trustStore path
    – David Szalai
    Nov 9 at 14:16












  • No it's just me amending things to publish code. Anyways corrected...thanks!
    – Black.Jack
    Nov 9 at 14:19










  • It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
    – David Szalai
    Nov 9 at 14:29












  • Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
    – Black.Jack
    Nov 9 at 14:39










  • I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
    – David Szalai
    Nov 9 at 14:49















up vote
2
down vote

favorite












Since I'm moving old architecture to a new Spring Boot solution I'm implementing the calls through @RestController.



Now, the FE needs to pass data to my @RestController which handles it, and make an old RPC-call to an old SoapWs.



The Rpc Ws-Endpoint uses Https, and needs a certificate.
So I've put everything in the Keystore and set the System.Properties accordingly.
Now the interesting part.
If I define the System properties in main spring boot Application Startup Class:



    @Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> {


@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {

System.setProperty("javax.net.ssl.keyStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.ssl.trustStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.debug","ssl");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");

}


I can see them in the @RestController. I've checked them through System.getProperties(...) method and they are where they're supposed to be.
But the call to remote-rpc ws gives Handshake failure.



If set variables in the @RestController constructor....it works!
That's the only change.
I'm astonished, no clues at all.










share|improve this question
























  • isn't there a typo? C:/ prefix is missing from trustStore path
    – David Szalai
    Nov 9 at 14:16












  • No it's just me amending things to publish code. Anyways corrected...thanks!
    – Black.Jack
    Nov 9 at 14:19










  • It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
    – David Szalai
    Nov 9 at 14:29












  • Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
    – Black.Jack
    Nov 9 at 14:39










  • I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
    – David Szalai
    Nov 9 at 14:49













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Since I'm moving old architecture to a new Spring Boot solution I'm implementing the calls through @RestController.



Now, the FE needs to pass data to my @RestController which handles it, and make an old RPC-call to an old SoapWs.



The Rpc Ws-Endpoint uses Https, and needs a certificate.
So I've put everything in the Keystore and set the System.Properties accordingly.
Now the interesting part.
If I define the System properties in main spring boot Application Startup Class:



    @Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> {


@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {

System.setProperty("javax.net.ssl.keyStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.ssl.trustStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.debug","ssl");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");

}


I can see them in the @RestController. I've checked them through System.getProperties(...) method and they are where they're supposed to be.
But the call to remote-rpc ws gives Handshake failure.



If set variables in the @RestController constructor....it works!
That's the only change.
I'm astonished, no clues at all.










share|improve this question















Since I'm moving old architecture to a new Spring Boot solution I'm implementing the calls through @RestController.



Now, the FE needs to pass data to my @RestController which handles it, and make an old RPC-call to an old SoapWs.



The Rpc Ws-Endpoint uses Https, and needs a certificate.
So I've put everything in the Keystore and set the System.Properties accordingly.
Now the interesting part.
If I define the System properties in main spring boot Application Startup Class:



    @Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> {


@Override
public void onApplicationEvent(final ApplicationReadyEvent event) {

System.setProperty("javax.net.ssl.keyStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.ssl.trustStore","/cert/clientkeystore.jks");
System.setProperty("javax.net.debug","ssl");
System.setProperty("javax.net.ssl.keyStorePassword","changeit");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");

}


I can see them in the @RestController. I've checked them through System.getProperties(...) method and they are where they're supposed to be.
But the call to remote-rpc ws gives Handshake failure.



If set variables in the @RestController constructor....it works!
That's the only change.
I'm astonished, no clues at all.







java spring spring-boot rpc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 14:58









tom1299

618




618










asked Nov 9 at 13:43









Black.Jack

1,09221428




1,09221428












  • isn't there a typo? C:/ prefix is missing from trustStore path
    – David Szalai
    Nov 9 at 14:16












  • No it's just me amending things to publish code. Anyways corrected...thanks!
    – Black.Jack
    Nov 9 at 14:19










  • It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
    – David Szalai
    Nov 9 at 14:29












  • Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
    – Black.Jack
    Nov 9 at 14:39










  • I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
    – David Szalai
    Nov 9 at 14:49


















  • isn't there a typo? C:/ prefix is missing from trustStore path
    – David Szalai
    Nov 9 at 14:16












  • No it's just me amending things to publish code. Anyways corrected...thanks!
    – Black.Jack
    Nov 9 at 14:19










  • It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
    – David Szalai
    Nov 9 at 14:29












  • Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
    – Black.Jack
    Nov 9 at 14:39










  • I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
    – David Szalai
    Nov 9 at 14:49
















isn't there a typo? C:/ prefix is missing from trustStore path
– David Szalai
Nov 9 at 14:16






isn't there a typo? C:/ prefix is missing from trustStore path
– David Szalai
Nov 9 at 14:16














No it's just me amending things to publish code. Anyways corrected...thanks!
– Black.Jack
Nov 9 at 14:19




No it's just me amending things to publish code. Anyways corrected...thanks!
– Black.Jack
Nov 9 at 14:19












It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
– David Szalai
Nov 9 at 14:29






It is possible that ApplicationReadyEvent is too late to register such values, as SSLContext might already be initialized. Try putting them in @PostConstruct of the component.
– David Szalai
Nov 9 at 14:29














Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
– Black.Jack
Nov 9 at 14:39




Yep that's more or less my "constructor approach". But other than specify every time I build the bean, I would fine-grained control the keystore.on a specific call.
– Black.Jack
Nov 9 at 14:39












I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
– David Szalai
Nov 9 at 14:49




I don't really understand what you mean by that. Why do you want to be able to change the trustStore for every call? Anyways, you can create multiple instances of docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html, and depending on what library you use for the remote call, inject an instance into that.
– David Szalai
Nov 9 at 14:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226876%2fspring-boot-ssl-works-only-on-restcontroller-contstructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226876%2fspring-boot-ssl-works-only-on-restcontroller-contstructor%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)