Refine search
/** * Performs a POST using the specified url and entity body. * * @param uri the URI to post to * @param entity the item to post * @return the client response of the request */ public Response post(URI uri, Object entity) { // get the resource Invocation.Builder builder = client.target(uri).request().accept(MediaType.APPLICATION_JSON); // perform the request return builder.post(Entity.json(entity)); }
@Override public int auth(final RegistryAuth registryAuth) throws DockerException, InterruptedException { final WebTarget resource = resource().path("auth"); final Response response = request(POST, Response.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(registryAuth)); return response.getStatus(); }
@Override public EurekaHttpResponse<ReplicationListResponse> submitBatchUpdates(ReplicationList replicationList) { Response response = null; try { response = jerseyClient.target(serviceUrl) .path(PeerEurekaNode.BATCH_URL_PATH) .request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.json(replicationList)); if (!isSuccess(response.getStatus())) { return anEurekaHttpResponse(response.getStatus(), ReplicationListResponse.class).build(); } ReplicationListResponse batchResponse = response.readEntity(ReplicationListResponse.class); return anEurekaHttpResponse(response.getStatus(), batchResponse).type(MediaType.APPLICATION_JSON_TYPE).build(); } finally { if (response != null) { response.close(); } } }
public ApioResult executePutRequest(JsonNode jsonNode) throws ApioException { WebTarget webTarget = _client.target(getEndpointURI()); if (_log.isDebugEnabled()) { _log.debug("Target: {}", getEndpoint()); } Invocation.Builder builder = webTarget.request(APPLICATION_JSON_LD); Entity<String> entity = Entity.json(_jsonNodeToPrettyString(jsonNode)); return _invokeBuilder(HttpMethod.PUT, builder, entity); }
public ApioResult executePostRequest(JsonNode jsonNode) throws ApioException { WebTarget webTarget = _client.target(getEndpointURI()); if (_log.isDebugEnabled()) { _log.debug("Target: {}", getEndpoint()); } Invocation.Builder builder = webTarget.request(APPLICATION_JSON_LD); Entity<String> entity = Entity.json(_jsonNodeToPrettyString(jsonNode)); return _invokeBuilder(HttpMethod.POST, builder, entity); }
@Override public void getLocation(Network network, final LocationProviderCallback callback) { ObjectNode json = objectMapper.valueToTree(network); json.put("token", key); Context.getClient().target(url).request().async().post(Entity.json(json), new InvocationCallback<JsonObject>() { @Override public void completed(JsonObject json) { if (json.getString("status").equals("error")) { callback.onFailure(new GeolocationException(json.getString("message"))); } else { callback.onSuccess( json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } } @Override public void failed(Throwable throwable) { callback.onFailure(throwable); } }); }
@Override public void disconnectFromNetwork(String containerId, String networkId, boolean force) throws DockerException, InterruptedException { final WebTarget resource = resource().path("networks").path(networkId).path("disconnect"); final Map<String, Object> request = new HashMap<>(); request.put("Container", containerId); request.put("Force", force); try { request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(request)); } catch (DockerRequestException e) { switch (e.status()) { case 404: final String message = String.format("Container %s or network %s not found.", containerId, networkId); throw new NotFoundException(message, e); default: throw e; } } }
@Override protected Position handlePosition(Position position) { if (json) { client.target(url).request().async().post(Entity.json(prepareJsonPayload(position))); } else { try { client.target(formatRequest(position)).request().async().get(); } catch (UnsupportedEncodingException | JsonProcessingException e) { LOGGER.warn("Forwarding formatting error", e); } } return position; }
private JsonNode postJsonResponse(final String pathSuffix, final JsonNode schema, final String schemaDescription) throws SchemaNotFoundException { String errorMessage = null; for(final String baseUrl: baseUrls) { final String path = getPath(pathSuffix); final String trimmedBase = getTrimmedBase(baseUrl); final String url = trimmedBase + path; final WebTarget builder = client.target(url); final Response response = builder.request().accept(MediaType.APPLICATION_JSON).header(CONTENT_TYPE_HEADER, SCHEMA_REGISTRY_CONTENT_TYPE).post(Entity.json(schema.toString())); final int responseCode = response.getStatus(); if (responseCode == Response.Status.NOT_FOUND.getStatusCode()) { continue; } if(responseCode == Response.Status.OK.getStatusCode()) { final JsonNode responseJson = response.readEntity(JsonNode.class); return responseJson; } } throw new SchemaNotFoundException("Failed to retrieve Schema with " + schemaDescription + " from any of the Confluent Schema Registry URL's provided; failure response message: " + errorMessage); }
@Override public void run() { final Client resourceClient = ClientBuilder.newClient(); resourceClient.register(new MoxyJsonFeature()); final WebTarget messageStreamResource = resourceClient.target(App.getApiUri()).path("message/stream"); Message message = null; try { while (!cancelled && (message = messages.take()) != null) { msgListener.onMessage(message); final Response r = messageStreamResource.request().put(Entity.json(message)); if (r.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { LOGGER.warning("Unexpected PUT message response status code: " + r.getStatus()); } } if (message == null) { LOGGER.info("Timed out while waiting for a message."); } } catch (InterruptedException ex) { LOGGER.log(Level.WARNING, "Waiting for a message has been interrupted.", ex); } finally { readerHandle.cancel(true); msgListener.onComplete(); } } });
@Override public NetworkCreation createNetwork(NetworkConfig networkConfig) throws DockerException, InterruptedException { final WebTarget resource = resource().path("networks").path("create"); try { return request(POST, NetworkCreation.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(networkConfig)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new NotFoundException("Plugin not found", e); default: throw e; } } }
@Override public void getLocation(Network network, final LocationProviderCallback callback) { AsyncInvoker invoker = Context.getClient().target(url).request().async(); invoker.post(Entity.json(network), new InvocationCallback<JsonObject>() { @Override public void completed(JsonObject json) { if (json.containsKey("error")) { callback.onFailure(new GeolocationException(json.getJsonObject("error").getString("message"))); } else { JsonObject location = json.getJsonObject("location"); callback.onSuccess( location.getJsonNumber("lat").doubleValue(), location.getJsonNumber("lng").doubleValue(), json.getJsonNumber("accuracy").doubleValue()); } } @Override public void failed(Throwable throwable) { callback.onFailure(throwable); } }); }
@Override public void connectToNetwork(String networkId, NetworkConnection networkConnection) throws DockerException, InterruptedException { final WebTarget resource = resource().path("networks").path(networkId).path("connect"); try { request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(networkConnection)); } catch (DockerRequestException e) { switch (e.status()) { case 404: final String message = String.format("Container %s or network %s not found.", networkConnection.containerId(), networkId); throw new NotFoundException(message, e); default: throw e; } } }
@Override public void updateSwarm(final Long version, final boolean rotateWorkerToken, final boolean rotateManagerToken, final boolean rotateManagerUnlockKey, final SwarmSpec spec) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.24"); try { final WebTarget resource = resource().path("swarm").path("update") .queryParam("version", version) .queryParam("rotateWorkerToken", rotateWorkerToken) .queryParam("rotateManagerToken", rotateManagerToken) .queryParam("rotateManagerUnlockKey", rotateManagerUnlockKey); request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(spec)); } catch (DockerRequestException e) { switch (e.status()) { case 400: throw new DockerException("bad parameter", e); default: throw e; } } }
@Override public ContainerUpdate updateContainer(final String containerId, final HostConfig config) throws DockerException, InterruptedException { assertApiVersionIsAbove("1.22"); try { WebTarget resource = resource().path("containers").path(containerId).path("update"); return request(POST, ContainerUpdate.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(config)); } catch (DockerRequestException e) { switch (e.status()) { case 404: throw new ContainerNotFoundException(containerId); default: throw e; } } }
@Override public EurekaHttpResponse<Void> register(InstanceInfo info) { String urlPath = "apps/" + info.getAppName(); Response response = null; try { Builder resourceBuilder = jerseyClient.target(serviceUrl).path(urlPath).request(); addExtraProperties(resourceBuilder); addExtraHeaders(resourceBuilder); response = resourceBuilder .accept(MediaType.APPLICATION_JSON) .acceptEncoding("gzip") .post(Entity.json(info)); return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build(); } finally { if (logger.isDebugEnabled()) { logger.debug("Jersey2 HTTP POST {}/{} with instance {}; statusCode={}", serviceUrl, urlPath, info.getId(), response == null ? "N/A" : response.getStatus()); } if (response != null) { response.close(); } } }