Search in sources :

Example 6 with ResponseParser

use of org.apache.solr.client.solrj.ResponseParser in project lucene-solr by apache.

the class LBHttpSolrClientBuilderTest method testDefaultsToBinaryResponseParserWhenNoneProvided.

@Test
public void testDefaultsToBinaryResponseParserWhenNoneProvided() {
    try (LBHttpSolrClient createdClient = new Builder().withBaseSolrUrl(ANY_BASE_SOLR_URL).build()) {
        final ResponseParser usedParser = createdClient.getParser();
        assertTrue(usedParser instanceof BinaryResponseParser);
    }
}
Also used : ResponseParser(org.apache.solr.client.solrj.ResponseParser) Builder(org.apache.solr.client.solrj.impl.LBHttpSolrClient.Builder) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) Test(org.junit.Test)

Example 7 with ResponseParser

use of org.apache.solr.client.solrj.ResponseParser in project lucene-solr by apache.

the class LBHttpSolrClientTest method testLBHttpSolrClientHttpClientResponseParserStringArray.

/**
   * Test method for {@link LBHttpSolrClient#LBHttpSolrClient(org.apache.http.client.HttpClient, org.apache.solr.client.solrj.ResponseParser, java.lang.String[])}.
   * 
   * Validate that the parser passed in is used in the <code>HttpSolrClient</code> instances created.
   */
@Test
public void testLBHttpSolrClientHttpClientResponseParserStringArray() throws IOException {
    CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
    try (LBHttpSolrClient testClient = new LBHttpSolrClient(httpClient, (ResponseParser) null);
        HttpSolrClient httpSolrClient = testClient.makeSolrClient("http://127.0.0.1:8080")) {
        assertNull("Generated server should have null parser.", httpSolrClient.getParser());
    } finally {
        HttpClientUtil.close(httpClient);
    }
    ResponseParser parser = new BinaryResponseParser();
    httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
    try {
        try (LBHttpSolrClient testClient = new LBHttpSolrClient(httpClient, parser);
            HttpSolrClient httpSolrClient = testClient.makeSolrClient("http://127.0.0.1:8080")) {
            assertEquals("Invalid parser passed to generated server.", parser, httpSolrClient.getParser());
        }
    } finally {
        HttpClientUtil.close(httpClient);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResponseParser(org.apache.solr.client.solrj.ResponseParser) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 8 with ResponseParser

use of org.apache.solr.client.solrj.ResponseParser in project lucene-solr by apache.

the class NoOpResponseParserTest method assertResponse.

private void assertResponse(String responseString) throws IOException {
    ResponseParser xmlResponseParser = new XMLResponseParser();
    NamedList expectedResponse = xmlResponseParser.processResponse(IOUtils.toInputStream(responseString, "UTF-8"), "UTF-8");
    List<SolrDocument> documentList = (List<SolrDocument>) expectedResponse.getAll("response").get(0);
    assertEquals(1, documentList.size());
    SolrDocument solrDocument = documentList.get(0);
    assertEquals("1234", String.valueOf(solrDocument.getFieldValue("id")));
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) ResponseParser(org.apache.solr.client.solrj.ResponseParser) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) NoOpResponseParser(org.apache.solr.client.solrj.impl.NoOpResponseParser) NamedList(org.apache.solr.common.util.NamedList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser)

Aggregations

ResponseParser (org.apache.solr.client.solrj.ResponseParser)8 Test (org.junit.Test)3 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)2 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 NamedList (org.apache.solr.common.util.NamedList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Header (org.apache.http.Header)1 NameValuePair (org.apache.http.NameValuePair)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1 HttpDelete (org.apache.http.client.methods.HttpDelete)1