Java Code Examples for com.google.api.client.http.HttpRequest#getRequestMethod()
The following examples show how to use
com.google.api.client.http.HttpRequest#getRequestMethod() .
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 File: MethodOverride.java From google-api-java-client with Apache License 2.0 | 6 votes |
public void intercept(HttpRequest request) throws IOException { if (overrideThisMethod(request)) { String requestMethod = request.getRequestMethod(); request.setRequestMethod(HttpMethods.POST); request.getHeaders().set(HEADER, requestMethod); if (requestMethod.equals(HttpMethods.GET)) { // take the URI query part and put it into the HTTP body request.setContent(new UrlEncodedContent(request.getUrl().clone())); // remove query parameters from URI request.getUrl().clear(); } else if (request.getContent() == null) { // Google servers will fail to process a POST unless the Content-Length header is specified request.setContent(new EmptyContent()); } } }
Example 2
Source File: GoogleApiClientSigner.java From oauth1-signer-java with MIT License | 5 votes |
public void sign(HttpRequest request) throws IOException { URI uri = request.getUrl().toURI(); String method = request.getRequestMethod(); String payload = null; HttpContent content = request.getContent(); if (null != content && content.getLength() > 0) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); content.writeTo(outputStream); payload = outputStream.toString(charset.name()); } String authorizationHeader = OAuth.getAuthorizationHeader(uri, method, payload, charset, consumerKey, signingKey); request.getHeaders().setAuthorization(authorizationHeader); }
Example 3
Source File: GoogleCloudStorageIntegrationHelper.java From hadoop-connectors with Apache License 2.0 | 5 votes |
/** Convert request to string representation that could be used for assertions in tests */ public static String requestToString(HttpRequest request) { String method = request.getRequestMethod(); String url = request.getUrl().toString(); String requestString = method + ":" + url; if ("POST".equals(method) && url.contains("uploadType=multipart")) { MultipartContent content = (MultipartContent) request.getContent(); JsonHttpContent jsonRequest = (JsonHttpContent) Iterables.get(content.getParts(), 0).getContent(); String objectName = ((StorageObject) jsonRequest.getData()).getName(); requestString += ":" + objectName; } return requestString; }
Example 4
Source File: MethodOverride.java From google-api-java-client with Apache License 2.0 | 5 votes |
private boolean overrideThisMethod(HttpRequest request) throws IOException { String requestMethod = request.getRequestMethod(); if (requestMethod.equals(HttpMethods.POST)) { return false; } if (requestMethod.equals(HttpMethods.GET) ? request.getUrl().build().length() > MAX_URL_LENGTH : overrideAllMethods) { return true; } return !request.getTransport().supportsMethod(requestMethod); }
Example 5
Source File: URLFetchUtils.java From appengine-gcs-client with Apache License 2.0 | 5 votes |
HTTPRequestInfo(HttpRequest req) { method = req.getRequestMethod(); url = req.getUrl().toURL(); long myLength; HttpContent content = req.getContent(); try { myLength = content == null ? -1 : content.getLength(); } catch (IOException e) { myLength = -1; } length = myLength; h1 = req.getHeaders(); h2 = null; }