mirror of
https://github.com/apache/lucene.git
synced 2025-02-09 03:25:15 +00:00
SOLR-8836: Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.
This commit is contained in:
parent
0739f9155b
commit
4deb4cd1ba
@ -437,6 +437,9 @@ Other Changes
|
||||
|
||||
* SOLR-8799: Improve error message when tuple can't be read by SolrJ JDBC (Kevin Risden, Joel Bernstein)
|
||||
|
||||
* SOLR-8836: Return 400, and a SolrException when an invalid json is provided to the update handler
|
||||
instead of 500. (Jason Gerlowski via Anshum Gupta)
|
||||
|
||||
================== 5.5.1 ==================
|
||||
|
||||
Bug Fixes
|
||||
|
@ -50,6 +50,7 @@ import org.apache.solr.update.RollbackUpdateCommand;
|
||||
import org.apache.solr.update.processor.UpdateRequestProcessor;
|
||||
import org.apache.solr.util.RecordingJSONParser;
|
||||
import org.noggit.JSONParser;
|
||||
import org.noggit.JSONParser.ParseException;
|
||||
import org.noggit.ObjectBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -111,7 +112,10 @@ public class JsonLoader extends ContentStreamLoader {
|
||||
}
|
||||
|
||||
this.processUpdate(reader);
|
||||
} finally {
|
||||
} catch (ParseException e) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot parse provided JSON: " + e.getMessage());
|
||||
}
|
||||
finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,26 @@ public class JsonLoaderTest extends SolrTestCaseJ4 {
|
||||
req.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidJsonProducesBadRequestSolrException() throws Exception
|
||||
{
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
|
||||
JsonLoader loader = new JsonLoader();
|
||||
String invalidJsonString = "}{";
|
||||
|
||||
try(SolrQueryRequest req = req()) {
|
||||
try {
|
||||
loader.load(req, rsp, new ContentStreamBase.StringStream(invalidJsonString), p);
|
||||
fail("Expected invalid JSON to produce a SolrException.");
|
||||
} catch (SolrException expectedException) {
|
||||
assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, expectedException.code());
|
||||
assertTrue(expectedException.getMessage().contains("Cannot parse"));
|
||||
assertTrue(expectedException.getMessage().contains("JSON"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testSimpleFormatInAdd() throws Exception
|
||||
{
|
||||
String str = "{'add':[{'id':'1'},{'id':'2'}]}".replace('\'', '"');
|
||||
|
Loading…
x
Reference in New Issue
Block a user