Search code examples
http-redirectconfigurationhttpsweblogic

Avoid HTTP to HTTPS redirection in Weblogic


I have a web application running on Weblogic. The HTTPS URL to this application is https://localhost:7002/MyApp.

Whenever I am changing the URL in the address bar to http://localhost:7002/MyApp, it automatically redirects to the original HTTPS based URL.

My requirement is to take the user to some kind of custom error page, if they request the HTTP URL. For example, http://localhost:7002/MyApp should redirect to https://localhost:7002/MyApp/error.jsp.

Is this redirection possible to configure in Weblogic?


Solution

  • You mentioned that your https URL is:

    https://localhost:7002/MyApp
    

    And assuming that your http URL is:

    http://localhost:7001/MyApp
    

    When you say you change the https URL in browser to:

    http://localhost:7002/MyApp
    

    This is in-correct. If you provide such a URL, WLS will accept the request on secure port 7002 but will fail to identify the protocol (it expected https but you gave http). Instead of a redirection, you would get some error in browser and definitely following error in WLS logs:

    <May XX, 2013 XX:XX:17 PM IST> <Warning> <Security> <BEA-090475> <Plaintext data for protocol HTTP was received from peer
    XXXXXXXXXXXXXX - 192.169.0.100 instead of an SSL handshake.>
    

    I assume you are changing the URL to:

    http://localhost:7001/MyApp
    

    Please correct/update your issue description.

    Now onto your requirement, it seems nearly impossible to do this via WLS configuration.

    As a workaround, you can create a servlet filter and call isSecure on ServletRequest to determine whether the request was made using secure protocol or not. If you find it was not, then you can redirect to some custom page. And you would also need to disable this automatic redirection to https that you have reported for your application.

    Ref: http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#isSecure%28%29