httpsweb.xmltomcat8server.xmlangular4-httpclient

Enabling Both HTTP and HTTPS for an Application in Tomcat 8


I have one application deployed in Tomcat 8, which i want to run on http and https both. I have configured server.xml to run both on http and https. web.xml for application is also configured to handle both requests. Issue is i am getting response for https requests only. For http it says request timed out.

https port configured is 9999 and http port is 8080. https://URL:9999/path => working http://URL:8080/path => not working

Below is attached code for server.xml , web.xml inside WEB-INF directory and catalina.out response when i start Tomcat.

SERVER.XML

<Connector port="8080" protocol="HTTP/1.1"
       connectionTimeout="20000"/>
  <Connector
       protocol="org.apache.coyote.http11.Http11NioProtocol"
       port="9999" maxThreads="200"
       scheme="https" secure="true" SSLEnabled="true"
       keystoreFile="/root/.keystore" keystorePass="Pooltooadm!n"
       clientAuth="false" sslProtocol="TLS"/>

web.xml

    <welcome-file-list>
        <welcome-file>/index.html</welcome-file>
        <welcome-file>/index.xhtml</welcome-file>
        <welcome-file>/index.htm</welcome-file>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>

    <security-constraint>
    <web-resource-collection>
    <web-resource-name>HTTP</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>HTTPS</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>

    <error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
  </error-page>

CATALINA.OUT=>

17-Nov-2017 14:07:46.349 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.23
17-Nov-2017 14:07:46.433 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Sep 28 2017 10:30:11 UTC
17-Nov-2017 14:07:46.593 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.23.0
17-Nov-2017 14:07:46.593 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
17-Nov-2017 14:07:46.593 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.4.21-90-default
17-Nov-2017 14:07:46.593 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
17-Nov-2017 14:07:46.593 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/java/jdk1.8.0_151/jre
17-Nov-2017 14:07:46.594 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_151-b12
17-Nov-2017 14:07:46.594 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
17-Nov-2017 14:07:46.594 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /opt/apache-tomcat-8.5.23
17-Nov-2017 14:07:46.594 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /opt/apache-tomcat-8.5.23
17-Nov-2017 14:07:46.594 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/opt/apache-tomcat-8.5.23/conf/logging.properties
17-Nov-2017 14:07:46.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
17-Nov-2017 14:07:46.595 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
17-Nov-2017 14:07:46.637 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
17-Nov-2017 14:07:46.637 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/opt/apache-tomcat-8.5.23
17-Nov-2017 14:07:46.637 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/opt/apache-tomcat-8.5.23
17-Nov-2017 14:07:46.637 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/opt/apache-tomcat-8.5.23/temp
17-Nov-2017 14:07:46.637 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
17-Nov-2017 14:07:51.020 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
17-Nov-2017 14:07:51.711 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
17-Nov-2017 14:07:51.832 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-jsse-nio-9999"]
17-Nov-2017 14:08:00.507 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
17-Nov-2017 14:08:00.509 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
17-Nov-2017 14:08:00.510 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
17-Nov-2017 14:08:00.592 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 28123 ms
17-Nov-2017 14:08:01.206 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
17-Nov-2017 14:08:01.207 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.23
17-Nov-2017 14:08:01.495 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/host-manager]
17-Nov-2017 14:08:11.450 WARNING [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [159] milliseconds.
17-Nov-2017 14:08:12.311 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/host-manager] has finished in [10,816] ms
17-Nov-2017 14:08:12.312 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/manager]
17-Nov-2017 14:08:12.924 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/manager] has finished in [612] ms
17-Nov-2017 14:08:12.924 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/docs]
17-Nov-2017 14:08:13.415 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/docs] has finished in [491] ms
17-Nov-2017 14:08:13.415 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/ROOT]
17-Nov-2017 14:08:13.825 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/ROOT] has finished in [409] ms
17-Nov-2017 14:08:13.825 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/examples]
17-Nov-2017 14:08:20.096 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/examples] has finished in [6,271] ms
17-Nov-2017 14:08:20.097 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/opt/apache-tomcat-8.5.23/webapps/pooltooadmin]
17-Nov-2017 14:08:20.549 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/apache-tomcat-8.5.23/webapps/pooltooadmin] has finished in [451] ms
17-Nov-2017 14:08:20.836 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
17-Nov-2017 14:08:20.999 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-jsse-nio-9999"]
17-Nov-2017 14:08:21.163 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
17-Nov-2017 14:08:21.204 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 20612 ms

Solution

  • Was able to this by configuring web.xml as follows:-

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Support Both HTTP and HTTPS</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
           <!--   <transport-guarantee>NONE</transport-guarantee> -->
        </user-data-constraint>
    </security-constraint>