Java Code Examples for javax.ws.rs.core.Response#bufferEntity()
The following examples show how to use
javax.ws.rs.core.Response#bufferEntity() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: datacollector File: DatabricksJobExecutor.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void verifyTaskType(Stage.Context context, List<Stage.ConfigIssue> issues, Response listResponse) { listResponse.bufferEntity(); Map<Object, Object> result = listResponse.readEntity(Map.class); Map<String, Object> settings = (Map<String, Object>)result.get("settings"); if ((databricksConfigBean.jobType == JAR && !verifyJarTask(settings)) || (databricksConfigBean.jobType == NOTEBOOK && !verifyNotebookTask(settings))) { JobType expected = databricksConfigBean.jobType; // We know we didn't get the expected type back, so the actual one must be the other type JobType actual = expected == JAR ? NOTEBOOK : JAR; issues.add(context.createConfigIssue( APPLICATION_GROUP, PREFIX + "jobType", DATABRICKS_04, databricksConfigBean.jobId, expected.getLabel(), actual.getLabel())); } }
Example 2
Source Project: jaxrs-beanvalidation-javaee7 File: PersonsIT.java License: Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(20) public void shouldReturnAValidationErrorWhenGettingAPerson(@ArquillianResource URL baseURL) { Client client = ClientBuilder.newBuilder() .register(JacksonJsonProvider.class) .build(); Response response = client.target(baseURL + "r/persons/{id}") .resolveTemplate("id", "test") .request(MediaType.APPLICATION_JSON) .header("Accept-Language", "en") .get(); response.bufferEntity(); logResponse("shouldReturnAValidationErrorWhenGettingAPerson", response); Assert.assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); }
Example 3
Source Project: zheshiyigeniubidexiangmu File: BitmexRestClient.java License: MIT License | 6 votes |
@Override public List<BitmexChartData> getChartData(Ticker ticker, int count, ChartDataBinSize binSize, String endTime, boolean getInprogressBar) { WebTarget target = client.target(apiURL) .path("trade/bucketed") .queryParam("symbol", ticker.getSymbol()) .queryParam("count", count) .queryParam("binSize", binSize.getBin()) .queryParam("endTime", endTime) .queryParam("partial", getInprogressBar) .queryParam("reverse", true); Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON); addHeaders(builder, target.getUri()); Response response = builder.get(); response.bufferEntity(); logger.info("Response: " + response.readEntity(String.class)); BitmexChartData[] data = response.readEntity(BitmexChartData[].class); List<BitmexChartData> returnList = Arrays.asList(data); Collections.reverse(returnList); return returnList; }
Example 4
Source Project: zheshiyigeniubidexiangmu File: BitmexRestClient.java License: MIT License | 6 votes |
@Override public BitmexInstrument getInstrument(Ticker ticker) { WebTarget target = client.target(apiURL) .path("instrument") .queryParam("symbol", ticker.getSymbol()); Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON); addHeaders(builder, target.getUri()); Response response = builder.get(); response.bufferEntity(); logger.info("Response: " + response.readEntity(String.class)); BitmexInstrument[] instruments = response.readEntity(BitmexInstrument[].class); return instruments[0]; }
Example 5
Source Project: zheshiyigeniubidexiangmu File: BitmexRestClient.java License: MIT License | 6 votes |
@Override public List<BitmexChartData> getChartData(Ticker ticker, int count, ChartDataBinSize binSize, String endTime, boolean getInprogressBar) { WebTarget target = client.target(apiURL) .path("trade/bucketed") .queryParam("symbol", ticker.getSymbol()) .queryParam("count", count) .queryParam("binSize", binSize.getBin()) .queryParam("endTime", endTime) .queryParam("partial", getInprogressBar) .queryParam("reverse", true); Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON); addHeaders(builder, target.getUri()); Response response = builder.get(); response.bufferEntity(); logger.info("Response: " + response.readEntity(String.class)); BitmexChartData[] data = response.readEntity(BitmexChartData[].class); List<BitmexChartData> returnList = Arrays.asList(data); Collections.reverse(returnList); return returnList; }
Example 6
Source Project: jaxrs-beanvalidation-javaee7 File: PersonsIT.java License: Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(40) public void shouldReturnAValidationErrorWhenCreatingAPerson(@ArquillianResource URL baseURL) { Form form = new Form(); Client client = ClientBuilder.newBuilder() .register(JacksonJsonProvider.class) .build(); Response response = client.target(baseURL + "r/persons/create") .request(MediaType.APPLICATION_JSON) .header("Accept-Language", "pt") .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED)); response.bufferEntity(); logResponse("shouldReturnAValidationErrorWhenCreatingAPerson", response); Assert.assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus()); }
Example 7
Source Project: jaxrs-beanvalidation-javaee7 File: PersonsIT.java License: Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(10) public void shouldReturnAllPersons(@ArquillianResource URL baseURL) { Client client = ClientBuilder.newBuilder() .register(JsonProcessingFeature.class) .property(JsonGenerator.PRETTY_PRINTING, true) .build(); Response response = client.target(baseURL + "r/persons") .request(MediaType.APPLICATION_JSON) .get(); response.bufferEntity(); logResponse("shouldReturnAllPersons", response, JsonArray.class); Assert.assertEquals(Collections.emptyList(), response.readEntity(new GenericType<Collection<Person>>() {})); }
Example 8
Source Project: geowave File: GeoServerRestClient.java License: Apache License 2.0 | 6 votes |
/** * Get coverage store from geoserver */ public Response getCoverageStore( final String workspaceName, final String coverageName, final boolean quietOnNotFound) { final Response resp = getWebTarget().path( "rest/workspaces/" + workspaceName + "/coveragestores/" + coverageName + ".json").queryParam("quietOnNotFound", quietOnNotFound).request().get(); if (resp.getStatus() == Status.OK.getStatusCode()) { resp.bufferEntity(); final JSONObject cvgstore = JSONObject.fromObject(resp.readEntity(String.class)); if (cvgstore != null) { return Response.ok(cvgstore.toString(defaultIndentation)).build(); } } return resp; }
Example 9
Source Project: dremio-oss File: TestMasterDown.java License: Apache License 2.0 | 6 votes |
private void checkNodeStatus(long giveUpAfterMs, WebTarget webTarget, Response.Status expectedStatus, ServerStatus expectedServerStatus) throws Exception { final long sleepBetweenRetries = 10; // ms long sleptSoFar = 0; ServerStatus serverStatus = ServerStatus.OK; int responseStatusCode = -1; while (sleptSoFar < giveUpAfterMs) { Response response = webTarget.path("/server_status").request(JSON).buildGet().invoke(); response.bufferEntity(); responseStatusCode = response.getStatusInfo().getStatusCode(); if (responseStatusCode == expectedStatus.getStatusCode()) { serverStatus = response.readEntity(ServerStatus.class); if (serverStatus.equals(expectedServerStatus)) { return; } } Thread.sleep(sleepBetweenRetries); sleptSoFar += sleepBetweenRetries; } assertEquals(responseStatusCode, expectedStatus.getStatusCode()); assertEquals(serverStatus, expectedServerStatus); }
Example 10
Source Project: SCIM-Client File: AbstractScimClient.java License: Apache License 2.0 | 6 votes |
private Response invokeServiceMethod(Method method, Object[] args) throws ReflectiveOperationException { logger.trace("Sending service request for method {}", method.getName()); Response response = (Response) method.invoke(scimService, args); boolean buffered = false; try { //This try block helps prevent a RestEasy NPE that arises when the response is empty (has no content) buffered = response.bufferEntity(); } catch (Exception e) { logger.trace(e.getMessage(), e); } logger.trace("Received response entity was{} buffered", buffered ? "" : " not"); logger.trace("Response status code was {}", response.getStatus()); return response; }
Example 11
Source Project: jaxrs-beanvalidation-javaee7 File: PersonsIT.java License: Apache License 2.0 | 6 votes |
@Test @RunAsClient @InSequence(30) public void shouldReturnAnEmptyPerson(@ArquillianResource URL baseURL) { Client client = ClientBuilder.newBuilder() .register(JacksonJsonProvider.class) .build(); Response response = client.target(baseURL + "r/persons/{id}") .resolveTemplate("id", "10") .request(MediaType.APPLICATION_JSON) .get(); response.bufferEntity(); logResponse("shouldReturnAnEmptyPerson", response); Assert.assertEquals(null, response.readEntity(Person.class)); }
Example 12
Source Project: cxf File: ClientProxyImpl.java License: Apache License 2.0 | 5 votes |
protected Object handleResponse(Message outMessage, Class<?> serviceCls) throws Throwable { try { Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build(); ((ResponseImpl)r).setOutMessage(outMessage); getState().setResponse(r); Method method = outMessage.getExchange().get(Method.class); checkResponse(method, r, outMessage); if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE) { return null; } if (method.getReturnType() == Response.class && (r.getEntity() == null || InputStream.class.isAssignableFrom(r.getEntity().getClass()) && ((InputStream)r.getEntity()).available() == 0)) { return r; } if (PropertyUtils.isTrue(super.getConfiguration().getResponseContext().get(BUFFER_PROXY_RESPONSE))) { r.bufferEntity(); } Class<?> returnType = getReturnType(method, outMessage); Type genericType = getGenericReturnType(serviceCls, method, returnType); returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType); return readBody(r, outMessage, returnType, genericType, method.getDeclaredAnnotations()); } finally { ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies(); } }
Example 13
Source Project: geowave File: GeoServerRestClient.java License: Apache License 2.0 | 5 votes |
/** * Get coverage from geoserver */ public Response getCoverage( final String workspaceName, final String cvgStoreName, final String coverageName, final boolean quietOnNotFound) { final Response resp = getWebTarget().path( "rest/workspaces/" + workspaceName + "/coveragestores/" + cvgStoreName + "/coverages/" + coverageName + ".json").queryParam("quietOnNotFound", quietOnNotFound).request().get(); if (resp.getStatus() == Status.OK.getStatusCode()) { resp.bufferEntity(); final JSONObject cvg = JSONObject.fromObject(resp.readEntity(String.class)); if (cvg != null) { return Response.ok(cvg.toString(defaultIndentation)).build(); } } return resp; }
Example 14
Source Project: shopify-sdk File: ShopifyErrorResponseException.java License: Apache License 2.0 | 5 votes |
public ShopifyErrorResponseException(final Response response) { super(buildMessage(response)); response.bufferEntity(); this.responseBody = response.readEntity(String.class); this.shopifyErrorCodes = ShopifyErrorCodeFactory.create(responseBody); this.statusCode = response.getStatus(); }
Example 15
Source Project: TeaStore File: TrainingSynchronizer.java License: Apache License 2.0 | 5 votes |
private void filterLists(List<OrderItem> orderItems, List<Order> orders) { // since we are not registered ourselves, we can multicast to all services List<Response> maxTimeResponses = ServiceLoadBalancer.multicastRESTOperation(Service.RECOMMENDER, "train/timestamp", Response.class, client -> client.getService().path(client.getApplicationURI()).path(client.getEndpointURI()) .request(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN).get()); for (Response response : maxTimeResponses) { if (response == null) { LOG.warn("One service response was null and is therefore not available for time-check."); } else if (response.getStatus() == Response.Status.OK.getStatusCode()) { // only consider if status was fine long milliTS = response.readEntity(Long.class); if (maxTime != TrainingSynchronizer.DEFAULT_MAX_TIME_VALUE && maxTime != milliTS) { LOG.warn("Services disagree about timestamp: " + maxTime + " vs " + milliTS + ". Therfore using the minimum."); } maxTime = Math.min(maxTime, milliTS); } else { // release connection by buffering entity response.bufferEntity(); LOG.warn("Service " + response + "was not available for time-check."); } } if (maxTime == Long.MIN_VALUE) { // we are the only known service // therefore we find max and set it for (Order or : orders) { maxTime = Math.max(maxTime, toMillis(or.getTime())); } } filterForMaxtimeStamp(orderItems, orders); }
Example 16
Source Project: TeaStore File: LoadBalancedImageOperations.java License: Apache License 2.0 | 5 votes |
/** * Gets preview images for a series of products with target image size. * * @param products * list of products * @param size * target size * @throws NotFoundException * If 404 was returned. * @throws LoadBalancerTimeoutException * On receiving the 408 status code and on repeated load balancer * socket timeouts. * @return HashMap containing all preview images */ public static HashMap<Long, String> getProductImages(List<Product> products, ImageSize size) throws NotFoundException, LoadBalancerTimeoutException { HashMap<Long, String> img = new HashMap<>(); for (Product p : products) { img.put(p.getId(), size.toString()); } Response r = ServiceLoadBalancer.loadBalanceRESTOperation(Service.IMAGE, "image", HashMap.class, client -> ResponseWrapper.wrap(HttpWrapper.wrap(client.getEndpointTarget().path("getProductImages")) .post(Entity.entity(img, MediaType.APPLICATION_JSON)))); if (r == null) { return new HashMap<Long, String>(); } HashMap<Long, String> result = null; if (r.getStatus() < 400) { result = r.readEntity(new GenericType<HashMap<Long, String>>() { }); } else { // buffer all entities so that the connections are released to the connection // pool r.bufferEntity(); } if (result == null) { return new HashMap<Long, String>(); } return result; }
Example 17
Source Project: brooklyn-server File: CatalogResourceTest.java License: Apache License 2.0 | 5 votes |
@Test public void testGetCatalogEntityIconDetails() throws IOException { String catalogItemId = "testGetCatalogEntityIconDetails"; addTestCatalogItemAsEntity(catalogItemId); Response response = client().path(URI.create("/catalog/icon/" + catalogItemId + "/" + TEST_VERSION)) .get(); response.bufferEntity(); Assert.assertEquals(response.getStatus(), 200); Assert.assertEquals(response.getMediaType(), MediaType.valueOf("image/png")); Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.readEntity(InputStream.class))); Assert.assertNotNull(image); }
Example 18
Source Project: geowave File: GeoServerRestClient.java License: Apache License 2.0 | 5 votes |
/** * Get a list of coverages (raster layers) from geoserver */ public Response getCoverages(final String workspaceName, final String cvsstoreName) { final Response resp = getWebTarget().path( "rest/workspaces/" + workspaceName + "/coveragestores/" + cvsstoreName + "/coverages.json").request().get(); if (resp.getStatus() == Status.OK.getStatusCode()) { resp.bufferEntity(); // get the datastore names final JSONArray coveragesArray = getArrayEntryNames( JSONObject.fromObject(resp.readEntity(String.class)), "coverages", "coverage"); final JSONObject dsObj = new JSONObject(); dsObj.put("coverages", coveragesArray); return Response.ok(dsObj.toString(defaultIndentation)).build(); } return resp; }
Example 19
Source Project: geowave File: StoreServiceClient.java License: Apache License 2.0 | 4 votes |
public Response listPlugins() { final Response resp = storeService.listPlugins(); resp.bufferEntity(); return resp; }
Example 20
Source Project: geowave File: IndexServiceClient.java License: Apache License 2.0 | 4 votes |
public Response listPlugins() { final Response resp = indexService.listPlugins(); resp.bufferEntity(); return resp; }