Search in sources :

Example 1 with InputStreamResponseParser

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

the class SolrStream method constructParser.

// temporary...
public TupleStreamParser constructParser(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException {
    String p = requestParams.get("qt");
    if (p != null) {
        ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
        modifiableSolrParams.remove("qt");
    }
    String wt = requestParams.get(CommonParams.WT, "json");
    QueryRequest query = new QueryRequest(requestParams);
    query.setPath(p);
    query.setResponseParser(new InputStreamResponseParser(wt));
    query.setMethod(SolrRequest.METHOD.POST);
    NamedList<Object> genericResponse = server.request(query);
    InputStream stream = (InputStream) genericResponse.get("stream");
    this.closeableHttpResponse = (CloseableHttpResponse) genericResponse.get("closeableResponse");
    if (CommonParams.JAVABIN.equals(wt)) {
        return new JavabinTupleStreamParser(stream, true);
    } else {
        InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
        return new JSONTupleStream(reader);
    }
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) InputStreamReader(java.io.InputStreamReader) InputStreamResponseParser(org.apache.solr.client.solrj.impl.InputStreamResponseParser) InputStream(java.io.InputStream) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 2 with InputStreamResponseParser

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

the class JSONTupleStream method create.

// temporary...
public static JSONTupleStream create(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException {
    String p = requestParams.get("qt");
    if (p != null) {
        ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
        modifiableSolrParams.remove("qt");
    }
    QueryRequest query = new QueryRequest(requestParams);
    query.setPath(p);
    query.setResponseParser(new InputStreamResponseParser("json"));
    query.setMethod(SolrRequest.METHOD.POST);
    NamedList<Object> genericResponse = server.request(query);
    InputStream stream = (InputStream) genericResponse.get("stream");
    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
    return new JSONTupleStream(reader);
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) InputStreamReader(java.io.InputStreamReader) InputStreamResponseParser(org.apache.solr.client.solrj.impl.InputStreamResponseParser) InputStream(java.io.InputStream) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 3 with InputStreamResponseParser

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

the class TestSQLHandler method assertResponseContains.

public void assertResponseContains(SolrClient server, SolrParams requestParams, String json) throws IOException, SolrServerException {
    String p = requestParams.get("qt");
    if (p != null) {
        ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
        modifiableSolrParams.remove("qt");
    }
    QueryRequest query = new QueryRequest(requestParams);
    query.setPath(p);
    query.setResponseParser(new InputStreamResponseParser("json"));
    query.setMethod(SolrRequest.METHOD.POST);
    NamedList<Object> genericResponse = server.request(query);
    InputStream stream = (InputStream) genericResponse.get("stream");
    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
    BufferedReader bufferedReader = new BufferedReader(reader);
    String response = bufferedReader.readLine();
    assertTrue(response.contains(json));
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) InputStreamReader(java.io.InputStreamReader) InputStreamResponseParser(org.apache.solr.client.solrj.impl.InputStreamResponseParser) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 4 with InputStreamResponseParser

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

the class GraphExpressionTest method testGraphHandler.

@Test
public void testGraphHandler() throws Exception {
    new UpdateRequest().add(id, "0", "from_s", "bill", "to_s", "jim", "message_t", "Hello jim").add(id, "1", "from_s", "bill", "to_s", "sam", "message_t", "Hello sam").add(id, "2", "from_s", "bill", "to_s", "max", "message_t", "Hello max").add(id, "3", "from_s", "max", "to_s", "kip", "message_t", "Hello kip").add(id, "4", "from_s", "sam", "to_s", "steve", "message_t", "Hello steve").add(id, "5", "from_s", "jim", "to_s", "ann", "message_t", "Hello steve").commit(cluster.getSolrClient(), COLLECTION);
    commit();
    List<JettySolrRunner> runners = cluster.getJettySolrRunners();
    JettySolrRunner runner = runners.get(0);
    String url = runner.getBaseUrl().toString();
    HttpSolrClient client = getHttpSolrClient(url);
    ModifiableSolrParams params = new ModifiableSolrParams();
    String expr = "sort(by=\"node asc\", gatherNodes(collection1, " + "walk=\"bill->from_s\"," + "trackTraversal=\"true\"," + "gather=\"to_s\"))";
    params.add("expr", expr);
    QueryRequest query = new QueryRequest(params);
    query.setPath("/collection1/graph");
    query.setResponseParser(new InputStreamResponseParser("xml"));
    query.setMethod(SolrRequest.METHOD.POST);
    NamedList<Object> genericResponse = client.request(query);
    InputStream stream = (InputStream) genericResponse.get("stream");
    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
    String xml = readString(reader);
    //Validate the nodes
    String error = h.validateXPath(xml, "//graph/node[1][@id ='jim']", "//graph/node[2][@id ='max']", "//graph/node[3][@id ='sam']");
    if (error != null) {
        throw new Exception(error);
    }
    //Validate the edges
    error = h.validateXPath(xml, "//graph/edge[1][@source ='bill']", "//graph/edge[1][@target ='jim']", "//graph/edge[2][@source ='bill']", "//graph/edge[2][@target ='max']", "//graph/edge[3][@source ='bill']", "//graph/edge[3][@target ='sam']");
    if (error != null) {
        throw new Exception(error);
    }
    client.close();
}
Also used : QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) InputStreamReader(java.io.InputStreamReader) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) InputStreamResponseParser(org.apache.solr.client.solrj.impl.InputStreamResponseParser) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) InputStream(java.io.InputStream) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IOException(java.io.IOException) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 InputStreamResponseParser (org.apache.solr.client.solrj.impl.InputStreamResponseParser)4 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)4 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)4 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 Test (org.junit.Test)1