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);
}
}
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);
}
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));
}
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();
}
Aggregations