I need to run the same server on 2 or more ports with HTTPS. In the early production, we had configured port 10500 for services. Currently, we need to run it both on 443 and 10500 with SSL enabled.
I have found many resources for enabling HTTP and HTTPS for spring boot. But I couldn't find any method that allows enabling HTTPS services on 2 or more ports.
I have tried configuring port redirection. But that also didn't work. It works when manually connecting to port 443 with HTTP. But whenever HTTPS is used, the program throws an exception.
java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x020x000x010x000x010xfc0x030x030x810x00aC0x1b0x10`0xb80x8d0xae0x9e0xe40xc7V0xf60x08:e0xcc0x8f<0xf70x8b0xc2y0xa40xfe0xa3(0xc7-0xe6]. HTTP method names must be tokens
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(oldPortRedirectConnector());
return tomcat;
}
private Connector oldPortRedirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("https");
connector.setPort(443);
connector.setSecure(true);
connector.setRedirectPort(10500);
return connector;
}
application.properties
server.port=10500
Any help is greatly appreciated. Either running the same service on 2 ports or forwarding from one HTTPS port to another will be really great to have for us.