How to customize ServletResponse in Apache Solr? - solr

Current behavior:
No matter what the response is, as long as we can get valid reponse (for example, JSON) from Solr, the http status code is always 200.
Expected behavior:
Within JSON response, we currently have other status codes such as 500(Internal Server Error) to be returned, and we need to change the response status code into 500 in http response header.
I know we can parse the response JSON, grab the status code and set it as http response code in a specific filter in filter chain, it may not be expensive, but obviously it takes time.
I am wondering if there is a way to overwrite the http status code when generating the JSON response in solr, so we don't need to do extra work in filter chain? I need it for both Solr 1.4 and Solr 4.0
Thanks for any help.

Related

Unable to fetch payload.access_token value after hitting salesforce using http connector. how to extract access_token value?

I am hitting salesforce which is giving me application/x-www-form-urlencoded JSON which looks like this
{"access_token":"00D5j0008yLhA!ARwAQBufl2Y6S1Tu3AU5zUWBCb442Nj2JqwWFOkm3AFL16CQZleLO.mnZwlDFttOMEnldbt_WqJBzhLrh1mgI1XEIvAN8sAM","instance_url":"https://cloudceitude-13a-dev-ed.my.salesforce.com","id":"https://login.salesforce.com/id/00D5j00000LhAEAU/0055j000004TZbAAAW","token_type":"Bearer","issued_at":"1668188564383","signature":"LQbWIODP8pqE+wD1yjgbVUBxMDI6YV1HjENZUeK/eoY="}
but when I am trying to access value of access_token using payload.access_token it is giving me error
I have tried by transforming into JSON using Transform connector using
%dw 2.0
output application/json
​---
payload
still after I tried to access my token it shows same error
and also while debugging map function is not working while working on Payload in DataWeave but instead when I use MapObject It reflect this:
key=%7B%22access_token%22%3A%2200D5j000008yLhA%21ARwAQIN5UGZWtk8Ucu8MUNgbnHAKleeqAk2M73Afy9iRKNEKRppu4C7Drfi0hg8q5t8C.PYX7RsMMXQPsjxmpVB1Ev_pU.2p%22%2C%22instance_url%22%3A%22https%3A%2F%2Fcloudcertitude-13a-dev-ed.my.salesforce.com%22%2C%22id%22%3A%22https%3A%2F%2Flogin.salesforce.com%2Fid%2F00D5j000008yLhAEAU%2F0055j000004TZbAAAW%22%2C%22token_type%22%3A%22Bearer%22%2C%22issued_at%22%3A%221668330168420%22%2C%22signature%22%3A%22kkDnnUe9pZfiqiuEjRi02az0lwpAlmwmv3cMRmF9nRU
I'll make an educated guess that the application or the server are somehow forcing the media type of the response to be application/x-www-form-urlencoded when it really is a JSON. The request for a token should be application/x-www-form-urlencoded, the response should be a JSON (application/json). If the server is returning it you should check with the administrators of that server. However if the application is overriding the content type of the response you should fix it.

ELK - How to match http request and response and store it as a single line of record?

I have seen a log in Kibana where the http request and response was displayed in a single line/record.
My Kibana setup currently displays the request and response in separate lines/records.
How do i customize and ultimately achieve this?
"Multiline" codec is the tool for this.

Get HTTP status code from a response coming as empty with $http service

I'm having trouble getting the HTTP status code from a empty response that is empty. status code is required to show the corresponding message that happened.
I Tried everything but couldn't get the http status code from the response. Does anyone have an idea ?
I believe this server is broken. I don't think there's a circumstance where POST can result in a 304 Not Modified response.
Usually 304 Not Modified is in response to a GET or HEAD request, when If-Match or If-Modified-Since is used.
However, if those headers are used for other HTTP requests (such as POST), the correct response is 412 Precondition Failed.
You usually never see a 304, because when it's used correctly (with GET), the browser will still not expose the 304, but instead it will give you a 200 and a response that's served directly from cache.
So in short, my best guess is that you can't, because your server doesn't conform with HTTP all assumptions are kind of out of the window.
A Promise that will be resolved (request success) or rejected (request failure) with a response object.
The response object has these properties:
data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.
xhrStatus – {string} – Status of the XMLHttpRequest (complete, error, timeout or abort).
So in your case you can add second parameter as status to get status code

duplicate ajax calls in angularjs

I am using express-jwt to build a restful api. Now the client is making duplicate ajax calls, for the first one the initiator is angularjs and for the second one the initiator is other. The first one gets 204 as the response code and the second one gets 200 as the response code. I tried to debug to get to the source of this duplicate requests, but I am not able to.
Below is the header details for the one with 204 status code
Below is the header details for the one with 204 status code
Can any one suggest what could be the issue?
The first call is OPTIONS type. That's a pre-flight call which a browser sends if the page and api are not on same domain.
The purpose of this call is to deal with CORS. Backend usually needs to send the allowed request method types (GET, POST etc.). The browser will then send the real call if the desired request type is among those returned.
Here's a sample of the response headers.
You can ignore it for all intents and purposes. It does not contain any normally useful payload or return data.
Take a look at AJAX in Chrome sending OPTIONS instead of GET/POST/PUT/DELETE? for more info.
Those two requests are different one is OPTIONS and other is GET.
For cross-domain requests, setting the content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or text/plain will trigger the browser to send a preflight OPTIONS request to the server.
You need to handle in the server when the request method OPTIONS , then you need to exit with out processing.

Prevent angular $http.get from returning 304 response

My backend returns different data for some get requests depending on the user's session data. I would like to force angular to not use cache for certain get requests so that it can retrieve the latest data from the server. I have tried a few things but I keep getting back a 304 not modified response when repeating the same get request. Any suggestions on how to fix this?

Resources