本文整理汇总了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);
}
示例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 "";
}
}