@Override public String postDomSnapshot(String domJson) { WebTarget target = restClient.target(serverUrl).path(("api/sessions/running/data")).queryParam("apiKey", getApiKey()); byte[] resultStream = GeneralUtils.getGzipByteArrayOutputStream(domJson); Invocation.Builder request = target.request(MediaType.APPLICATION_JSON); Response response = postWithRetry(request, Entity.entity(resultStream, MediaType.APPLICATION_OCTET_STREAM), null); String entity = response.getHeaderString("Location"); return entity; }
@Override public String postDomSnapshot(String domJson) { restClient.register(GZipEncoder.class); WebTarget target = restClient.target(serverUrl).path(("api/sessions/running/data")).queryParam("apiKey", getApiKey()); Invocation.Builder request = target.request(MediaType.APPLICATION_JSON); byte[] resultStream = GeneralUtils.getGzipByteArrayOutputStream(domJson); Response response = postWithRetry(request, Entity.entity(resultStream, MediaType.APPLICATION_OCTET_STREAM), null ); String entity = response.getHeaderString("Location"); return entity; }
private Response postWithRetry(Invocation.Builder request, Entity entity, AtomicInteger retiresCounter) { if (retiresCounter == null) { retiresCounter = new AtomicInteger(0); } try { return request. post(entity); } catch (Exception e) { GeneralUtils.logExceptionStackTrace(e); try { Thread.sleep(THREAD_SLEEP_MILLIS); } catch (InterruptedException e1) { GeneralUtils.logExceptionStackTrace(e); } if(retiresCounter.incrementAndGet() < NUM_OF_RETRIES){ return postWithRetry(request, entity, retiresCounter); } else{ throw e; } } }
private Response postWithRetry(Invocation.Builder request, Entity entity, AtomicInteger retiresCounter) { if (retiresCounter == null) { retiresCounter = new AtomicInteger(0); } try { return request. post(entity); } catch (Exception e) { GeneralUtils.logExceptionStackTrace(e); try { Thread.sleep(THREAD_SLEEP_MILLIS); } catch (InterruptedException e1) { GeneralUtils.logExceptionStackTrace(e); } if(retiresCounter.incrementAndGet() < NUM_OF_RETRIES){ return postWithRetry(request, entity, retiresCounter); } else{ throw e; } } }
Invocation.Builder request = endPoint.queryParam("apiKey", getApiKey()). request(MediaType.APPLICATION_JSON); response = postWithRetry(request, Entity.json(postData), null); } catch (RuntimeException e) { logger.log("Server request failed: " + e.getMessage());
Invocation.Builder request = endPoint.queryParam("apiKey", getApiKey()). request(MediaType.APPLICATION_JSON); response = postWithRetry(request, Entity.json(postData), null); } catch (RuntimeException e) { logger.log("Server request failed: " + e.getMessage());
response = postWithRetry(request, Entity.entity(requestData, MediaType.APPLICATION_OCTET_STREAM), null);
response = postWithRetry(request, Entity.entity(requestData, MediaType.APPLICATION_OCTET_STREAM), null);