0.2
tomcat 9.0.53
the error is throw when i deploy the application to an external tomcat server.
if i run as an Springboot application (with same configuration) then there is no error.
also i can access the same api via postman.
http://localhost:9080/api/authenticate
POST
method
{"username":"User","password":"user"}
code:
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Setting basic post request
con.setRequestMethod("POST");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type", "application/json");
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(jsonData);
wr.flush();
wr.close();
Logger.info("nSending 'POST' request to URL : " url);
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String output;
while ((output = in.readLine()) != null) {
response.append(output);
}
Logger.info(response.toString());
in.close();
Error:
> 12-08-2021 @ 2:04:36PM : ERROR ---------->
> http://localhost:9080/api/authenticate
> [com.edge.service.common.ApiHandler.post:63 <
> com.edge.service.common.ApiHandler.parseAsObject:86]
> java.io.FileNotFoundException: http://localhost:9080/api/authenticate
> at
> java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1909)
> at
> java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
> at com.edge.service.common.ApiHandler.post(ApiHandler.java:55) at
> com.edge.service.common.ApiHandler.parseAsObject(ApiHandler.java:86)
> at
> com.edge.service.login.LoginService.authenticateuser(LoginService.java:44)
> at
> com.edge.controller.login.LoginController.authenticate(LoginController.java:66)
> at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.base/java.lang.reflect.Method.invoke(Method.java:566) at
> org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
> at
> org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
> at
> org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
> at
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
> at
> org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
> at
> org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
> at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
> at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
> at
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
> at
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) at
> org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
CodePudding user response:
I was able to resolve the issue, there was an issue with the contextroot, cleaned and redoplyed
CodePudding user response:
My Application started to work but i know that's an workaround.
when my API is deployed without an context root(http://localhost:9080/authenticate) its working. but with a context root(http://localhost:9080/epalsapi/authenticate), my UI application is throwing the above asked question.
java.io.FileNotFoundException: http://localhost:9080/api/authenticate at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0