Java Code Examples for org.apache.http.client.methods.HttpPut#METHOD_NAME
The following examples show how to use
org.apache.http.client.methods.HttpPut#METHOD_NAME .
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: HttpRequestFactory.java From caravan with Apache License 2.0 | 5 votes |
private static HttpEntityEnclosingRequestBase createEntityEnclosingRequest(String uri, String method) { switch (method) { case HttpPut.METHOD_NAME: return new HttpPut(uri); default: return new HttpPost(uri); } }
Example 2
Source File: HttpPutWithoutBody.java From vividus with Apache License 2.0 | 4 votes |
@Override public String getMethod() { return HttpPut.METHOD_NAME; }
Example 3
Source File: OriginCheckFilter.java From teammates with GNU General Public License v2.0 | 4 votes |
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; if (Config.isDevServer()) { response.setHeader("Access-Control-Allow-Origin", Config.APP_FRONTENDDEV_URL); response.setHeader("Access-Control-Allow-Methods", ALLOWED_HTTP_METHODS); response.setHeader("Access-Control-Allow-Headers", ALLOWED_HEADERS); response.setHeader("Access-Control-Allow-Credentials", "true"); } if (Config.CSRF_KEY.equals(request.getHeader("CSRF-Key"))) { // Can bypass CSRF check with the correct key chain.doFilter(req, res); return; } String referrer = request.getHeader("referer"); if (referrer == null) { // Requests with missing referrer information are given the benefit of the doubt // to accommodate users who choose to disable the HTTP referrer setting in their browser // for privacy reasons } else if (!isHttpReferrerValid(referrer, request.getRequestURL().toString())) { denyAccess("Invalid HTTP referrer.", request, response); return; } switch (request.getMethod()) { case HttpPost.METHOD_NAME: case HttpPut.METHOD_NAME: case HttpDelete.METHOD_NAME: String message = getCsrfTokenErrorIfAny(request); if (message != null) { denyAccess(message, request, response); return; } break; default: break; } chain.doFilter(req, res); }
Example 4
Source File: BackDoor.java From teammates with GNU General Public License v2.0 | 4 votes |
/** * Executes HTTP request with the given {@code method} and {@code relativeUrl}. * * @return The content of the HTTP response */ private static ResponseBodyAndCode executeRequest( String method, String relativeUrl, Map<String, String[]> params, String body) { String url = TestProperties.TEAMMATES_URL + Const.ResourceURIs.URI_PREFIX + relativeUrl; HttpRequestBase request; switch (method) { case HttpGet.METHOD_NAME: request = createGetRequest(url, params); break; case HttpPost.METHOD_NAME: request = createPostRequest(url, params, body); break; case HttpPut.METHOD_NAME: request = createPutRequest(url, params, body); break; case HttpDelete.METHOD_NAME: request = createDeleteRequest(url, params); break; default: throw new RuntimeException("Unaccepted HTTP method: " + method); } addAuthKeys(request); try (CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = httpClient.execute(request)) { String responseBody = null; HttpEntity entity = response.getEntity(); if (entity != null) { try (BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()))) { responseBody = br.lines().collect(Collectors.joining(System.lineSeparator())); } } return new ResponseBodyAndCode(responseBody, response.getStatusLine().getStatusCode()); } catch (IOException e) { throw new RuntimeException(e); } }