Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed Tomcat-7 to run only in https

Tags:

java

tomcat7

I want to run embedded tomcat that uses only HTTPS (8443). I do not want 8080 port to be used at all. Any idea about ?


    Connector httpsConnector = new Connector();
    httpsConnector.setPort(httpsPort);
    httpsConnector.setSecure(true);
    httpsConnector.setScheme("https");
    httpsConnector.setAttribute("keystoreFile", appBase + "/.keystore");
    httpsConnector.setAttribute("clientAuth", "false");
    httpsConnector.setAttribute("sslProtocol", "TLS");
    httpsConnector.setAttribute("SSLEnabled", true);

    Tomcat tomcat = new Tomcat();
    tomcat.getService().addConnector(httpsConnector);
    tomcat.setPort(8080);
    Connector defaultConnector = tomcat.getConnector();
    defaultConnector.setRedirectPort(8443);

    tomcat.setBaseDir(".");
    tomcat.getHost().setAppBase(appBase);

    StandardServer server = (StandardServer) tomcat.getServer();
    AprLifecycleListener listener = new AprLifecycleListener();
    server.addLifecycleListener(listener);

Thanks

like image 360
Srinivas Avatar asked Aug 06 '12 07:08

Srinivas


People also ask

Can Tomcat run on both http and https?

You can configure two virtual hosts (one for http and one for https) which connect to the respective Tomcat backend servlets. You can look at this question for config examples. You want to do almost exactly the same thing.

What is HTTP connector in Tomcat?

The HTTP Connector element represents a Connector component that supports the HTTP/1.1 protocol. It enables Catalina to function as a stand-alone web server, in addition to its ability to execute servlets and JSP pages.


1 Answers

You would have to remove the connector defined in [tomcat-dir]/conf/server.xml which binds it to 8080 and have a separate connector for HTTPS.

like image 167
Chris Avatar answered Nov 02 '22 16:11

Chris