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


Java GetMethod.releaseConnection方法代码示例

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


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

示例1: testAddRequestHeader

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Test {@link HttpMethod#addRequestHeader}.
 */
public void testAddRequestHeader() throws Exception {
    this.server.setHttpService(new HeaderDumpService());
    
    GetMethod method = new GetMethod("/");
    method.setRequestHeader(new Header("addRequestHeader(Header)","True"));
    method.setRequestHeader("addRequestHeader(String,String)","Also True");
    try {
        this.client.executeMethod(method);
        String s = method.getResponseBodyAsString();
        assertTrue(s.indexOf("name=\"addrequestheader(header)\";value=\"True\"") >= 0);
        assertTrue(s.indexOf("name=\"addrequestheader(string,string)\";value=\"Also True\"") >= 0);
    } finally {
        method.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestHeaderOps.java

示例2: testHttpMethodBaseTEandCL

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/** 
 * Tests response with a Trasfer-Encoding and Content-Length 
 */
public void testHttpMethodBaseTEandCL() throws Exception {
    this.server.setHttpService(new SimpleChunkedService());
    
    GetMethod httpget = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
        assertEquals("1234567890123", httpget.getResponseBodyAsString());
        assertTrue(this.client.getHttpConnectionManager() instanceof SimpleHttpConnectionManager);
        HttpConnection conn = this.client.getHttpConnectionManager().
            getConnection(this.client.getHostConfiguration());
        assertNotNull(conn);
        conn.assertNotOpen();
    } finally {
        httpget.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:21,代码来源:TestHttpMethodFundamentals.java

示例3: testPreemptiveAuthProxy

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testPreemptiveAuthProxy() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.client.getParams().setAuthenticationPreemptive(true);
    this.server.setHttpService(new FeedbackService());

    this.proxy.requireAuthentication(creds, "test", true);
    
    GetMethod get = new GetMethod("/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
        if (isUseSSL()) {
            assertNull(get.getRequestHeader("Proxy-Authorization"));
        } else {
            assertNotNull(get.getRequestHeader("Proxy-Authorization"));
        }
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestProxy.java

示例4: testBasicRedirect307

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testBasicRedirect307() throws IOException {
    String host = this.server.getLocalAddress();
    int port = this.server.getLocalPort();
    this.server.setHttpService(
            new BasicRedirectService(host, port, HttpStatus.SC_TEMPORARY_REDIRECT));
    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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestRedirects.java

示例5: testGetInteractiveProxyAuthHostAuthConnKeepAlive

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Tests GET via authenticating proxy + interactive host and proxy auth + connection keep-alive 
 */
public void testGetInteractiveProxyAuthHostAuthConnKeepAlive() throws Exception {

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getParams().setParameter(CredentialsProvider.PROVIDER, 
            new GetItWrongThenGetItRight());
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);

    this.proxy.requireAuthentication(creds, "test", true);
    
    GetMethod get = new GetMethod("/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:28,代码来源:TestProxy.java

示例6: 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();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:TestRedirects.java

示例7: testCookieVersionSupportHeader2

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testCookieVersionSupportHeader2() throws IOException {
    this.server.setHttpService(new CookieVer1Service());
    this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
    GetMethod httpget1 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget1);
    } finally {
        httpget1.releaseConnection();
    }
    GetMethod httpget2 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget2);
    } finally {
        httpget2.releaseConnection();
    }
    Header cookiesupport = httpget2.getRequestHeader("Cookie2");
    assertNull(cookiesupport);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestCookieVersionSupport.java

示例8: testDefaults

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testDefaults() throws IOException {
    this.server.setHttpService(new SimpleService());

    this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");
    HostConfiguration hostconfig = new HostConfiguration();
    hostconfig.setHost(
            this.server.getLocalAddress(), 
            this.server.getLocalPort(),
            Protocol.getProtocol("http"));
    
    GetMethod httpget = new GetMethod("/miss/");
    try {
        this.client.executeMethod(hostconfig, httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
    assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
    assertEquals("test", httpget.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
    assertEquals("test", hostconfig.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
    assertEquals("test", client.getParams().
            getParameter(HttpMethodParams.USER_AGENT));
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:TestHttpParams.java

示例9: testGetProxyAuthHostAuthHTTP10

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
 * Tests GET via authenticating proxy + host auth + HTTP/1.0 
 */
public void testGetProxyAuthHostAuthHTTP10() throws Exception {

    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    this.client.getState().setCredentials(AuthScope.ANY, creds);
    this.client.getState().setProxyCredentials(AuthScope.ANY, creds);
    this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds, "test", true));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
    
    this.server.setRequestHandler(handlerchain);
    
    this.proxy.requireAuthentication(creds, "test", false);
    
    GetMethod get = new GetMethod("/");
    try {
        this.client.executeMethod(get);
        assertEquals(HttpStatus.SC_OK, get.getStatusCode());
    } finally {
        get.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestProxy.java

示例10: testCookieVersionSupportHeader3

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testCookieVersionSupportHeader3() throws IOException {
    this.server.setHttpService(new CookieVer2Service());
    this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
    GetMethod httpget1 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget1);
    } finally {
        httpget1.releaseConnection();
    }
    GetMethod httpget2 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget2);
    } finally {
        httpget2.releaseConnection();
    }
    Header cookiesupport = httpget2.getRequestHeader("Cookie2");
    assertNotNull(cookiesupport);
    assertEquals("$Version=\"1\"", cookiesupport.getValue());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestCookieVersionSupport.java

示例11: httpClientPost

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public static final String httpClientPost(String url) {
    String result = "";
    HttpClient client = new HttpClient();
    GetMethod getMethod = new GetMethod(url);
    try {
        client.executeMethod(getMethod);
        result = getMethod.getResponseBodyAsString();
    } catch (Exception e) {
        logger.error("", e);
    } finally {
        getMethod.releaseConnection();
    }
    return result;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:15,代码来源:HttpUtil.java

示例12: 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();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:32,代码来源:ServerStatusChecker.java

示例13: main

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public static void main(String[] args) {
    
    // register the auth scheme
    AuthPolicy.registerAuthScheme("Negotiate", NegotiateScheme.class);

    // include the scheme in the AuthPolicy.AUTH_SCHEME_PRIORITY preference
    ArrayList schemes = new ArrayList();
    schemes.add("Negotiate");

    HttpParams params = DefaultHttpParams.getDefaultParams();        
    params.setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
    
    // now that our scheme has been registered we can execute methods against
    // servers that require "Negotiate" authentication... 
    HttpClient client = new HttpClient();
    
    // The Negotiate scheme uses JAAS as credential provider but the
    // httpclient api require us to supply cred anyway.
    // a work around is to provide an empty set of creds.
    Credentials use_jaas_creds = new Credentials() {};
    client.getState().setCredentials(
        new AuthScope(null, -1, null),
        use_jaas_creds);
    GetMethod httpget = new GetMethod(args[0]);

    try {
        client.executeMethod(httpget);
        //System.out.println(httpget.getStatusLine());
        //System.out.println(httpget.getResponseBodyAsString());
    } catch (Exception e) {
        e.printStackTrace();            
    } finally {
        // release any connection resources used by the method
        httpget.releaseConnection();
    }            
    
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:CustomAuthenticationNegotiateExample.java

示例14: testPreemptiveAuthorizationTrueWithoutCreds

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testPreemptiveAuthorizationTrueWithoutCreds() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    HttpState state = new HttpState();
    this.client.setState(state);
    this.client.getParams().setAuthenticationPreemptive(true);
    
    this.server.setRequestHandler(handlerchain);

    GetMethod httpget = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertNotNull(httpget.getStatusLine());
    assertEquals(HttpStatus.SC_UNAUTHORIZED, httpget.getStatusLine().getStatusCode());
    Header auth = httpget.getRequestHeader("Authorization");
    assertNull(auth);
    AuthState authstate = httpget.getHostAuthState();
    assertNotNull(authstate.getAuthScheme());
    assertTrue(authstate.getAuthScheme() instanceof BasicScheme);
    assertNotNull(authstate.getRealm());
    assertTrue(authstate.isPreemptive());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:31,代码来源:TestBasicAuth.java

示例15: testEmptyBodyAsByteArray

import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testEmptyBodyAsByteArray() throws Exception {
    this.server.setHttpService(new EmptyResponseService());
    
    GetMethod httpget = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget);
        assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
        byte[] response = httpget.getResponseBody();
        assertNull(response);
    } finally {
        httpget.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:14,代码来源:TestHttpMethodFundamentals.java


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