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


Java Client.setFollowRedirects方法代碼示例

本文整理匯總了Java中com.sun.jersey.api.client.Client.setFollowRedirects方法的典型用法代碼示例。如果您正苦於以下問題:Java Client.setFollowRedirects方法的具體用法?Java Client.setFollowRedirects怎麽用?Java Client.setFollowRedirects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.jersey.api.client.Client的用法示例。


在下文中一共展示了Client.setFollowRedirects方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRequestBuilder

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
protected WebResource.Builder getRequestBuilder(String path) {
  assertNotNull("HTTP server must be started first", httpServer);
  ClientConfig config = new DefaultClientConfig();
  config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
  config.getClasses().add(GsonMessageBodyHandler.class);
  Client client = Client.create(config);
  // Disable redirects so we can unit test them.
  client.setFollowRedirects(false);
  return client.resource(makeUrl(path)).getRequestBuilder().accept(MediaType.APPLICATION_JSON);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:11,代碼來源:AbstractJettyTest.java

示例2: getRedirectUrl

import com.sun.jersey.api.client.Client; //導入方法依賴的package包/類
/**
 * Gets the redirect url.
 * 
 * @param path the path
 * @param client the client
 * @param method the method
 * @return the redirect url
 * @throws MotuCasBadRequestException
 */
public static String getRedirectUrl(String path, Client client, RestUtil.HttpMethod method) throws MotuCasBadRequestException {
    WebResource webResource = client.resource(path);
    ClientResponse response = webResource.accept(MediaType.WILDCARD).method(method.toString(), ClientResponse.class);
    Integer responseCode = response.getStatus();
    if (responseCode >= 400) {
        throw MotuCasBadRequestException
                .createMotuCasBadRequestException(response,
                                                  path,
                                                  "Error while trying to retrieve CAS url (RestUtil.getRedirectUrl(String path, Proxy proxy)");
    }

    String location = "";
    if (response.getLocation() != null) {
        location = response.getLocation().toString();
    }
    if (location.contains("login")) {
        // This is a CAS URL
        return RestUtil.extractRedirectUrl(location, responseCode);
    } else if (responseCode >= 300 && responseCode < 400) {
        // Recursive case while a redirection is done not directly to the CAS server
        // There is a redirection, not directly to the CAS, we try to follow it
        client.setFollowRedirects(false);
        return getRedirectUrl(location, client, method);
    } else {
        return "";
    }
}
 
開發者ID:clstoulouse,項目名稱:motu,代碼行數:37,代碼來源:RestUtil.java


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