本文整理匯總了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 "";
}
}