private static String createDefaultName(WebTarget target) { return String.format("jersey-sse-event-source-[%s]", target.getUri().toASCIIString().replace("%", "%%")); }
private Map<String, String> getQueryParamMap(final WebTarget resource) { final String queryParams = resource.getUri().getQuery(); final Map<String, String> paramsMap = Maps.newHashMap(); if (queryParams != null) { for (final String queryParam : queryParams.split("&")) { final String[] kv = queryParam.split("="); paramsMap.put(kv[0], kv[1]); } } return paramsMap; }
@Override public Void call() throws DockerException, InterruptedException, IOException { stream.tail(handler, method, resource.getUri()); return null; } }
private void init() { final ApacheConnectorProvider apacheConnectorProvider = new ApacheConnectorProvider(); final ClientConfig clientConfig = new ClientConfig().connectorProvider(apacheConnectorProvider); // transfer encoding should be set as jersey sets it on by default. clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, enableChunkedEncoding ? RequestEntityProcessing.CHUNKED : RequestEntityProcessing.BUFFERED); client = ClientBuilder.newClient(clientConfig); target = client.target(urlString).path(PUT_PATH); if(sync) { // need to add an empty string else it is nto added as query param. target = target.queryParam("sync", "").queryParam("sync_timeout", syncTimeout); } if(responseType != ResponseType.None) { // need to add an empty string else it is nto added as query param. target = target.queryParam(responseType.value, ""); } LOG.info("target uri [{}]", target.getUri()); }
throw new DockerRequestException(method, resource.getUri(), response.getStatus(), message(response), cause); } else if ((cause instanceof SocketTimeoutException) || (cause instanceof ConnectTimeoutException)) { throw new DockerTimeoutException(method, resource.getUri(), ex); } else if ((cause instanceof InterruptedIOException) || (cause instanceof InterruptedException)) {
if (!executor.awaitTermination(timeout, unit)) { LOGGER.log(CONNECTION_ERROR_LEVEL, LocalizationMessages.EVENT_SOURCE_SHUTDOWN_TIMEOUT(target.getUri().toString())); return false; LocalizationMessages.EVENT_SOURCE_SHUTDOWN_INTERRUPTED(target.getUri().toString())); Thread.currentThread().interrupt(); return false;
private void requestAndTail(final String method, final ProgressHandler handler, final WebTarget resource, final Invocation.Builder request) throws DockerException, InterruptedException { Response response = request(method, Response.class, resource, request); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new DockerRequestException(method, resource.getUri(), response.getStatus(), message(response), null); } tailResponse(method, response, handler, resource); }
@Override public Set<String> load(final InputStream imagePayload, final ProgressHandler handler) throws DockerException, InterruptedException { final WebTarget resource = resource() .path("images") .path("load") .queryParam("quiet", "false"); final LoadProgressHandler loadProgressHandler = new LoadProgressHandler(handler); final Entity<InputStream> entity = Entity.entity(imagePayload, APPLICATION_OCTET_STREAM); try (final ProgressStream load = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE), entity)) { load.tail(loadProgressHandler, POST, resource.getUri()); return loadProgressHandler.getImageNames(); } catch (IOException e) { throw new DockerException(e); } finally { IOUtils.closeQuietly(imagePayload); } }
@Override public EventStream events(EventsParam... params) throws DockerException, InterruptedException { WebTarget resource = noTimeoutResource().path("events"); resource = addParameters(resource, params); try { final CloseableHttpClient client = (CloseableHttpClient) ApacheConnectorProvider .getHttpClient(noTimeoutClient); final CloseableHttpResponse response = client.execute(new HttpGet(resource.getUri())); return new EventStream(response, objectMapper()); } catch (IOException exception) { throw new DockerException(exception); } }
if (LOGGER.isLoggable(CONNECTION_ERROR_LEVEL)) { LOGGER.log(CONNECTION_ERROR_LEVEL, String.format("Unable to connect - closing the event source to %s.", target.getUri().toASCIIString()), ex);
this.sseEventSourceScheduler = new SseEventSourceScheduler(scheduledExecutor, name); } else { this.sseEventSourceScheduler = new SseEventSourceScheduler(scheduledExecutor, String.format("sse-event-source(%s)", target.getUri())); this.sseEventSourceScheduler = new SseEventSourceScheduler(executor, name); } else { this.sseEventSourceScheduler = new SseEventSourceScheduler(executor, String.format("sse-event-source(%s)", target.getUri()));
WebTarget target = client.target("http://www.someurl.com"); WebTarget newTarget = target.queryParam("id", "1"); newTarget.request().post(); System.out.println(newTarget.getUri());
protected ClientInvocation createRequest(Object[] args) { WebTarget target = this.webTarget; for (int i = 0; i < processors.length; i++) { if (processors != null && processors[i] instanceof WebTargetProcessor) { WebTargetProcessor processor = (WebTargetProcessor)processors[i]; target = processor.build(target, args[i]); } } ClientConfiguration parentConfiguration=(ClientConfiguration) target.getConfiguration(); ClientInvocation clientInvocation = new ClientInvocation(this.webTarget.getResteasyClient(), target.getUri(), new ClientRequestHeaders(parentConfiguration), parentConfiguration); clientInvocation.setClientInvoker(this); if (accepts != null) { clientInvocation.getHeaders().accept(accepts); } for (int i = 0; i < processors.length; i++) { if (processors != null && processors[i] instanceof InvocationProcessor) { InvocationProcessor processor = (InvocationProcessor)processors[i]; processor.process(clientInvocation, args[i]); } } clientInvocation.setMethod(httpMethod); return clientInvocation; }
@Override public String discoverServiceURI(String name) { final String endpoint = Optional.ofNullable(services.get(name).getServiceRoot()) .orElseThrow(RuntimeException::new) .getUri() .toString(); LOGGER.config(() -> "Returning service endpoint for '" + name + "': " + endpoint); return endpoint; }
@Override public void failed(Throwable throwable) { log.warn("[{}] Failed to perform http put request: {}", target.getUri(), throwable.getMessage()); future.completeExceptionally(getApiException(throwable.getCause())); }
public List<GluuGroup> searchGroups(String pattern, int size) { WebTarget resource = webTarget.path("search").queryParam("pattern", pattern).queryParam("size", size); logger.debug("Final Url:" + resource.getUri().toString()); GenericType<List<GluuGroup>> responseType = new GenericType<List<GluuGroup>>() { }; return resource.request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get(responseType); }
UserException.Builder addContext(UserException.Builder builder){ if(target != null){ builder.addContext("Request: " + target.getUri()); } for(ContextInfo i : contexts){ builder.addContext(i.name, String.format(i.message, i.values)); } return builder; }
void delete(MCRWork work) throws IOException, JDOMException, SAXException { WebTarget target = orcid.getWebTarget().path("work").path(work.getPutCode()); Builder builder = buildInvocation(target); LOGGER.info("delete {} from {}", work.getObjectID(), target.getUri()); Response response = builder.delete(); expect(response, Response.Status.NO_CONTENT); orcid.getWorksSection().removeWork(work); }
@Test public void testUpdateNotExistingCaseComment() { String caseId = startUserTaskCase(USER_YODA, USER_JOHN); Entity<String> newComment = Entity.entity("", getMediaType()); Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(RestURI.CONTAINER_ID, CONTAINER_ID); valuesMap.put(RestURI.CASE_ID, caseId); valuesMap.put(RestURI.CASE_COMMENT_ID, "not-existing-id"); WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), RestURI.CASE_URI + "/" + RestURI.CASE_COMMENTS_PUT_URI, valuesMap)); logger.debug("Update case: [PUT] " + clientRequest.getUri()); response = clientRequest.request(getMediaType()).put(newComment); Assert.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); }
@Before public void setup() throws Exception { client.start(); URI socketUri = new URI(getAPIv2().path("socket").getUri().toString().replace("http://", "ws://")); ClientUpgradeRequest request = new ClientUpgradeRequest(); request.setSubProtocols(Lists.newArrayList(getAuthHeaderValue())); this.socket = new TestSocket(); client.connect(socket, socketUri, request); socket.awaitConnection(2); assertEquals(getAuthHeaderValue(), socket.session.getUpgradeResponse().getAcceptedSubProtocol()); }