当前位置: 首页>>代码示例>>Java>>正文


Java GetMethod.getResponseHeader方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.methods.GetMethod.getResponseHeader方法的典型用法代码示例。如果您正苦于以下问题:Java GetMethod.getResponseHeader方法的具体用法?Java GetMethod.getResponseHeader怎么用?Java GetMethod.getResponseHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.methods.GetMethod的用法示例。


在下文中一共展示了GetMethod.getResponseHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: processConditionalRetrievalHeaders

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Records the ETag and Last-Modified headers, from the response, if they are present.
 * 
 * @param getMethod GetMethod containing a valid HTTP response
 */
protected void processConditionalRetrievalHeaders(GetMethod getMethod) {
    Header httpHeader = getMethod.getResponseHeader("ETag");
    if (httpHeader != null) {
        cachedMetadataETag = httpHeader.getValue();
    }

    httpHeader = getMethod.getResponseHeader("Last-Modified");
    if (httpHeader != null) {
        cachedMetadataLastModified = httpHeader.getValue();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HTTPMetadataProvider.java

示例3: getHeader

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String getHeader(String url, String cookies, String headername) throws IOException {
//        clearCookies();
        GetMethod g = new GetMethod(url);
        g.setFollowRedirects(false);
        if (StringUtils.isNotEmpty(cookies)) {
            g.addRequestHeader("cookie", cookies);
        }
        hc.executeMethod(g);
        return g.getResponseHeader(headername) == null ? null : g.getResponseHeader(headername).getValue();
    }
 
开发者ID:bruceq,项目名称:Gather-Platform,代码行数:11,代码来源:HttpClientUtil.java

示例4: testWebServerRoot

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testWebServerRoot() throws Exception
{
    // by default, the Launchpad default servlet redirects / to index.html
    final String url = HTTP_BASE_URL + "/";
    final GetMethod get = new GetMethod(url);
    get.setFollowRedirects(false);
    final int status = httpClient.executeMethod(get);
    assertEquals("Status must be 302 for " + url, 302, status);
    final Header h = get.getResponseHeader("Location");
    assertNotNull("Location header must be provided",h);
    assertTrue("Location header must end with index.html", h.getValue().endsWith("index.html"));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:13,代码来源:HttpPingTest.java

示例5: getAuthenticatedContent

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/** retrieve the contents of given URL and assert its content type
 * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
 * @throws IOException
 * @throws HttpException */
public String getAuthenticatedContent(Credentials creds, String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode) throws IOException {
    final GetMethod get = new GetMethod(url);

    URL baseUrl = new URL(HTTP_BASE_URL);
    AuthScope authScope = new AuthScope(baseUrl.getHost(), baseUrl.getPort(), AuthScope.ANY_REALM);
    get.setDoAuthentication(true);
    Credentials oldCredentials = httpClient.getState().getCredentials(authScope);
    try {
        httpClient.getState().setCredentials(authScope, creds);

        if(params != null) {
            final NameValuePair [] nvp = new NameValuePair[0];
            get.setQueryString(params.toArray(nvp));
        }
        final int status = httpClient.executeMethod(get);
        final InputStream is = get.getResponseBodyAsStream();
        final StringBuffer content = new StringBuffer();
        final String charset = get.getResponseCharSet();
        final byte [] buffer = new byte[16384];
        int n = 0;
        while( (n = is.read(buffer, 0, buffer.length)) > 0) {
            content.append(new String(buffer, 0, n, charset));
        }
        assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
                expectedStatusCode,status);
        final Header h = get.getResponseHeader("Content-Type");
        if(expectedContentType == null) {
            if(h!=null) {
                fail("Expected null Content-Type, got " + h.getValue());
            }
        } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
            // no check
        } else if(h==null) {
            fail(
                    "Expected Content-Type that starts with '" + expectedContentType
                    +" but got no Content-Type header at " + url
            );
        } else {
            assertTrue(
                "Expected Content-Type that starts with '" + expectedContentType
                + "' for " + url + ", got '" + h.getValue() + "'",
                h.getValue().startsWith(expectedContentType)
            );
        }
        return content.toString();

    } finally {
        httpClient.getState().setCredentials(authScope, oldCredentials);
    }
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:55,代码来源:AuthenticatedTestUtil.java


注:本文中的org.apache.commons.httpclient.methods.GetMethod.getResponseHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。