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

HttpURLConnection org::apache::jmeter::protocol::http::sampler::HTTPSampler::setupConnection ( URL  u,
String  method,
HTTPSampleResult  res 
) throws IOException [inline, protected]

Returns an HttpURLConnection 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
method GET, POST etc
res sample result to save request infos to
HttpURLConnection ready for .connect
IOException if an I/O Exception occurs

Definition at line 183 of file HTTPSampler.java.

References getConnectionHeaders(), org::apache::jmeter::util::SSLManager::getInstance(), setConnectionAuthorization(), setConnectionCookie(), setConnectionHeaders(), org::apache::jmeter::util::SSLManager::setContext(), and setPostHeaders().

Referenced by sample().

        SSLManager sslmgr = null;
        if (PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
            try {
                sslmgr=SSLManager.getInstance(); // N.B. this needs to be done before opening the connection
            } catch (Exception e) {
                log.warn("Problem creating the SSLManager: ", e);

        HttpURLConnection conn = (HttpURLConnection) u.openConnection();
        // Update follow redirects setting just for this connection

        int cto = getConnectTimeout();
        if (cto > 0){
            setTimeout(setConnectTimeout, conn, cto);
        int rto = getResponseTimeout();
        if (rto > 0){
            setTimeout(setReadTimeout, conn, rto);
        if (PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
            try {
                if (null != sslmgr){
                    sslmgr.setContext(conn); // N.B. must be done after opening connection
            } catch (Exception e) {
                log.warn("Problem setting the SSLManager for the connection: ", e);

        // a well-bahaved 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()) {
            conn.setRequestProperty(HEADER_CONNECTION, KEEP_ALIVE);
        } else {
            conn.setRequestProperty(HEADER_CONNECTION, CONNECTION_CLOSE);

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

        setConnectionAuthorization(conn, u, getAuthManager());

        if (method.equals(POST)) {
        } else if (method.equals(PUT)) {

        if (res != null) {

        return conn;

Generated by  Doxygen 1.6.0   Back to index