I have a Spring Boot app running on Heroku and I am facing a weird problem.
If I try to access https://appname.herokuapp.com/authentication/token which is a POST request it works as expected with no problem.
However, I have configured my DNS and Heroku app to work on myxyzappdomain.com too and for most part it does. I can access the index.html page and all GET APIs. But, If I try to access any POST API like the one above (https://myxyzappdomain.com/authentication/token) I get a 405 error -
2020-08-17T19:47:31.039889+00:00 heroku[router]: at=info method=GET path="/authentication/token" host=www.myxyzappdomain.com request_id=92dbc99e-ed32-4643-abdb-7a0a8b6828f1 fwd="27.56.186.133,141.101.98.19" dyno=web.1 connect=6ms service=17ms status=405 bytes=287 protocol=http
2020-08-17T19:47:31.028327+00:00 app[web.1]: 2020-08-17 19:47:31.028 DEBUG 4 --- [io-57518-exec-6] o.s.web.servlet.DispatcherServlet : GET "/authentication/token", parameters={}
2020-08-17T19:47:31.031695+00:00 app[web.1]: 2020-08-17 19:47:31.031 DEBUG 4 --- [io-57518-exec-6] .m.m.a.ExceptionHandlerExceptionResolver : Using #ExceptionHandler com.abc.xyz.globalexceptions.GlobalExceptionHandler#handleException(Exception, WebRequest)
2020-08-17T19:47:31.031869+00:00 app[web.1]: 2020-08-17 19:47:31.031 WARN 4 --- [io-57518-exec-6] o.s.web.servlet.PageNotFound : Request method 'GET' not supported
2020-08-17T19:47:31.033581+00:00 app[web.1]: 2020-08-17 19:47:31.033 DEBUG 4 --- [io-57518-exec-6] o.s.w.s.m.m.a.HttpEntityMethodProcessor : No match for [*/*], supported: []
2020-08-17T19:47:31.037345+00:00 app[web.1]: 2020-08-17 19:47:31.037 DEBUG 4 --- [io-57518-exec-6] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
2020-08-17T19:47:31.037484+00:00 app[web.1]: 2020-08-17 19:47:31.037 DEBUG 4 --- [io-57518-exec-6] o.s.web.servlet.DispatcherServlet : Completed 405 METHOD_NOT_ALLOWED
Notice how it is trying to accept the POST request as a GET one and failing to do so. What is happening here?
It would appear you have a "middle-man" (according to your comments: a CloudFlare configuration) that redirects from the naked domain myxyzappdomain.com to www.myxyzappdomain.com.
You wrote that you use the URL https://myxyzappdomain.com/authentication/token, yet in your log output it says host=www.myxyzappdomain.com (note the www). That means that a redirect has taken place, probably using status code 302. Although this was originally not defined this way in the HTTP spec, nowadays virtually all clients change the request method to GET when a 302 redirect is received from a POST request.
For entering a URL in the browser this is not a problem, because it will be a GET request in the first place, but for API usage it is.
To avoid this issue, you can send your POST request to the final URL of the redirect in the first place - to https://www.myxyzappdomain.com/authentication/token (with www), so there won't be any redirect messing with your HTTP method.
Related
in my application (deployed in Heroku), there is a request (GET) that is blocked in the infrastructure layer, the request does not get to execute the code of my application. It returns an error status=400 and connect=0ms and does not carry any associated Heroku error code and description. The request never reaches the application.
It only happens with this GET request, when it comes from the production server. if I make the request from postman it is received correctly with status=200
The other requests have not problem and are executed correctly from the production server.
This is an example:
2021-08-20T10: 27: 02.217551 + 00: 00 heroku [router]: at=info method=GET path="/api/get" host=myapp.herokuapp.com request_id=2920634e-87f2-4b2c-be60-b38497c53e58 dyno=web.1 connect=0ms service=1ms status=400 bytes=47 protocol=https
The problem was identified and corrected.
The problem was that one of the headers of the GET request was being sent to null and the request was rejected as Bad Request Exception before entering the APP.
regards
I currently have replaced httpurlconnection to feign-okhttp in my projects. I use the following edition:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>9.6.0</version>
</dependency>
but I got a problem when I post this url: "http://gclife-platform-service:20000/v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS"
The log from server side as following:
Received [1.1
cache-control: no-cache
...
But "Received [1.1" should be:
Received [POST v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS HTTP/1.1
So this caused the parse problem.
2018-05-05 10:10:04.076 DEBUG 6525 --- [io-20000-exec-9] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
when I post url with no query parameters like "http://gclife-platform-service:20000/v1/message/sms/verifycode/check", I got:
Received [POST /v1/message/sms/verifycode/check HTTP/1.1
This is the correct result.
How can I get the correct log like this? Can anyone help? Thanks.
This exception can occur when you try to execute https request from client on endpoint which isn't https enabled. Client will encrypt request data when server is expecting raw data.
Change https:// to http:// in your client url.
I made the same mistake.
print Feign header and find Content-Length was duplicate definition.
I am looking on my drain log and I see this
327 <158>1 2018-04-17T22:03:27.578702+00:00 heroku router - - at=info method=GET path="/{url}" host={my_host} request_id=11bb9b05-dea3-42c2-b57a-9be6fb9b93d2 fwd="80.6.26.72,141.101.107.25" dyno=web.1 connect=0ms service=1ms status=200 bytes=6265 protocol=http
I am certain that this request doesn't come from a legit user, how is it possible to dig in more and get the remote server IP? I used https://stackoverflow.com/a/6837689/2513428 inside my script to check the ip's but I assume it returned the proxy of herocu servers.
Heroku makes the IP making the request available in the fwd log field: https://devcenter.heroku.com/articles/http-routing#heroku-router-log-format
You can also read it within your code by looking at the X-Forwarded-For HTTP header.
So in your case, the IP of the client making this request was 80.6.26.72.
I have a controller that is doing something, everything seems fine, it logs a success, and then it does this
return new ResponseEntity<>(resp, HttpStatus.OK);
Seems like it should send a 200 OK.
Well, I also have a HandlerInterceptorAdapter with an "afterCompletion" that logs the status:
logger.debug("Response status: {}, URI: {}", response.getStatus(), request.getRequestURI());
This is showing a 500 where there was a success from the controller.
In the stdout logs I see an error
2018-01-12 12:33:59.035 ERROR 18952 --- [pr-8080-exec-14] o.s.boot.web.support.ErrorPageFilter : Cannot forward to error page for request [/ws/path] as the response has already been committed.
As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
and
org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error: -32
I can't find any doc on what that APR error is and I have no idea why the status code would be wrong. I am using tomcat 8.5.
So. APR -32 is a "Client Abort" error. The client was timing out in waiting. It looks like what was happening was the client made a request and was sitting in queue for a few seconds. It has a short hard timeout limit. The client timed out before the server got to the request. Then the server picked up the request and did everything fine but when trying to write back to the client, it found the socket closed. So it set a 500 and threw that exception.
I'm currently running an app on heroku with python/flask as the main back-end. I've managed to successfully launch the site on heroku (Here's the site link). What seems to happen is that when I load the sit in the browser after a certain period of time, I will get an error as follows:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Essentially I am getting a 500 Error, with the following in the heroku logs:
2014-01-11T22:08:01.423860+00:00 heroku[router]: at=info method=GET path=/ host=outlet-beta.herokuapp.com fwd="207.38.157.121" dyno=web.1 connect=2ms service=92ms status=500 bytes=291
After I reload the page, the site works fine. I'm not 100% sure how to proceed on this front.
I have the Sentry addon that lets me see what's going on with the errors:
OperationalError: (OperationalError) (2006, 'MySQL server has gone away')
Sentry has logged this as a trending error which happens pretty often, and is logged each time this internal service error occurs.
I'm running the site with ClearDB and Cloudinary. Is there any chance the mysql server isn't getting connected to quickly enough, and after reload it works? If so, how do I fix it?