Java client with Apache HttpClient to connect to Druid -
i working on ingesting , query data on druid server. but, when query using command line below:
curl -x 'post' -h 'content-type:application/json' -d @quickstart/ingest_statistic_hourly_generate.json localhost:8090/druid/indexer/v1/task
can tell me way of utilizing java client apache httpclient send query druid server response. much.
i have not tested , should give fair idea of doing this
import java.io.bufferedreader; import java.io.inputstreamreader; import java.nio.file.files; import java.nio.file.paths; import org.apache.http.httpresponse; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httppost; import org.apache.http.entity.stringentity; import org.apache.http.impl.client.httpclientbuilder; public class httptestclient { public static void main(string[] args) throws exception { string url = "http://localhost:8090/druid/indexer/v1/task"; string content = new string(files.readallbytes(paths.get("quickstart/ingest_statistic_hourly_generate.json"))); httpclient client = httpclientbuilder.create().build(); httppost post = new httppost(url); post.addheader("accept", "application/json"); post.addheader("charset", "utf-8"); post.addheader("content-type", "application/json"); post.setentity(new stringentity(content)); httpresponse response = client.execute(post); system.out.println(response.getstatusline()); system.out.println("response code : " + response); bufferedreader rd = new bufferedreader(new inputstreamreader(response.getentity().getcontent())); stringbuffer result = new stringbuffer(); string line = ""; while ((line = rd.readline()) != null) { result.append(line); } system.out.println(result); } }
Comments
Post a Comment