Logo Search packages:      
Sourcecode: jakarta-jmeter version File versions  Download package

HttpClient org::apache::jmeter::protocol::http::sampler::HTTPSampler2::setupConnection ( URL  u,
HttpMethodBase  httpMethod,
HTTPSampleResult  res 
) throws IOException [inline, protected, inherited]

Returns an HttpConnection fully ready to attempt connection. This means it sets the request method (GET or POST), headers, cookies, and authorization for the URL request.

The request infos are saved into the sample result if one is provided.

u URL of the URL request
httpMethod GET/PUT/HEAD etc
res sample result to save request infos to
HttpConnection ready for .connect
IOException if an I/O Exception occurs

Definition at line 503 of file HTTPSampler2.java.

References org::apache::jmeter::protocol::http::sampler::HTTPSampler2::setConnectionAuthorization(), org::apache::jmeter::protocol::http::sampler::HTTPSampler2::setConnectionCookie(), and org::apache::jmeter::protocol::http::sampler::HTTPSampler2::setConnectionHeaders().

Referenced by sample(), and org::apache::jmeter::protocol::http::sampler::HTTPSampler2::sample().


        String urlStr = u.toString();

        org.apache.commons.httpclient.URI uri = new org.apache.commons.httpclient.URI(urlStr,false);

        String schema = uri.getScheme();
        if ((schema == null) || (schema.length()==0)) {
            schema = PROTOCOL_HTTP;

        if (PROTOCOL_HTTPS.equalsIgnoreCase(schema)){
            SSLManager.getInstance(); // ensure the manager is initialised
            // we don't currently need to do anything further, as this sets the default https protocol

        Protocol protocol = Protocol.getProtocol(schema);

        String host = uri.getHost();
        int port = uri.getPort();

         *  We use the HostConfiguration as the key to retrieve the HttpClient,
         *  so need to ensure that any items used in its equals/hashcode methods are
         *  not changed after use, i.e.:
         *  host, port, protocol, localAddress, proxy
        HostConfiguration hc = new HostConfiguration();
        hc.setHost(host, port, protocol); // All needed to ensure re-usablility

        // Set up the local address if one exists
        if (localAddress != null){

        boolean useProxy = PROXY_DEFINED && !isNonProxy(host);
        if (useProxy) {
            if (log.isDebugEnabled()){
                log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
            hc.setProxy(PROXY_HOST, PROXY_PORT);

        Map map = (Map) httpClients.get();
        HttpClient httpClient = (HttpClient) map.get(hc);

        if ( httpClient == null )
            httpClient = new HttpClient(new SimpleHttpConnectionManager());
            if (log.isDebugEnabled()) {
                log.debug("Created new HttpClient: @"+System.identityHashCode(httpClient));
            map.put(hc, httpClient);
            // These items don't change, so only need to be done once
            if (useProxy) {
                if (PROXY_USER.length() > 0){
                        new AuthScope(PROXY_HOST,PROXY_PORT,null,AuthScope.ANY_SCHEME),
                        new NTCredentials(PROXY_USER,PROXY_PASS,localHost,PROXY_DOMAIN)

        } else {
            if (log.isDebugEnabled()) {
                log.debug("Reusing the HttpClient: @"+System.identityHashCode(httpClient));

        int rto = getResponseTimeout();
        if (rto > 0){

        int cto = getConnectTimeout();
        if (cto > 0){

        // Allow HttpClient to handle the redirects:

        // a well-behaved browser is supposed to send 'Connection: close'
        // with the last request to an HTTP server. Instead, most browsers
        // leave it to the server to close the connection after their
        // timeout period. Leave it to the JMeter user to decide.
        if (getUseKeepAlive()) {
            httpMethod.setRequestHeader(HEADER_CONNECTION, KEEP_ALIVE);
        } else {
            httpMethod.setRequestHeader(HEADER_CONNECTION, CONNECTION_CLOSE);

        setConnectionHeaders(httpMethod, u, getHeaderManager(), getCacheManager());
        String cookies = setConnectionCookie(httpMethod, u, getCookieManager());

        setConnectionAuthorization(httpClient, u, getAuthManager());

        if (res != null) {

        return httpClient;

Generated by  Doxygen 1.6.0   Back to index