Search in sources :

Example 1 with StandardRequestParser

use of org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser 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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FormDataRequestParser(org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser) ContentStream(org.apache.solr.common.util.ContentStream) RawRequestParser(org.apache.solr.servlet.SolrRequestParsers.RawRequestParser) SolrParams(org.apache.solr.common.params.SolrParams) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) MultipartRequestParser(org.apache.solr.servlet.SolrRequestParsers.MultipartRequestParser) StandardRequestParser(org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser) Test(org.junit.Test)

Example 2 with StandardRequestParser

use of org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser 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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FormDataRequestParser(org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser) ContentStream(org.apache.solr.common.util.ContentStream) RawRequestParser(org.apache.solr.servlet.SolrRequestParsers.RawRequestParser) SolrParams(org.apache.solr.common.params.SolrParams) MultiMapSolrParams(org.apache.solr.common.params.MultiMapSolrParams) MultipartRequestParser(org.apache.solr.servlet.SolrRequestParsers.MultipartRequestParser) StandardRequestParser(org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser) Test(org.junit.Test)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MultiMapSolrParams (org.apache.solr.common.params.MultiMapSolrParams)2 SolrParams (org.apache.solr.common.params.SolrParams)2 ContentStream (org.apache.solr.common.util.ContentStream)2 FormDataRequestParser (org.apache.solr.servlet.SolrRequestParsers.FormDataRequestParser)2 MultipartRequestParser (org.apache.solr.servlet.SolrRequestParsers.MultipartRequestParser)2 RawRequestParser (org.apache.solr.servlet.SolrRequestParsers.RawRequestParser)2 StandardRequestParser (org.apache.solr.servlet.SolrRequestParsers.StandardRequestParser)2 Test (org.junit.Test)2