[
https://issues.apache.org/jira/browse/SOLR-11760?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Chantal Ackermann updated SOLR-11760:
-------------------------------------
Description:
We generally request JSON from SOLR, via HTTP with {{wt=json}} (without using a
client impl).
In case of fundamental errors, however, no JSON is returned but XML (either
because {{wt=json}} is not transmitted correctly or the request handler that
understands this parameter is not executed). It would be nice if in this case
the `Accept:application/json` header could be honored.
{code}
$ http http://localhost:8983/solr/offers_gb/select q==*:* wt=json rows=1
Accept:"application/json" -v
POST /solr/offers_gb/select?q=%2A%3A%2A HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 27
Content-Type: application/json
Host: localhost:8983
User-Agent: HTTPie/0.9.4
{
"rows": "1",
"wt": "json"
}
HTTP/1.1 400 Bad Request
Content-Length: 525
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int
name="QTime">0</int><lst name="params"><str name="q">*:*</str><str
name="json">{"wt": "json", "rows": "1"}</str></lst></lst><lst name="error"><lst
name="metadata"><str
name="error-class">org.apache.solr.common.SolrException</str><str
name="root-error-class">org.apache.solr.common.SolrException</str></lst><str
name="msg">Unknown top-level key in JSON request : wt</str><int
name="code">400</int></lst>
</response>
{code}
As opposed to:
{code}
$ http http://localhost:8983/solr/offers_gb/select q==bla:* wt==json rows==1
Accept:"application/json" -v
GET /solr/offers_gb/select?q=bla%3A%2A&wt=json&rows=1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8983
User-Agent: HTTPie/0.9.4
HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store
Content-Length: 282
Content-Type: application/json; charset=UTF-8
ETag: "1605105208b"
Expires: Sat, 01 Jan 2000 01:00:00 GMT
Last-Modified: Wed, 13 Dec 2017 17:56:18 GMT
Pragma: no-cache
{
"error": {
"code": 400,
"metadata": [
"error-class",
"org.apache.solr.common.SolrException",
"root-error-class",
"org.apache.solr.common.SolrException"
],
"msg": "undefined field bla"
},
"responseHeader": {
"QTime": 0,
"params": {
"q": "bla:*",
"rows": "1",
"wt": "json"
},
"status": 400,
"zkConnected": true
}
}
{code}
was:
We generally request JSON from SOLR, via HTTP with {{wt=json}} (without using a
client impl).
In certain error cases, however, no JSON is returned but XML, most likely
because the request handler that understands the parameter {{wt=json}} is not
even executed if the error is a fundamental one. It would be nice if in this
case the `Accept:application/json` header could be honored.
{code}
$ http http://localhost:8983/solr/offers_gb/select q==*:* wt=json rows=1
Accept:"application/json" -v
POST /solr/offers_gb/select?q=%2A%3A%2A HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 27
Content-Type: application/json
Host: localhost:8983
User-Agent: HTTPie/0.9.4
{
"rows": "1",
"wt": "json"
}
HTTP/1.1 400 Bad Request
Content-Length: 525
Content-Type: application/xml; charset=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int
name="QTime">0</int><lst name="params"><str name="q">*:*</str><str
name="json">{"wt": "json", "rows": "1"}</str></lst></lst><lst name="error"><lst
name="metadata"><str
name="error-class">org.apache.solr.common.SolrException</str><str
name="root-error-class">org.apache.solr.common.SolrException</str></lst><str
name="msg">Unknown top-level key in JSON request : wt</str><int
name="code">400</int></lst>
</response>
{code}
As opposed to:
{code}
$ http http://localhost:8983/solr/offers_gb/select q==bla:* wt==json rows==1
Accept:"application/json" -v
GET /solr/offers_gb/select?q=bla%3A%2A&wt=json&rows=1 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8983
User-Agent: HTTPie/0.9.4
HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store
Content-Length: 282
Content-Type: application/json; charset=UTF-8
ETag: "1605105208b"
Expires: Sat, 01 Jan 2000 01:00:00 GMT
Last-Modified: Wed, 13 Dec 2017 17:56:18 GMT
Pragma: no-cache
{
"error": {
"code": 400,
"metadata": [
"error-class",
"org.apache.solr.common.SolrException",
"root-error-class",
"org.apache.solr.common.SolrException"
],
"msg": "undefined field bla"
},
"responseHeader": {
"QTime": 0,
"params": {
"q": "bla:*",
"rows": "1",
"wt": "json"
},
"status": 400,
"zkConnected": true
}
}
{code}
> Accept Header is not honored / Errors returned in XML instead of JSON
> ---------------------------------------------------------------------
>
> Key: SOLR-11760
> URL: https://issues.apache.org/jira/browse/SOLR-11760
> Project: Solr
> Issue Type: Bug
> Security Level: Public(Default Security Level. Issues are Public)
> Components: Response Writers
> Affects Versions: 6.6
> Reporter: Chantal Ackermann
> Priority: Minor
>
> We generally request JSON from SOLR, via HTTP with {{wt=json}} (without using
> a client impl).
> In case of fundamental errors, however, no JSON is returned but XML (either
> because {{wt=json}} is not transmitted correctly or the request handler that
> understands this parameter is not executed). It would be nice if in this case
> the `Accept:application/json` header could be honored.
> {code}
> $ http http://localhost:8983/solr/offers_gb/select q==*:* wt=json rows=1
> Accept:"application/json" -v
> POST /solr/offers_gb/select?q=%2A%3A%2A HTTP/1.1
> Accept: application/json
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Content-Length: 27
> Content-Type: application/json
> Host: localhost:8983
> User-Agent: HTTPie/0.9.4
> {
> "rows": "1",
> "wt": "json"
> }
> HTTP/1.1 400 Bad Request
> Content-Length: 525
> Content-Type: application/xml; charset=UTF-8
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
> <lst name="responseHeader"><int name="status">400</int><int
> name="QTime">0</int><lst name="params"><str name="q">*:*</str><str
> name="json">{"wt": "json", "rows": "1"}</str></lst></lst><lst
> name="error"><lst name="metadata"><str
> name="error-class">org.apache.solr.common.SolrException</str><str
> name="root-error-class">org.apache.solr.common.SolrException</str></lst><str
> name="msg">Unknown top-level key in JSON request : wt</str><int
> name="code">400</int></lst>
> </response>
> {code}
> As opposed to:
> {code}
> $ http http://localhost:8983/solr/offers_gb/select q==bla:* wt==json rows==1
> Accept:"application/json" -v
> GET /solr/offers_gb/select?q=bla%3A%2A&wt=json&rows=1 HTTP/1.1
> Accept: application/json
> Accept-Encoding: gzip, deflate
> Connection: keep-alive
> Host: localhost:8983
> User-Agent: HTTPie/0.9.4
> HTTP/1.1 400 Bad Request
> Cache-Control: no-cache, no-store
> Content-Length: 282
> Content-Type: application/json; charset=UTF-8
> ETag: "1605105208b"
> Expires: Sat, 01 Jan 2000 01:00:00 GMT
> Last-Modified: Wed, 13 Dec 2017 17:56:18 GMT
> Pragma: no-cache
> {
> "error": {
> "code": 400,
> "metadata": [
> "error-class",
> "org.apache.solr.common.SolrException",
> "root-error-class",
> "org.apache.solr.common.SolrException"
> ],
> "msg": "undefined field bla"
> },
> "responseHeader": {
> "QTime": 0,
> "params": {
> "q": "bla:*",
> "rows": "1",
> "wt": "json"
> },
> "status": 400,
> "zkConnected": true
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]