Java Code Examples for org.apache.http.client.methods.RequestBuilder#get()
The following examples show how to use
org.apache.http.client.methods.RequestBuilder#get() .
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: HTTPMethod.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected RequestBuilder getRequestBuilder() throws HTTPException { if (this.methodurl == null) throw new HTTPException("Null url"); RequestBuilder rb = null; switch (this.methodkind) { case Put: rb = RequestBuilder.put(); break; case Post: rb = RequestBuilder.post(); break; case Head: rb = RequestBuilder.head(); break; case Options: rb = RequestBuilder.options(); break; case Get: default: rb = RequestBuilder.get(); break; } rb.setUri(this.methodurl); return rb; }
Example 2
Source File: HttpDownloadHandler.java From cetty with Apache License 2.0 | 6 votes |
private RequestBuilder getRequestMethod(Seed seed) { String method = seed.getMethod(); if (method == null || method.equalsIgnoreCase(HttpConstants.GET)) { return RequestBuilder.get(); } else if (method.equalsIgnoreCase(HttpConstants.POST)) { return addFormParams(RequestBuilder.post(), seed); } else if (method.equalsIgnoreCase(HttpConstants.HEAD)) { return RequestBuilder.head(); } else if (method.equalsIgnoreCase(HttpConstants.PUT)) { return addFormParams(RequestBuilder.put(), seed); } else if (method.equalsIgnoreCase(HttpConstants.DELETE)) { return RequestBuilder.delete(); } else if (method.equalsIgnoreCase(HttpConstants.TRACE)) { return RequestBuilder.trace(); } throw new IllegalArgumentException("Illegal HTTP Method " + method); }
Example 3
Source File: DefaultZtsClient.java From vespa with Apache License 2.0 | 6 votes |
@Override public AwsTemporaryCredentials getAwsTemporaryCredentials(AthenzDomain athenzDomain, AwsRole awsRole, Duration duration, String externalId) { URI uri = ztsUrl.resolve( String.format("domain/%s/role/%s/creds", athenzDomain.getName(), awsRole.encodedName())); RequestBuilder requestBuilder = RequestBuilder.get(uri); // Add optional durationSeconds and externalId parameters Optional.ofNullable(duration).ifPresent(d -> requestBuilder.addParameter("durationSeconds", Long.toString(duration.getSeconds()))); Optional.ofNullable(externalId).ifPresent(s -> requestBuilder.addParameter("externalId", s)); HttpUriRequest request = requestBuilder.build(); return execute(request, response -> { AwsTemporaryCredentialsResponseEntity entity = readEntity(response, AwsTemporaryCredentialsResponseEntity.class); return entity.credentials(); }); }
Example 4
Source File: JSON.java From validatar with Apache License 2.0 | 6 votes |
/** * Creates a HttpUriRequest based on the metadata configuration. * @param metadata The metadata configuration. * @return A configured request object. */ private HttpUriRequest createRequest(Map<String, String> metadata) { String verb = metadata.getOrDefault(VERB_KEY, DEFAULT_VERB); String url = metadata.get(URL_KEY); if (url == null || url.isEmpty()) { throw new IllegalArgumentException("The " + URL_KEY + " must be provided and contain a valid url."); } RequestBuilder builder; if (GET.equals(verb)) { builder = RequestBuilder.get(url); } else if (POST.equals(verb)) { builder = RequestBuilder.post(url); String body = metadata.getOrDefault(BODY_KEY, EMPTY_BODY); builder.setEntity(new StringEntity(body, Charset.defaultCharset())); } else { throw new UnsupportedOperationException("This HTTP method is not currently supported: " + verb); } // Everything else is assumed to be a header metadata.entrySet().stream().filter(entry -> !KNOWN_KEYS.contains(entry.getKey())) .forEach(entry -> builder.addHeader(entry.getKey(), entry.getValue())); return builder.build(); }
Example 5
Source File: HttpClientDownloader.java From zongtui-webcrawler with GNU General Public License v2.0 | 6 votes |
protected RequestBuilder selectRequestMethod(Request request) { String method = request.getMethod(); if (method == null || method.equalsIgnoreCase(HttpConstant.Method.GET)) { //default get return RequestBuilder.get(); } else if (method.equalsIgnoreCase(HttpConstant.Method.POST)) { RequestBuilder requestBuilder = RequestBuilder.post(); NameValuePair[] nameValuePair = (NameValuePair[]) request.getExtra("nameValuePair"); if (nameValuePair != null && nameValuePair.length > 0) { requestBuilder.addParameters(nameValuePair); } return requestBuilder; } else if (method.equalsIgnoreCase(HttpConstant.Method.HEAD)) { return RequestBuilder.head(); } else if (method.equalsIgnoreCase(HttpConstant.Method.PUT)) { return RequestBuilder.put(); } else if (method.equalsIgnoreCase(HttpConstant.Method.DELETE)) { return RequestBuilder.delete(); } else if (method.equalsIgnoreCase(HttpConstant.Method.TRACE)) { return RequestBuilder.trace(); } throw new IllegalArgumentException("Illegal HTTP Method " + method); }
Example 6
Source File: HttpUriRequestConverter.java From webmagic with Apache License 2.0 | 6 votes |
private RequestBuilder selectRequestMethod(Request request) { String method = request.getMethod(); if (method == null || method.equalsIgnoreCase(HttpConstant.Method.GET)) { //default get return RequestBuilder.get(); } else if (method.equalsIgnoreCase(HttpConstant.Method.POST)) { return addFormParams(RequestBuilder.post(),request); } else if (method.equalsIgnoreCase(HttpConstant.Method.HEAD)) { return RequestBuilder.head(); } else if (method.equalsIgnoreCase(HttpConstant.Method.PUT)) { return addFormParams(RequestBuilder.put(), request); } else if (method.equalsIgnoreCase(HttpConstant.Method.DELETE)) { return RequestBuilder.delete(); } else if (method.equalsIgnoreCase(HttpConstant.Method.TRACE)) { return RequestBuilder.trace(); } throw new IllegalArgumentException("Illegal HTTP Method " + method); }
Example 7
Source File: HTTPUtil.java From OpenAs2App with BSD 2-Clause "Simplified" License | 5 votes |
private static RequestBuilder getRequestBuilder(String method, URL urlObj, NameValuePair[] params, Enumeration<Header> headers) throws URISyntaxException { RequestBuilder req = null; if (method == null || method.equalsIgnoreCase(Method.GET)) { //default get req = RequestBuilder.get(); } else if (method.equalsIgnoreCase(Method.POST)) { req = RequestBuilder.post(); } else if (method.equalsIgnoreCase(Method.HEAD)) { req = RequestBuilder.head(); } else if (method.equalsIgnoreCase(Method.PUT)) { req = RequestBuilder.put(); } else if (method.equalsIgnoreCase(Method.DELETE)) { req = RequestBuilder.delete(); } else if (method.equalsIgnoreCase(Method.TRACE)) { req = RequestBuilder.trace(); } else { throw new IllegalArgumentException("Illegal HTTP Method: " + method); } req.setUri(urlObj.toURI()); if (params != null && params.length > 0) { req.addParameters(params); } if (headers != null) { boolean removeHeaderFolding = "true".equals(Properties.getProperty(HTTP_PROP_REMOVE_HEADER_FOLDING, "true")); while (headers.hasMoreElements()) { Header header = headers.nextElement(); String headerValue = header.getValue(); if (removeHeaderFolding) { headerValue = headerValue.replaceAll("\r\n[ \t]*", " "); } req.setHeader(header.getName(), headerValue); } } return req; }
Example 8
Source File: ApiBase.java From nomad-java-sdk with Mozilla Public License 2.0 | 4 votes |
protected RequestBuilder get(final URIBuilder uri) { return RequestBuilder.get(build(uri)); }
Example 9
Source File: HttpClaimInformationPointProvider.java From keycloak with Apache License 2.0 | 4 votes |
private InputStream executeRequest(HttpFacade httpFacade) { String method = config.get("method").toString(); if (method == null) { method = "GET"; } RequestBuilder builder = null; if ("GET".equalsIgnoreCase(method)) { builder = RequestBuilder.get(); } else { builder = RequestBuilder.post(); } builder.setUri(config.get("url").toString()); byte[] bytes = new byte[0]; try { setParameters(builder, httpFacade); if (config.containsKey("headers")) { setHeaders(builder, httpFacade); } HttpResponse response = httpClient.execute(builder.build()); HttpEntity entity = response.getEntity(); if (entity != null) { bytes = EntityUtils.toByteArray(entity); } StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode < 200 || statusCode >= 300) { throw new HttpResponseException("Unexpected response from server: " + statusCode + " / " + statusLine.getReasonPhrase(), statusCode, statusLine.getReasonPhrase(), bytes); } return new ByteArrayInputStream(bytes); } catch (Exception cause) { try { throw new RuntimeException("Error executing http method [" + builder + "]. Response : " + StreamUtil.readString(new ByteArrayInputStream(bytes), Charset.forName("UTF-8")), cause); } catch (Exception e) { throw new RuntimeException("Error executing http method [" + builder + "]", cause); } } }