本文整理汇总了Java中org.apache.commons.httpclient.methods.GetMethod.setFollowRedirects方法的典型用法代码示例。如果您正苦于以下问题:Java GetMethod.setFollowRedirects方法的具体用法?Java GetMethod.setFollowRedirects怎么用?Java GetMethod.setFollowRedirects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.GetMethod
的用法示例。
在下文中一共展示了GetMethod.setFollowRedirects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkOfflineServers
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
* Checks if the offline servers has come back online
* again.
*/
private synchronized void checkOfflineServers() {
Iterator itr = offline.listIterator();
while (itr.hasNext()) {
Server server = (Server) itr.next();
String url = getServerURL(server);
GetMethod get = new GetMethod(url);
get.setFollowRedirects(false);
try {
httpClient.executeMethod(get);
if (okServerResponse(get.getStatusCode())) {
online.add(server);
itr.remove();
log.debug("Server back online " + getServerURL(server));
listener.serverOnline(server);
}
} catch (Exception e) {
listener.serverOffline(server);
} finally {
get.releaseConnection();
}
}
}
示例2: testBasicRedirect303
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect303() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(
new BasicRedirectService(host, port, HttpStatus.SC_SEE_OTHER));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("/newlocation/", httpget.getPath());
assertEquals(host, httpget.getURI().getHost());
assertEquals(port, httpget.getURI().getPort());
assertEquals(new URI("http://" + host + ":" + port + "/newlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例3: testRedirectToResourceAfterLogout
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
* Test SLING-1847
* @throws Exception
*/
@Test
public void testRedirectToResourceAfterLogout() throws Exception {
//login
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("j_username", "admin"));
params.add(new NameValuePair("j_password", "admin"));
H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_MOVED_TEMPORARILY, params, null);
//...and then...logout with a resource redirect
String locationAfterLogout = HttpTest.SERVLET_CONTEXT + "/system/sling/info.sessionInfo.json";
final GetMethod get = new GetMethod(HttpTest.HTTP_BASE_URL + "/system/sling/logout");
NameValuePair [] logoutParams = new NameValuePair[1];
logoutParams[0] = new NameValuePair("resource", locationAfterLogout);
get.setQueryString(logoutParams);
get.setFollowRedirects(false);
final int status = H.getHttpClient().executeMethod(get);
assertEquals("Expected redirect", HttpServletResponse.SC_MOVED_TEMPORARILY, status);
Header location = get.getResponseHeader("Location");
assertEquals(HttpTest.HTTP_BASE_URL + locationAfterLogout, location.getValue());
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:26,代码来源:RedirectOnLogoutTest.java
示例4: testInternalRedirect
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/** test vanity path with internal redirect */
public void testInternalRedirect() throws IOException {
// create a node with a vanity path
Map<String, String> props = new HashMap<String, String>();
props.put("jcr:mixinTypes", "sling:VanityPath");
props.put("sling:vanityPath", vanityPath);
String createdNodeUrl = testClient.createNode(postUrl, props);
String createdPath = createdNodeUrl.substring(HTTP_BASE_URL.length());
waitForMapReload();
// get the created node without following redirects
GetMethod get = new GetMethod(vanityUrl);
get.setFollowRedirects(false);
int status = httpClient.executeMethod(get);
// expect a 200, not a redirect
assertEquals(200, status);
assertTrue(get.getResponseBodyAsString().contains(createdPath));
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:22,代码来源:VanityPathTest.java
示例5: testRejectRelativeRedirect
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testRejectRelativeRedirect() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(new RelativeRedirectService());
this.client.getParams().setBooleanParameter(
HttpClientParams.REJECT_RELATIVE_REDIRECT, true);
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
assertEquals(new URI("/oldlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例6: testRedirectKeepingExtensionAndSelector
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/** test vanity path with redirect using a non-html extension and a selector */
public void testRedirectKeepingExtensionAndSelector() throws IOException {
// create a node with a vanity path
Map<String, String> props = new HashMap<String, String>();
props.put("jcr:mixinTypes", "sling:VanityPath");
props.put("sling:vanityPath", vanityPath);
props.put("sling:redirect", "true");
String createdNodeUrl = testClient.createNode(postUrl, props);
waitForMapReload();
// get the created node's vanity path without following redirects
GetMethod get = new GetMethod(vanityUrl + ".test.json");
get.setFollowRedirects(false);
int status = httpClient.executeMethod(get);
// expect temporary redirect ...
assertEquals(302, status);
// ... to the created node
String location = get.getResponseHeader("Location").getValue();
assertNotNull(location);
assertEquals(removeHttpBase(createdNodeUrl) + ".test.json", location);
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:VanityPathTest.java
示例7: testBasicRedirect304
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect304() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(
new BasicRedirectService(host, port, HttpStatus.SC_NOT_MODIFIED));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_NOT_MODIFIED, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
assertEquals(new URI("/oldlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例8: testBasicRedirect302
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect302() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(
new BasicRedirectService(host, port, HttpStatus.SC_MOVED_TEMPORARILY));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("/newlocation/", httpget.getPath());
assertEquals(host, httpget.getURI().getHost());
assertEquals(port, httpget.getURI().getPort());
assertEquals(new URI("http://" + host + ":" + port + "/newlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例9: testRedirectJson2
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/** test JSON result for .json requests with sling:target */
public void testRedirectJson2() throws JsonException, IOException {
// create a sling:redirect node without a target
Map<String, String> props = new HashMap<String, String>();
props.put("sling:resourceType", "sling:redirect");
String redirNodeUrl = testClient.createNode(postUrl, props);
// get the created node without following redirects
final GetMethod get = new GetMethod(redirNodeUrl + ".json");
get.setFollowRedirects(false);
final int status = httpClient.executeMethod(get);
// expect 200 OK with the JSON data
assertEquals(200, status);
assertTrue(get.getResponseHeader("Content-Type").getValue().startsWith(CONTENT_TYPE_JSON));
// the json data
String jsonString = get.getResponseBodyAsString();
JsonObject json = JsonUtil.parseObject(jsonString);
assertEquals("sling:redirect", json.getString("sling:resourceType"));
}
示例10: testBasicRedirect305
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect305() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(
new BasicRedirectService(host, port, HttpStatus.SC_USE_PROXY));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_USE_PROXY, httpget.getStatusCode());
assertEquals("/oldlocation/", httpget.getPath());
assertEquals(new URI("/oldlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例11: testRedirectWithVirtualHost
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testRedirectWithVirtualHost() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
Protocol testhttp = new Protocol("http", new VirtualSocketFactory(host, port), port);
Protocol.registerProtocol("testhttp", testhttp);
try {
this.server.setHttpService(new VirtualHostService());
this.client.getHostConfiguration().setHost(host, port, "testhttp");
this.client.getHostConfiguration().getParams().setVirtualHost("whatever.com");
GetMethod httpget = new GetMethod("/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("http://www.whatever.co.nz/", httpget.getURI().toString());
} finally {
httpget.releaseConnection();
}
} finally {
Protocol.unregisterProtocol("testhttp");
}
}
示例12: testRelativeRedirect
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testRelativeRedirect() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(new RelativeRedirectService());
this.client.getParams().setBooleanParameter(
HttpClientParams.REJECT_RELATIVE_REDIRECT, false);
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals("/relativelocation/", httpget.getPath());
assertEquals(host, httpget.getURI().getHost());
assertEquals(port, httpget.getURI().getPort());
assertEquals(new URI("http://" + host + ":" + port + "/relativelocation/", false),
httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例13: testBasicRedirect301
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect301() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
this.server.setHttpService(
new BasicRedirectService(host, port, HttpStatus.SC_MOVED_PERMANENTLY));
GetMethod httpget = new GetMethod("/oldlocation/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("/newlocation/", httpget.getPath());
assertEquals(host, httpget.getURI().getHost());
assertEquals(port, httpget.getURI().getPort());
assertEquals(new URI("http://" + host + ":" + port + "/newlocation/", false), httpget.getURI());
} finally {
httpget.releaseConnection();
}
}
示例14: checkOnlineServers
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
* Checks all the servers marked as being online
* if they still are online.
*/
private synchronized void checkOnlineServers() {
Iterator itr;
itr = online.listIterator();
while (itr.hasNext()) {
Server server = (Server) itr.next();
String url = getServerURL(server);
GetMethod get = new GetMethod(url);
get.setFollowRedirects(false);
try {
httpClient.executeMethod(get);
if (!okServerResponse(get.getStatusCode())) {
offline.add(server);
itr.remove();
log.debug("Server going OFFLINE! " + getServerURL(server));
listener.serverOffline(server);
}
} catch (Exception e) {
offline.add(server);
itr.remove();
log.debug("Server going OFFLINE! " + getServerURL(server));
listener.serverOffline(server);
} finally {
get.releaseConnection();
}
}
}
示例15: get
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String get(String url, String cookies) throws
IOException {
// clearCookies();
GetMethod g = new GetMethod(url);
g.setFollowRedirects(false);
if (StringUtils.isNotEmpty(cookies)) {
g.addRequestHeader("cookie", cookies);
}
hc.executeMethod(g);
return g.getResponseBodyAsString();
}