Refine search
Invocation.Builder builder = resourceTarget.request(mediaType); builder.headers(newHeaders); builder.property(REQUEST_PROPERTY_FILTER_REUSED, "true"); invocation = builder.build(method); } else { invocation = builder.build(method, Entity.entity(request.getEntity(), request.getMediaType())); Response nextResponse = invocation.invoke(); if (nextResponse.hasEntity()) { response.setEntityStream(nextResponse.readEntity(InputStream.class)); headers.putAll(nextResponse.getStringHeaders()); response.setStatus(nextResponse.getStatus());
@Override @Test public void testCreateStream() { String streamResourceURI = getURI() + "v1/scopes/" + scope1 + "/streams"; Response response = addAuthHeaders(client.target(streamResourceURI).request()).buildPost(Entity.json(createStreamRequest)).invoke(); assertEquals("Create Stream Status", expectedResult, response.getStatus()); response.close(); }
public Result getResult(WebTarget target) { try { return new CountResult(parse(target.path(Joiner.on(",").join(indexes)).path(Joiner.on(",").join(types)).path("_count").request().header(CONTENT_TYPE, APPLICATION_JSON).buildGet().invoke(String.class)).get("count").getAsLong()); } catch (WebApplicationException e) { return new FailureResult(e.getResponse().getStatus(), e.getMessage()); } } }
@Override public Response dispatch(URI targetUri) { // Other methods? String method = "GET"; WebTarget target = ClientBuilder.newClient().target(targetUri); Invocation invocation = target.request().build(method); Response r = invocation.invoke(); ResponseBuilder b = Response.status(r.getStatus()); b.type(r.getMediaType()); b.entity(r.readEntity(InputStream.class)); b.header(HttpHeaders.CONTENT_DISPOSITION, r.getHeaderString(HttpHeaders.CONTENT_DISPOSITION)); // Other headers? return b.build(); }
@Override protected void run(Environment environment, Namespace namespace, T configuration) throws Exception { try { JerseyClientConfiguration jerseyConfig = ((KeystoreConfiguration) configuration) .getJerseyClientConfiguration(); final Client client = new JerseyClientBuilder(environment) .using(jerseyConfig) .build("TLS-truststore-test"); WebTarget target = client.target(namespace.getString("url")); Response response = target.request().buildGet().invoke(); LOGGER.info(String.valueOf(response)); assert response.getStatus() == 200; } catch (Exception e) { LOGGER.error(String.valueOf(e)); throw e; } }
private Response getWithRedirect(Client client, Invocation req) { while (true) { Response res = req.invoke(); String location = res.getHeaderString("Location"); if (res.getStatus() / 100 != 3 || location == null) { return res; } res.readEntity(String.class); if (!location.startsWith("http")) { location = endpoint + location; } req = client.target(fromUri(location)) .request() .buildGet(); } }
public RpcClientResult put(String path, String content) { if (null == serverUri) { throw new RuntimeException("service url is null"); } WebTarget target = client.target(serverUri).path(path); return target.request().buildPut(Entity.entity(content, MediaType.APPLICATION_JSON)).invoke(RpcClientResult.class); }
public void archive(final DocBlob docBlob, final String externalUrl) { ensureInitialized(); ArchiveArgs archiveArgs = new ArchiveArgs(); archiveArgs.setDocBookmark(new StringValue(docBlob.getDocBookmark())); archiveArgs.setExternalUrl(new StringValue(externalUrl)); Client client = null; try { client = clientBuilder.build(); final WebTarget webTarget = client.target(archiveUri); final Invocation.Builder invocationBuilder = webTarget.request(); invocationBuilder.header("Authorization", "Basic " + encode(username, password)); final String json = archiveArgs.asJson(); final Invocation invocation = invocationBuilder.buildPut( Entity.entity(json, MediaType.APPLICATION_JSON_TYPE)); final Response response = invocation.invoke(); final int responseStatus = response.getStatus(); if (responseStatus != 200) { LOG.warn("uri: " + archiveUri + "; " + archiveArgs.toString()); return; } } catch(Exception ex) { LOG.error(archiveArgs.toString(), ex); } finally { closeQuietly(client); } }
response = invocation.invoke(); } catch (final Exception e) { getLogger().error("Failed to make request to Yandex to transate text for {} due to {}; routing to comms.failure", new Object[]{flowFile, e}); if (response.getStatus() != Response.Status.OK.getStatusCode()) { getLogger().error("Failed to translate text using Yandex for {}; response was {}: {}; routing to {}", new Object[]{ flowFile, response.getStatus(), response.getStatusInfo().getReasonPhrase(), REL_TRANSLATION_FAILED.getName()}); flowFile = session.putAttribute(flowFile, "yandex.translate.failure.reason", response.getStatusInfo().getReasonPhrase()); session.transfer(flowFile, REL_TRANSLATION_FAILED);
@Override @Test public void testGetScalingEvents() throws Exception { String resourceURI = getURI() + "v1/scopes/scope1/streams/stream1/scaling-events"; Response response = addAuthHeaders(client.target(resourceURI).queryParam("from", new Date()). queryParam("to", new Date()).request()).buildGet().invoke(); assertEquals("Get Scaling Events response code", 404, response.getStatus()); }
target = target.queryParam("delimiterChar", delimiterChar); target = target.queryParam("quoteChar", quoteChar); Invocation invocation = target.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).buildPost(Entity.text(is)); Response response = invocation.invoke(); Response.StatusType status = response.getStatusInfo(); switch(status.getFamily()){ case CLIENT_ERROR: case SERVER_ERROR: return response.readEntity(SimpleResponse.class); default: break; try(InputStream result = response.readEntity(InputStream.class)){ byte[] buffer = new byte[10 * 1024];
@Override public ModelResponse perform(WebTarget target) throws IOException { try(PushbackInputStream is = new PushbackInputStream(new FileInputStream(getFile()), 16)){ String encoding = getContentEncoding(is); Variant variant = new Variant(MediaType.APPLICATION_XML_TYPE, (Locale)null, encoding); Invocation invocation = target.request(MediaType.APPLICATION_JSON).buildPut(Entity.entity(is, variant)); Response response = invocation.invoke(); return response.readEntity(ModelResponse.class); } } };
private Response request(String url, String method, Object body) throws URISyntaxException { URI uri = new URI(url); Invocation.Builder builder = client.target(url).request(); StringBuilder str = new StringBuilder(); str.append("url: ").append(url).append("\n").append("method: ").append(method); JaxRSClientContext context = getContext(); Subjoin subjoin = context.getSubjoin(); String tokenId = ClientTokenManagement.getTokenId(getDestination(), context.getTokenId()); // getDestination().isTokenTransfer() ? // context.getTokenId() : // ClientTokenManagement.getTokenId(getDestination()); builder = buildHeaders(builder, str, subjoin, tokenId); if (body != null && log.isDebugEnabled()) { str.append("\ncontent:\n").append(getJSONSerializer().toJson(body)); } log.debug("requestInfo: \n{}", str.toString()); return body == null ? builder.build(method).invoke() : builder.build(method, Entity.entity(body, MediaType.APPLICATION_JSON_TYPE.withCharset(getEncodingCharset()))).invoke(); }
@Test public void testDownloadCsvRest() throws Exception { final String downloadPath = new DatasetVersionResourcePath(new DatasetPath("DG.dsg1"), dsg1.getVersion()).toString(); InitialDownloadResponse initialDownloadResponse = expectSuccess( getBuilder(getAPIv2().path(downloadPath).path("download").queryParam("downloadFormat", DownloadFormat.CSV)).buildGet(), InitialDownloadResponse.class); // wait for job final Job job = l(JobsService.class).getJob(initialDownloadResponse.getJobId()); job.getData().loadIfNecessary(); // get job data Response response = getBuilder(getAPIv2().path(initialDownloadResponse.getDownloadUrl())).buildGet().invoke(); validateAllRows(readDataCsv((InputStream)response.getEntity())); }
/** * @param channelUri * @param resourceBuilder * @param notification * @param retriesLeft to push the notification if the token expires * @return WnsNotificationResponse please see response headers from <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response">http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response</a> * @throws WnsException when authentication fails */ public WnsNotificationResponse push(WnsResourceBuilder resourceBuilder, String channelUri, WnsAbstractNotification notification, int retriesLeft, WnsNotificationRequestOptional optional) throws WnsException { WebTarget target = client.target(channelUri); Invocation.Builder webResourceBuilder = resourceBuilder.build(target, notification, getToken().access_token, optional); String type = notification.getType().equals(WnsNotificationType.RAW) ? MediaType.APPLICATION_OCTET_STREAM : MediaType.TEXT_XML; Response response = webResourceBuilder.buildPost(Entity.entity(resourceBuilder.getEntityToSendWithNotification(notification), type)).invoke(); WnsNotificationResponse notificationResponse = new WnsNotificationResponse(channelUri, response.getStatus(), response.getStringHeaders()); if (notificationResponse.code == 200) { return notificationResponse; } if (notificationResponse.code == 401 && retriesLeft > 0) { retriesLeft--; // Access token may have expired refreshAccessToken(); // Retry return this.push(resourceBuilder, channelUri, notification, retriesLeft, optional); } // Assuming push failed return notificationResponse; }
@Override public EvaluationResponse perform(WebTarget target) throws Exception { EvaluationRequest request = new EvaluationRequest() .setArguments(getArguments()); Invocation invocation = target.request(MediaType.APPLICATION_JSON).buildPost(Entity.json(request)); Response response = invocation.invoke(); return response.readEntity(EvaluationResponse.class); } };
@Override public SimpleResponse perform(WebTarget target){ Invocation invocation = target.request(MediaType.APPLICATION_JSON).buildDelete(); Response response = invocation.invoke(); return response.readEntity(SimpleResponse.class); } };
@Test public void testNonExistentJaxrs20WithPost() throws Exception { Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://168.168.168.168/"); Invocation.Builder builder = target.request(); Entity<String> entity = Entity.entity("entity", MediaType.WILDCARD_TYPE); Invocation invocation = builder.buildPost(entity); Future<String> future = invocation.submit( new GenericType<String>() { } ); try { future.get(); } catch (Exception ex) { Throwable cause = ex.getCause(); assertTrue(cause instanceof ProcessingException); } }