當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。