use of org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser in project lucene-solr by apache.
the class SolrRequestParserTest method testParameterIncompatibilityException2.
@Test
public void testParameterIncompatibilityException2() throws Exception {
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
when(request.getMethod()).thenReturn("POST");
// we emulate Tomcat that throws IllegalStateException when parameters were parsed before:
when(request.getInputStream()).thenThrow(new IllegalStateException());
FormDataRequestParser formdata = new FormDataRequestParser(2048);
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
verify(request).getInputStream();
}
use of org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser in project lucene-solr by apache.
the class SolrRequestParserTest method testParameterIncompatibilityException1.
@Test
public void testParameterIncompatibilityException1() throws Exception {
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", 100);
// we emulate Jetty that returns empty stream when parameters were parsed before:
when(request.getInputStream()).thenReturn(new ServletInputStream() {
@Override
public int read() {
return -1;
}
@Override
public boolean isFinished() {
return true;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
}
});
FormDataRequestParser formdata = new FormDataRequestParser(2048);
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().startsWith("Solr requires that request parameters"));
assertEquals(500, solre.code());
}
verify(request).getInputStream();
}
use of org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser in project lucene-solr by apache.
the class SolrRequestParserTest method testStandardFormdataUploadLimit.
@Test
public void testStandardFormdataUploadLimit() throws Exception {
final int limitKBytes = 128;
final StringBuilder large = new StringBuilder("q=hello");
// grow exponentially to reach 128 KB limit:
while (large.length() <= limitKBytes * 1024) {
large.append('&').append(large);
}
HttpServletRequest request = getMock("/solr/select", "application/x-www-form-urlencoded", -1);
when(request.getMethod()).thenReturn("POST");
when(request.getInputStream()).thenReturn(new ByteServletInputStream(large.toString().getBytes(StandardCharsets.US_ASCII)));
FormDataRequestParser formdata = new FormDataRequestParser(limitKBytes);
try {
formdata.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
fail("should throw SolrException");
} catch (SolrException solre) {
assertTrue(solre.getMessage().contains("upload limit"));
assertEquals(400, solre.code());
}
verify(request).getInputStream();
}
use of org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser in project lucene-solr by apache.
the class SolrRequestParserTest method testStandardParseParamsAndFillStreamsISO88591.
@Test
public void testStandardParseParamsAndFillStreamsISO88591() throws Exception {
final String getParams = "qt=%FC&dup=foo&ie=iso-8859-1&dup=%FC", postParams = "qt2=%FC&q=hello&d%75p=bar";
final byte[] postBytes = postParams.getBytes(StandardCharsets.US_ASCII);
final String contentType = "application/x-www-form-urlencoded; charset=iso-8859-1";
// Set up the expected behavior
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
when(request.getMethod()).thenReturn("POST");
when(request.getQueryString()).thenReturn(getParams);
when(request.getInputStream()).thenReturn(new ByteServletInputStream(postBytes));
MultipartRequestParser multipart = new MultipartRequestParser(2048);
RawRequestParser raw = new RawRequestParser();
FormDataRequestParser formdata = new FormDataRequestParser(2048);
StandardRequestParser standard = new StandardRequestParser(multipart, raw, formdata);
SolrParams p = standard.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
assertEquals("contentType: " + contentType, "hello", p.get("q"));
assertEquals("contentType: " + contentType, "ü", p.get("qt"));
assertEquals("contentType: " + contentType, "ü", p.get("qt2"));
assertArrayEquals("contentType: " + contentType, new String[] { "foo", "ü", "bar" }, p.getParams("dup"));
verify(request).getInputStream();
}
use of org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser in project lucene-solr by apache.
the class SolrRequestParserTest method testStandardParseParamsAndFillStreams.
@Test
public void testStandardParseParamsAndFillStreams() throws Exception {
final String getParams = "qt=%C3%BC&dup=foo", postParams = "q=hello&d%75p=bar";
final byte[] postBytes = postParams.getBytes(StandardCharsets.US_ASCII);
// Set up the expected behavior
final String[] ct = new String[] { "application/x-www-form-urlencoded", "Application/x-www-form-urlencoded", "application/x-www-form-urlencoded; charset=utf-8", "application/x-www-form-urlencoded;" };
for (String contentType : ct) {
HttpServletRequest request = getMock("/solr/select", contentType, postBytes.length);
when(request.getMethod()).thenReturn("POST");
when(request.getQueryString()).thenReturn(getParams);
when(request.getInputStream()).thenReturn(new ByteServletInputStream(postBytes));
MultipartRequestParser multipart = new MultipartRequestParser(2048);
RawRequestParser raw = new RawRequestParser();
FormDataRequestParser formdata = new FormDataRequestParser(2048);
StandardRequestParser standard = new StandardRequestParser(multipart, raw, formdata);
SolrParams p = standard.parseParamsAndFillStreams(request, new ArrayList<ContentStream>());
assertEquals("contentType: " + contentType, "hello", p.get("q"));
assertEquals("contentType: " + contentType, "ü", p.get("qt"));
assertArrayEquals("contentType: " + contentType, new String[] { "foo", "bar" }, p.getParams("dup"));
verify(request).getInputStream();
}
}
Aggregations