當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestBuilder類代碼示例

本文整理匯總了Java中org.apache.http.client.methods.RequestBuilder的典型用法代碼示例。如果您正苦於以下問題:Java RequestBuilder類的具體用法?Java RequestBuilder怎麽用?Java RequestBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RequestBuilder類屬於org.apache.http.client.methods包,在下文中一共展示了RequestBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: download

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
private static void download(String url, File destination)
        throws IOException {
    HttpUriRequest request = RequestBuilder
            .get()
            .setUri(url)
            .addParameter("hostname",
                    MinecraftServer.getServer().getHostname())
            .addParameter("port",
                    String.valueOf(MinecraftServer.getServer().getPort()))
            .build();
    CloseableHttpClient client = HttpClientBuilder.create()
            .setRedirectStrategy(new LaxRedirectStrategy())
            .setUserAgent("Uranium Updater").build();

    HttpResponse response = client.execute(request);
    if (response.getStatusLine().getStatusCode() != 200) {
        client.close();
        throw new IllegalStateException("Could not download " + url);
    }
    InputStream is = response.getEntity().getContent();
    OutputStream os = new FileOutputStream(destination);
    IOUtils.copy(is, os);
    is.close();
    os.close();
    client.close();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:27,代碼來源:UraniumUpdater.java

示例2: buildtHttpRequest

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
/**
 * Builds a new HTTP POST request with the given URL and request body.
 * Content type of the request is set according to the given headers. If the
 * given headers do not contain Content-Type header, "application/xml" is
 * used.
 *
 * @param url URL where the request is sent
 * @param requestBody request body
 * @param headers HTTP headers to be added to the request
 * @return new HttpUriRequest object
 */
@Override
protected HttpUriRequest buildtHttpRequest(String url, String requestBody, Map<String, String> headers) {
    LOGGER.debug("Build new HTTP POST request.");
    HttpUriRequest request;
    // Create request entity that's used as request body
    StringEntity requestEntity = super.buildRequestEntity(requestBody, headers);
    if (requestEntity != null) {
        request = RequestBuilder.post().setUri(url).setEntity(requestEntity).build();
    } else {
        LOGGER.debug("No request body found for HTTP POST request.");
        request = RequestBuilder.post().setUri(url).build();
    }
    // Return request
    return request;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:27,代碼來源:PostClient.java

示例3: transferCall

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
@Override
public ModifyCallResponse transferCall(String id, String destinationUrl) {

  LOGGER.debug("Transferring call {} to {}",
      id, destinationUrl);

  String authorization = "Authorization";
  String uri = "https://api.nexmo.com/v1/calls/";
  RequestBuilder requestBuilder = jwtAuthMethod.apply(RequestBuilder.put(uri));
  Header header = requestBuilder.getLastHeader(authorization);

  LOGGER.debug("header: {}", header);

  ModifyCallPayload transferPayload = new ModifyCallPayload(TRANSFER, destinationUrl);
  WebTarget target = client.target(uri);
  ModifyCallResponse response = target
      .request(MediaType.APPLICATION_JSON_TYPE)
      .header(authorization, header.getValue())
      .put(
          Entity.entity(transferPayload, MediaType.APPLICATION_JSON_TYPE),
          ModifyCallResponse.class);

  LOGGER.debug("response: {}", response);

  return response;
}
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:27,代碼來源:NexMoServiceImpl.java

示例4: getNextPage

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
public <T> Page<T> getNextPage(Page<T> currentPage) throws IOException {
    Pagination pagination = currentPage.getPagination();
    if (pagination.getNextPage() == null || pagination.getNextPage().isEmpty()) {
        return null;
    }
    RequestBuilder requestBuilder = RequestBuilder.get(pagination.getNextPage());
    requestBuilder = addHeaders(requestBuilder);
    HttpUriRequest httpUriRequest = requestBuilder.build();
    ContentItemsListingResponse response = executeRequest(httpUriRequest, ContentItemsListingResponse.class);
    RichTextElementConverter converter = new RichTextElementConverter(
            getContentLinkUrlResolver(),
            getBrokenLinkUrlResolver(),
            getRichTextElementResolver(),
            templateEngineConfig,
            stronglyTypedContentItemConverter
    );
    converter.process(response.getItems());
    return new Page<>(response, currentPage.getType(), this);
}
 
開發者ID:Kentico,項目名稱:delivery-sdk-java,代碼行數:20,代碼來源:DeliveryClient.java

示例5: addHeaders

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
protected RequestBuilder addHeaders(RequestBuilder requestBuilder) {
    if (deliveryOptions.getProductionApiKey() != null) {
        requestBuilder.setHeader(
                HttpHeaders.AUTHORIZATION, String.format("Bearer %s", deliveryOptions.getProductionApiKey())
        );
    } else if (deliveryOptions.isUsePreviewApi()) {
        requestBuilder.setHeader(
                HttpHeaders.AUTHORIZATION, String.format("Bearer %s", deliveryOptions.getPreviewApiKey())
        );
    }
    if (deliveryOptions.isWaitForLoadingNewContent()) {
        requestBuilder.setHeader(
                "X-KC-Wait-For-Loading-New-Content", "true"
        );
    }
    requestBuilder.setHeader(HttpHeaders.ACCEPT, "application/json");
    requestBuilder.setHeader("X-KC-SDKID", SDK_ID);
    return requestBuilder;
}
 
開發者ID:Kentico,項目名稱:delivery-sdk-java,代碼行數:20,代碼來源:DeliveryClient.java

示例6: buildtHttpRequest

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
/**
 * Builds a new HTTP DELETE request with the given URL and request body.
 * Content type of the request is set according to the given headers. If the
 * given headers do not contain Content-Type header, "application/xml" is
 * used.
 *
 * @param url URL where the request is sent
 * @param requestBody request body
 * @param headers HTTP headers to be added to the request
 * @return new HttpUriRequest object
 */
@Override
protected HttpUriRequest buildtHttpRequest(String url, String requestBody, Map<String, String> headers) {
    LOGGER.debug("Build new HTTP DELETE request.");
    HttpUriRequest request;
    // Create request entity that's used as request body
    StringEntity requestEntity = super.buildRequestEntity(requestBody, headers);
    if (requestEntity != null) {
        request = RequestBuilder.delete().setUri(url).setEntity(requestEntity).build();
    } else {
        LOGGER.debug("No request body found for HTTP DELETE request.");
        request = RequestBuilder.delete().setUri(url).build();
    }
    // Return request
    return request;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:27,代碼來源:DeleteClient.java

示例7: buildtHttpRequest

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
/**
 * Builds a new HTTP PUT request with the given URL and request body.
 * Content type of the request is set according to the given headers. If the
 * given headers do not contain Content-Type header, "application/xml" is
 * used.
 *
 * @param url URL where the request is sent
 * @param requestBody request body
 * @param headers HTTP headers to be added to the request
 * @return new HttpUriRequest object
 */
@Override
protected HttpUriRequest buildtHttpRequest(String url, String requestBody, Map<String, String> headers) {
    LOGGER.debug("Build new HTTP PUT request.");
    HttpUriRequest request;
    // Create request entity that's used as request body
    StringEntity requestEntity = super.buildRequestEntity(requestBody, headers);
    if (requestEntity != null) {
        request = RequestBuilder.put().setUri(url).setEntity(requestEntity).build();
    } else {
        LOGGER.debug("No request body found for HTTP PUT request.");
        request = RequestBuilder.put().setUri(url).build();
    }
    // Return request
    return request;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:27,代碼來源:PutClient.java

示例8: send

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
public RawHttpResponse<CloseableHttpResponse> send(RawHttpRequest request) throws IOException {
    RequestBuilder builder = RequestBuilder.create(request.getMethod());
    builder.setUri(request.getUri());
    builder.setVersion(toProtocolVersion(request.getStartLine().getHttpVersion()));
    request.getHeaders().getHeaderNames().forEach((name) ->
            request.getHeaders().get(name).forEach(value ->
                    builder.addHeader(new BasicHeader(name, value))));

    request.getBody().ifPresent(b -> builder.setEntity(new InputStreamEntity(b.asStream())));

    CloseableHttpResponse response = httpClient.execute(builder.build());

    RawHttpHeaders headers = readHeaders(response);

    @Nullable LazyBodyReader body;
    if (response.getEntity() != null) {
        OptionalLong headerLength = RawHttp.parseContentLength(headers);
        @Nullable Long length = headerLength.isPresent() ? headerLength.getAsLong() : null;
        BodyType bodyType = RawHttp.getBodyType(headers, length);
        body = new LazyBodyReader(bodyType, response.getEntity().getContent(), length, false);
    } else {
        body = null;
    }

    return new RawHttpResponse<>(response, request, adaptStatus(response.getStatusLine()), headers, body);
}
 
開發者ID:renatoathaydes,項目名稱:rawhttp,代碼行數:27,代碼來源:RawHttpComponentsClient.java

示例9: post0

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
private static HttpUriRequest post0(String url, Map<String, Object> params) {
    RequestBuilder requestBuilder = RequestBuilder.post().setCharset(CHARSET).setUri(url);
    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectionRequestTimeout(10000).setSocketTimeout(10000).setConnectTimeout(10000).setCookieSpec("ignoreCookies");
    requestBuilder.setConfig(requestConfigBuilder.build());
    if (params != null && params.size() > 0) {
        List<NameValuePair> nvList = new ArrayList();
        Iterator var6 = params.entrySet().iterator();

        while (var6.hasNext()) {
            Map.Entry<String, Object> param = (Map.Entry) var6.next();
            Object value = param.getValue();
            if (value != null) {
                nvList.add(new BasicNameValuePair((String) param.getKey(), value.toString()));
            }
        }

        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvList, CHARSET);
        requestBuilder.setEntity(formEntity);
    }

    requestBuilder.addHeader("Connection", "Keep-Alive");
    return requestBuilder.build();
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:24,代碼來源:OpenClient.java

示例10: post0

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
private static HttpUriRequest post0(String url, Map<String, String> params) {
    RequestBuilder requestBuilder = RequestBuilder.post().setCharset(CHARSET).setUri(url);
    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
            .setConnectionRequestTimeout(TIMEOUT)
            .setSocketTimeout(TIMEOUT)
            .setConnectTimeout(TIMEOUT).setCookieSpec(CookieSpecs.IGNORE_COOKIES);
    requestBuilder.setConfig(requestConfigBuilder.build());
    if (params != null && params.size() > 0) {
        List<NameValuePair> nvList = new ArrayList<>();
        for (Map.Entry<String, String> param : params.entrySet()) {
            Object value = param.getValue();
            if (value == null) {
                continue;
            }
            nvList.add(new BasicNameValuePair(param.getKey(), value.toString()));
        }
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvList, CHARSET);
        requestBuilder.setEntity(formEntity);
    }
    requestBuilder.addHeader("Connection", "Keep-Alive");
    return requestBuilder.build();

}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:24,代碼來源:IpClient.java

示例11: addFormParams

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) {
     if (request.getEntity() != null && "POST".equalsIgnoreCase(requestBuilder.getMethod())) {
         requestBuilder.setEntity(request.getEntity());
     }else if(request.getParams()!=null){
     	List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
     	for(String key:request.getParams().keySet()){
     		BasicNameValuePair pair=new BasicNameValuePair(key, request.getParams().get(key));
     		nameValuePairs.add(pair);
     	}
     	try {
	requestBuilder.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
	log.error("",e);
}
     }
     return requestBuilder;
 }
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:18,代碼來源:AbsDownloader.java

示例12: httpPost

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
public HttpResponse httpPost(String url, T bodyData) {
    // todo check with regex that is a valid url
    // todo check that the header contain atleast one information or add a content type
    HttpClient httpClient = HttpClients
            .custom()
            .setDefaultHeaders(headers)
            .build();

    HttpEntity bodyEntity = createJsonBody(bodyData);
    HttpUriRequest request = RequestBuilder.post(url).setEntity(bodyEntity).build();

    try {
        return httpClient.execute(request);
    } catch (IOException e) {
        e.printStackTrace();
        LOGGER.log(Level.INFO, "Error from FSFlight Agent during HTTP POST");
    }

    return null;

}
 
開發者ID:flexisaf,項目名稱:paystack,代碼行數:22,代碼來源:FSFlightAgent.java

示例13: send

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
/**
 * Sends an HTTP request to the partner service after checking that the credentials are not expired. It will also
 * handle the response.
 * 
 * @param httpOperation The HTTP operation to execute.
 * @return A deserialized HTTP response.
 */
private TResponse send( RequestBuilder request )
{
    validateCredentials();

    RetryableHttpCall retryableHttpCall = new RetryableHttpCall();
    CloseableHttpClient httpClient = buildHttpClient();
    addHttpHeaders( request );

    CloseableHttpResponse response;
    try
    {
        response = retryableHttpCall.execute( httpClient, request.build() );
    }
    catch ( IOException e )
    {
        throw new PartnerException( e.getMessage(), this.requestContext, PartnerErrorCategory.NOT_SPECIFIED, e );
    }

    return this.handleResponse( response );
}
 
開發者ID:PartnerCenterSamples,項目名稱:Partner-Center-Java-SDK,代碼行數:28,代碼來源:PartnerServiceProxy.java

示例14: getRedirect

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
public HttpUriRequest getRedirect(
        final HttpRequest request,
        final HttpResponse response,
        final HttpContext context) throws ProtocolException {
    final URI uri = getLocationURI(request, response, context);
    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase(HttpHeadHC4.METHOD_NAME)) {
        return new HttpHeadHC4(uri);
    } else if (method.equalsIgnoreCase(HttpGetHC4.METHOD_NAME)) {
        return new HttpGetHC4(uri);
    } else {
        final int status = response.getStatusLine().getStatusCode();
        if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
            return RequestBuilder.copy(request).setUri(uri).build();
        } else {
            return new HttpGetHC4(uri);
        }
    }
}
 
開發者ID:xxonehjh,項目名稱:remote-files-sync,代碼行數:20,代碼來源:DefaultRedirectStrategy.java

示例15: getToken

import org.apache.http.client.methods.RequestBuilder; //導入依賴的package包/類
@Override
public String getToken() throws AuthenticationException {

    final DcosLoginPayload payload       = createDcosLoginPayload();
    final HttpEntity       stringPayload = new StringEntity(payload.toString(), this.contentType);

    // build request
    final HttpUriRequest request = RequestBuilder
            .post()
            .setUri(payload.getLoginURL())
            .setEntity(stringPayload)
            .build();

    try {
        client.build().execute(request, context).close();
    } catch (IOException e) {
        final String errorMessage = "Failed to execute web request to login endpoint.\n" + e.getMessage();
        LOGGER.warning(errorMessage);
        throw new AuthenticationException(errorMessage);
    }

    return getTokenFromCookie(context);
}
 
開發者ID:jenkinsci,項目名稱:marathon-plugin,代碼行數:24,代碼來源:DcosAuthImpl.java


注:本文中的org.apache.http.client.methods.RequestBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。