public static void prepareRPC(HttpRequest httpRequest) { val context = threadLocal.get(); if (context == null) return; val httpMethod = httpRequest.getHttpMethod().name(); trace("RPC", httpMethod + ":" + httpRequest.getUrl()); httpRequest.header(BLACKCAT_TRACEID, context.getTraceId()); val linkId = context.getParentLinkId() + String.format(".%06d", context.getSubLinkId()); httpRequest.header(BLACKCAT_LINKID, linkId); }
serversAutoupdateMethod = HttpMethod.valueOf(autoupdateMethod.toUpperCase());
private T doWork() { try { setupErrorHandlers(); WorkingContext workingContext = workingContext(); HttpRequest builtRequest = buildUnirest(workingContext) .queryString(workingContext.getQueryParams()) .headers(workingContext.getHeaders()).header("Ocp-Apim-Subscription-Key", cognitiveContext.subscriptionKey); if (!workingContext.getHttpMethod().equals(HttpMethod.GET) && workingContext().getPayload().size() > 0) { buildBody((HttpRequestWithBody) builtRequest); } HttpResponse response; if (typedResponse() == InputStream.class) response = builtRequest.asBinary(); else response = builtRequest.asString(); checkForError(response); return postProcess(typeResponse(response.getBody())); } catch (UnirestException | IOException e) { throw new CognitiveException(e); } }
private JSONArray toArray(BaseRequest request) { try { if (api.isDebug()) { System.out.printf("Requesting %s -> %s\n\tPayload: %s\n\tResponse: ", request.getHttpRequest().getHttpMethod().name(), request.getHttpRequest().getUrl(), ((request instanceof RequestBodyEntity)? ((RequestBodyEntity) request).getBody().toString():"None")); } String body = request.asString().getBody(); if (api.isDebug()) { System.out.println(body); } return body == null ? null : new JSONArray(body); } catch (UnirestException e) { e.printStackTrace(); } return null; }
private JSONObject toObject(BaseRequest request) { try { if (api.isDebug()) { System.out.printf("Requesting %s -> %s\n\tPayload: %s\n\tResponse: ", request.getHttpRequest().getHttpMethod().name(), request.getHttpRequest().getUrl(), ((request instanceof RequestBodyEntity)? ((RequestBodyEntity) request).getBody().toString():"None")); } String body = request.asString().getBody(); if (api.isDebug()) { System.out.println(body); } return body == null ? null : new JSONObject(body); } catch (UnirestException e) { e.printStackTrace(); } return null; }