public String getStoreClientConfigString(List<String> storeNames, String coordinatorUrl) { try { // Create the REST request StringBuilder URIStringBuilder = new StringBuilder().append(coordinatorUrl) .append(URL_SEPARATOR) .append(STORE_CLIENT_CONFIG_OPS) .append(URL_SEPARATOR) .append(Joiner.on(",") .join(storeNames)); RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(URIStringBuilder.toString())); String timeoutStr = Long.toString(this.config.getTimeoutConfig() .getOperationTimeout(VoldemortOpCode.GET_OP_CODE)); requestBuilder.setMethod(requestType.GET.toString()); requestBuilder.setHeader(RestMessageHeaders.X_VOLD_REQUEST_TIMEOUT_MS, timeoutStr); requestBuilder = setCommonRequestHeader(requestBuilder); RestRequest request = requestBuilder.build(); Future<RestResponse> future = client.restRequest(request); // This will block RestResponse response = future.get(); ByteString entity = response.getEntity(); return entity.asString("UTF-8"); } catch(Exception e) { if(e.getCause() instanceof RestException) { return ((RestException) e.getCause()).getResponse().getEntity().asString("UTF-8"); } handleRequestAndResponseException(e); } return null; }
return response.getEntity().asString("UTF-8"); } catch(ExecutionException e) { if(e.getCause() instanceof RestException) {
@Override public void onResponse(RestResponse restResponse, RequestContext requestContext, Map<String, String> wireAttrs) { String header = restResponse.getHeader(_headerName); Assert.assertEquals(header, _expectedValue); if (_entityLength > 0) { Assert.assertEquals(restResponse.getEntity().length(), _entityLength); } }
final ByteString entity = response.getEntity(); if(entity != null) { resultList = parseGetResponse(entity);
final ByteString entity = response.getEntity(); if(entity != null) { resultList = parseGetVersionResponse(entity);
final ByteString entity = response.getEntity();
final ByteString entity = response.getEntity(); if(entity == null) { if(logger.isDebugEnabled()) {
@Override public R2ResponseStatus handleResponse(Request<RestRequest> request, RestResponse response) { R2ResponseStatus status = new R2ResponseStatus(StatusType.OK); int statusCode = response.getStatus(); status.setStatusCode(statusCode); HttpUtils.updateStatusType(status, statusCode, errorCodeWhitelist); if (status.getType() == StatusType.OK) { status.setContent(response.getEntity()); status.setContentType(response.getHeader(CONTENT_TYPE_HEADER)); } else { log.info("Receive an unsuccessful response with status code: " + statusCode); Map<String, String> metadata = Maps.newHashMap(); metadata.put(HttpConstants.STATUS_CODE, String.valueOf(statusCode)); metadata.put(HttpConstants.REQUEST, request.toString()); if (status.getType() != StatusType.CONTINUE) { FailureEventBuilder failureEvent = new FailureEventBuilder(R2_FAILED_REQUEST_EVENT); failureEvent.addAdditionalMetadata(metadata); failureEvent.submit(metricsContext); } else { GobblinTrackingEvent event = new GobblinTrackingEvent(0L, R2_RESPONSE_EVENT_NAMESPACE, R2_FAILED_REQUEST_EVENT, metadata); metricsContext.submitEvent(event); } } return status; } }
final ByteString entity = response.getEntity(); if(entity == null) { if(logger.isDebugEnabled()) {
public RestResponseBuilder(RestResponse response) { super(response); _entity = response.getEntity(); }
/** * Construct a new instance, using the specified response message. * * @param response the {@link RestResponse} message for this exception. */ public RestException(RestResponse response) { // TODO: we should probably should check the content-type / charset and decode appropriately super(response.getEntity().asAvroString()); _response = response; }
static void writeToServletError(HttpServletResponse resp, int statusCode, String message) throws IOException { RestResponse restResponse = RestStatus.responseForStatus(statusCode, message); writeResponseHeadersToServletResponse(TransportResponseImpl.success(Messages.toStreamResponse(restResponse)), resp); final ByteString entity = restResponse.getEntity(); entity.write(resp.getOutputStream()); resp.getOutputStream().close(); }
private void trace(final String method, final RestResponse response, final Map<String, String> wireAttrs, final RequestContext requestContext) { final URI requestUri = (URI)requestContext.getLocalAttr(REQUEST_URI); final String requestMethod = (String)requestContext.getLocalAttr(REQUEST_METHOD); _log.debug(buildLogMessage(method, "response", formatResponse(response, response.getEntity().length(), requestUri, requestMethod), wireAttrs, requestContext)); }
/** * Create a StreamResponse based on the RestResponse * @param restResponse the rest response * @return the StreamResponse that's created based on rest response */ public static StreamResponse toStreamResponse(RestResponse restResponse) { StreamResponseBuilder builder = new StreamResponseBuilder(restResponse); return builder.build(EntityStreams.newEntityStream(new ByteStringWriter(restResponse.getEntity()))); }
public Response<T> decodeResponse(RestResponse restResponse) throws RestLiDecodingException { return createResponse(restResponse.getHeaders(), restResponse.getStatus(), restResponse.getEntity(), restResponse.getCookies()); }
private static IndividualResponse toIndividualResponse(String id, RestResponse restResponse) throws MimeTypeParseException, IOException { IndividualResponse individualResponse = new IndividualResponse(); individualResponse.setStatus(restResponse.getStatus()); individualResponse.setHeaders(new StringMap(restResponse.getHeaders())); ByteString entity = restResponse.getEntity(); if (!entity.isEmpty()) { // TODO Avoid converting bytes to datamap here. Individual response should have only the bytes. individualResponse.setBody(new IndividualBody(DataMapConverter.bytesToDataMap(restResponse.getHeaders(), entity))); } return individualResponse; }