Rest template exchange method working incorrectly - spring

I am consuming another restful web service that's https inside my rest WS. When I am running my application on localachine the code works fine. But as soon as I deploy it and then access my application through that url, that rest template call written inside my code gives 400 error.
Here is the log trace
400 Bad Request
: org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:524)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:481)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:317)
at com.pekam.myandroid.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:106)
at com.pekam.myandroid.MainActivity$HttpRequestTask.doInBackground(MainActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

Probably there should be an issue in your request. Either you are missing mandatory request parameters in your request XML or missing some headers which throw this 400 Bad request exception.
Please follow this Link.It may resolve your issue. Let us know for any issue.

Related

403 error response from IIS on almost alternate request while load testing api

I have a web api which is deployed on IIS.
Api's are going through load test using load runner and almost on all alternative api call, getting 403 error response code, struggling to identify the issue, call is not going to the API, its returned back from IIS
I am doing bearer token authorization, somehow token which were incoming with each request were not valid, that is why the issue was occurring, to overcome this we have increased the lifetime of token to 1 hour and request load test team to generate the token once and send that token only with each request so that we can now see the proper execution time for each end point.
403 error indicates that access to the requested URL by the client is Forbidden for some reason. you need to provide detailed error message snapshot and what is the sub status code. and check that you assign this permission to the site folder:1) IIS_IUSRS,2)NETWORK SERVICE,3)IUSR

HTTP status code for a resource infected by virus

I'm developing an application which acts as an Http-Proxy for serving files from an external resource. It actually downloads the file from the external resource, checks for viruses and if the file is not infected, returns the file to the client.
My problem is, in case of the file is infected, what HTTP Status code my service should return? I suppose that any type of 4xx error codes is not appropriate for that situation because this class of code is intended for Client errors.
Is a 502 (Bad Gateway) error more appropriate?
Is there any kind of Standard that covers this situation?
I think you are right maestromarko : 502 Bad Gateway. Read the specifications here:
The 502 (Bad Gateway) status code indicates that the server, while
acting as a gateway or proxy, received an invalid response from an
inbound server it accessed while attempting to fulfill the request.
Your proxy is acting as a Gateway and he received what it conciders is invalid as there are virus in it.
It is not a 4xx class error, because whatever the client changes in the request, the result will still be an error.
See also this decision diagram
Http response codes are only meant to handle http specific conditions so I don't think there is a correct answer as such. But some possibilities...
204 - "The server successfully processed the request and is not returning any content"
403 - "The request was valid, but the server is refusing action"
https://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes

Getting Null Exception in GooglePlus Page API

I got an exception frequently while getting and posting activities via GooglePlus Page API. The details are given below:
APIs:
https://www.googleapis.com/plusPages/v2/people/userId/activities/collection
https://www.googleapis.com/plusPages/v2/people/userId/activities
Exception:
{"error":{"message":null,"code":500}}
Can anyone tell me why i am getting the above exception and how to fix this?
I like to call 500 a server hiccup. Normally you can just send the request again and it will work. Why you are getting it only Google knows. Just send it again.
INTERNAL_SERVER_ERROR (500)
Error code Description internalError The request failed due to an
internal error.
You can find it in Googles standard error responses page.

A bad request call to my asmx service causes a http 500 error, what can I do to make it return a http-400 error instead?

I have an ASMX service hosted in IIS 7.5. When it is called with a bad http request (having an empty string value for "host" in the http header), the service returns a http-500 (internal server error). To satisfy company security requirements, it should return a http-400 (bad request) under this situation.
I have verified that the error occurs at the service infrastructure level, and the exception is not thrown from my code. I put try/catch block around the web method but nothing is caught, and the application log has nothing. So the error occurs before my code is executed.
I know WCF can handle the problem gracefully with IErrorHandler; but that's not an option for me at the moment.
Another interesting fact is that when testing inside Visual Studio, the same request causes a 400-error, my desired result.
So my question is: what can I do to make the service hosted under IIS also return a 400 error to a bad request?

Spring Rest Service getting 400 Bad Request after running 2-3 minutes

I have a rest client and server which we have developed using spring. The client will send requests to the server for 2-3 minutes and then starts getting org.springframework.web.client.HttpClientErrorException: 400 Bad Request errors.
Once the 400 error starts the client is unable to communicate with the server.
Any suggestions would be appreciated.
I will try to develop a working example that creates this error.
I have resolved this issue. The code was setting the following for every call:
// Add the Gson message converter
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
I moved this code to the constructor and no longer getting the 400 Bad Request error.

Resources