Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running this implemnetaion on Tomcat Spring Application throws java.net.ConnectException #16

Closed
KDPandit opened this issue Oct 20, 2022 · 1 comment

Comments

@KDPandit
Copy link

When I run InstallCert.java file as Java main Application, I am able to successfully run and get the certificate from my server without any issue. But running it in a Spring Application on tomcat, throws down below error. (Pasting only the root cause.)

This failure is seen when the SSLSocketFactory object tries to create the socket.

socket = (SSLSocket) factory.createSocket(host, port);

java.net.ConnectException: Connection refused: connect
	java.base/sun.nio.ch.Net.connect0(Native Method)
	java.base/sun.nio.ch.Net.connect(Net.java:579)
	java.base/sun.nio.ch.Net.connect(Net.java:568)
	java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
	java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	java.base/java.net.Socket.connect(Socket.java:633)
	java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:299)
	java.base/sun.security.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:158)
	java.base/sun.security.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:88)
	com.luv2code.springdemo.mvc.CustomCertManager.installCert(CustomCertManager.java:198)
	com.luv2code.springdemo.mvc.CustomCertManager.<init>(CustomCertManager.java:40)
	com.luv2code.springdemo.mvc.RestCallService.getSecuredRestTemplate(RestCallService.java:27)
	com.luv2code.springdemo.mvc.RestCallService.makeSSLRequest(RestCallService.java:43)
	com.luv2code.springdemo.mvc.HelloWorldController.showForm(HelloWorldController.java:22)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.base/java.lang.reflect.Method.invoke(Method.java:568)
	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1064)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

I am unable to figure out what is causing the issue.

@KDPandit KDPandit reopened this Oct 20, 2022
@KDPandit
Copy link
Author

Sorry, the issue was with the port on the server, able to get it working.

Great tool! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant