当前位置: 首页>>代码示例>>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;未经允许,请勿转载。