public static InputStream post( String url, CharSequence data, Map<String, String> headers, int cTimeout, int rTimeout) throws IOException { return executeMethod(data == null ? "GET" : "POST", url, data, headers, cTimeout, rTimeout); }
/** Reads data source names from Druid. */ Set<String> tableNames() { final Map<String, String> requestHeaders = ImmutableMap.of("Content-Type", "application/json"); final String data = null; final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources"; if (CalcitePrepareImpl.DEBUG) { System.out.println("Druid: table names" + data + "; " + url); } try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { final ObjectMapper mapper = new ObjectMapper(); final CollectionType listType = mapper.getTypeFactory().constructCollectionType(List.class, String.class); final List<String> list = mapper.readValue(in, listType); return ImmutableSet.copyOf(list); } catch (IOException e) { throw new RuntimeException(e); } }
public static InputStream executeMethod( String method, String url, CharSequence data, Map<String, String> headers, int cTimeout, int rTimeout) throws IOException { // NOTE: do not log "data" or "url"; may contain user name or password. final HttpURLConnection conn = getURLConnection(url); conn.setRequestMethod(method); conn.setReadTimeout(rTimeout); conn.setConnectTimeout(cTimeout); if (headers != null) { for (Map.Entry<String, String> me : headers.entrySet()) { conn.setRequestProperty(me.getKey(), me.getValue()); } } if (data == null) { return conn.getInputStream(); } conn.setDoOutput(true); try (Writer w = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8)) { w.write(data.toString()); w.flush(); // Get the response return conn.getInputStream(); } } }
/** Reads data source names from Druid. */ Set<String> tableNames() { final Map<String, String> requestHeaders = ImmutableMap.of("Content-Type", "application/json"); final String data = null; final String url = coordinatorUrl + "/druid/coordinator/v1/metadata/datasources"; if (CalcitePrepareImpl.DEBUG) { System.out.println("Druid: table names" + data + "; " + url); } try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { final ObjectMapper mapper = new ObjectMapper(); final CollectionType listType = mapper.getTypeFactory().constructCollectionType(List.class, String.class); final List<String> list = mapper.readValue(in, listType); return ImmutableSet.copyOf(list); } catch (IOException e) { throw new RuntimeException(e); } }
public static InputStream executeMethod( String method, String url, CharSequence data, Map<String, String> headers, int cTimeout, int rTimeout) throws IOException { // NOTE: do not log "data" or "url"; may contain user name or password. final HttpURLConnection conn = getURLConnection(url); conn.setRequestMethod(method); conn.setReadTimeout(rTimeout); conn.setConnectTimeout(cTimeout); if (headers != null) { for (Map.Entry<String, String> me : headers.entrySet()) { conn.setRequestProperty(me.getKey(), me.getValue()); } } if (data == null) { return conn.getInputStream(); } conn.setDoOutput(true); try (Writer w = new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8)) { w.write(data.toString()); w.flush(); // Get the response return conn.getInputStream(); } } }
/** Executes a query request. * * @param queryType Query type * @param data Data to post * @param sink Sink to which to send the parsed rows * @param fieldNames Names of fields * @param fieldTypes Types of fields (never null, but elements may be null) * @param page Page definition (in/out) */ public void request(QueryType queryType, String data, Sink sink, List<String> fieldNames, List<ColumnMetaData.Rep> fieldTypes, Page page) { final String url = this.url + "/druid/v2/?pretty"; final Map<String, String> requestHeaders = ImmutableMap.of("Content-Type", "application/json"); if (CalcitePrepareImpl.DEBUG) { System.out.println(data); } try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { parse(queryType, in, sink, fieldNames, fieldTypes, page); } catch (IOException e) { throw new RuntimeException("Error while processing druid request [" + data + "]", e); } }
public static InputStream post( String url, CharSequence data, Map<String, String> headers, int cTimeout, int rTimeout) throws IOException { return executeMethod(data == null ? "GET" : "POST", url, data, headers, cTimeout, rTimeout); }
/** Executes a query request. * * @param queryType Query type * @param data Data to post * @param sink Sink to which to send the parsed rows * @param fieldNames Names of fields * @param fieldTypes Types of fields (never null, but elements may be null) * @param page Page definition (in/out) */ public void request(QueryType queryType, String data, Sink sink, List<String> fieldNames, List<ColumnMetaData.Rep> fieldTypes, Page page) { final String url = this.url + "/druid/v2/?pretty"; final Map<String, String> requestHeaders = ImmutableMap.of("Content-Type", "application/json"); if (CalcitePrepareImpl.DEBUG) { System.out.println(data); } try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { parse(queryType, in, sink, fieldNames, fieldTypes, page); } catch (IOException e) { throw new RuntimeException("Error while processing druid request [" + data + "]", e); } }
System.out.println("Druid: " + data); try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { final ObjectMapper mapper = new ObjectMapper()
System.out.println("Druid: " + data); try (InputStream in0 = post(url, data, requestHeaders, 10000, 1800000); InputStream in = traceResponse(in0)) { final ObjectMapper mapper = new ObjectMapper()