import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import java.io.IOException; import java.io.InputStream; public class Network { static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); public void getRequest(String reqUrl) throws IOException { GenericUrl url = new GenericUrl(reqUrl); HttpRequest request = HTTP_TRANSPORT.createRequestFactory().buildGetRequest(url); HttpResponse response = request.execute(); System.out.println(response.getStatusCode()); InputStream is = response.getContent(); int ch; while ((ch = is.read()) != -1) { System.out.print((char) ch); } response.disconnect(); } }
public static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
/** * @see HttpRequest#getEndpoint() */ public T replaceQueryParam(String name, String... values) { endpoint = uriBuilder(endpoint).replaceQuery(name, values).build(); return self(); }
HttpCommand createHttpCommandForFailureCount(final int failureCount) { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://localhost").build()); while (command.getFailureCount() != failureCount) command.incrementFailureCount(); return command; } }
public T fromHttpRequest(HttpRequest in) { return super.fromHttpMessage(in) .method(in.getMethod()) .endpoint(in.getEndpoint()) .filters(in.getFilters()); } }
public T fromHttpResponse(HttpResponse in) { return super.fromHttpMessage(in) .statusCode(in.getStatusCode()) .message(in.getMessage()); } }
public String apply(HttpResponse from) { releasePayload(from); String eTag = from.getFirstHeaderOrNull(ETAG); if (eTag == null) { // TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed. eTag = from.getFirstHeaderOrNull("Etag"); } if (eTag != null) { return eTag; } throw new HttpException("did not receive ETag"); }
return; } catch (HttpResponseException hre) { HttpResponse hr = hre.getResponse(); if (hr == null) { response.sendError( return; int status = hr.getStatusCode(); switch (status) { case 416:
/** * @see HttpRequest#getEndpoint() */ public T addQueryParams(Multimap<String, String> parameters) { endpoint = uriBuilder(endpoint).addQuery(parameters).build(); return self(); }
URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri);
private static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
/** * @see HttpRequest#getEndpoint() */ public T replaceQueryParam(String name, Iterable<String> values) { endpoint = uriBuilder(endpoint).replaceQuery(name, values).build(); return self(); }
/** * @see HttpRequest#getEndpoint() */ public T addQueryParam(String name, String... values) { endpoint = uriBuilder(endpoint).addQuery(name, values).build(); return self(); }
private static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); // TODO: bogus endpoint return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
/** * @see HttpRequest#getEndpoint() */ public T replaceQueryParams(Multimap<String, String> parameters) { endpoint = uriBuilder(endpoint).replaceQuery(parameters).build(); return self(); }
/** * @see HttpRequest#getEndpoint() */ public T addQueryParam(String name, Iterable<String> values) { endpoint = uriBuilder(endpoint).addQuery(name, values).build(); return self(); }
public static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
private static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); // TODO: bogus endpoint return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
private static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }
public static HttpResponseException returnResponseException(int code) { HttpResponse response = HttpResponse.builder().statusCode(code).build(); return new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub") .build()), response); }