KJEjava48
KJEjava48

Reputation: 2055

404 Not Found : after adding https to spring boot

In my spring boot application I added ssl properties in application.yml as below:

server:
  ssl:
    key-store: classpath:keystore.p12
    key-store-password: password
    key-store-type: PKCS12
    key-alias: alias
    enabled: true
 port: 443

and the application war file has successfully deployed on tomcat server.Configured server.xml of tomcat as below for https:

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
keystoreFile="conf/keystore.p12" keystorePass="password" keyAlias="alias" clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1.2,TLSv1.1"/>

But when I try to call the url(https://fortunenetworks.in:443/ourectestschool/public/users/checkToken) from postman I got below error:

<head>
    <title>404 Not Found</title>
</head>

<body>
    <h1>Not Found</h1>
    <p>The requested URL was not found on this server.</p>
    <p>Additionally, a 404 Not Found
        error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body>

</html>

If I tried the same url with http(http://fortunenetworks.in:443/ourectestschool/public/users/checkToken) got below msg:

<html>

<head>
    <title>400 Bad Request</title>
</head>

<body>
    <h1>Bad Request</h1>
    <p>Your browser sent a request that this server could not understand.<br />
Reason: You're speaking plain HTTP to an SSL-enabled server port.<br />
 Instead use the HTTPS scheme to access this URL, please.<br />
</p>
        <p>Additionally, a 400 Bad Request
            error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body>

</html>

When I use http and 8080 as port(http://fortunenetworks.in:8080/ourectestschool/public/users/checkToken) the url is working. My controller class is:

@RestController
@RequestMapping("/public/users")
public class PublicController {

        @RequestMapping(value = "/checkToken",method = RequestMethod.GET)
        public @ResponseBody
        String getCheckToken() {
            return "Success";
        }
}

Why is my https call is not working,what i am doing wrong here.

Upvotes: 0

Views: 288

Answers (1)

Panagiotis Bougioukos
Panagiotis Bougioukos

Reputation: 19173

and the application war file has successfully deployed on tomcat server.Configured server.xml of tomcat as below for https:

Considering that you have a spring boot application deployed as war file in some existing external tomcat server, you don't need to configure the spring-boot properties for ssl.

So the properies defined for the above reason inside application.yml can be removed

You only need to configure your server.xml on your external tomcat you have running for ssl to work.

<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
keystoreFile="conf/keystore.p12" keystorePass="password" keyAlias="alias" clientAuth="false" sslProtocol="TLS"> sslEnabledProtocols="TLSv1.2,TLSv1.1"/>

Make sure that everything you have configured in the above snippet is complying (certificate, keystorePass..)

Also any modification of server.xml requires tomcat restart for changes to apply.

You can use this as a simple example tutorial.

Then the https://fortunenetworks.in:443/ourectestschool/public/users/checkToken should become reachable.

Upvotes: 1

Related Questions