View | Details | Raw Unified | Return to bug 55175
Collapse All | Expand All

(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-19 / +67 lines)
Lines 224-235 Link Here
224
    protected HTTPSampleResult sample(URL url, String method,
224
    protected HTTPSampleResult sample(URL url, String method,
225
            boolean areFollowingRedirect, int frameDepth) {
225
            boolean areFollowingRedirect, int frameDepth) {
226
226
227
        HTTPSampleResult res = new HTTPSampleResult();
227
        HTTPSampleResult res = createSampleResult(url, method);
228
        res.setMonitor(isMonitor());
229
230
        res.setSampleLabel(url.toString()); // May be replaced later
231
        res.setHTTPMethod(method);
232
        res.setURL(url);
233
228
234
        HttpClient httpClient = setupClient(url);
229
        HttpClient httpClient = setupClient(url);
235
        
230
        
Lines 279-292 Link Here
279
274
280
        try {
275
        try {
281
            currentRequest = httpRequest;
276
            currentRequest = httpRequest;
282
            // Handle the various methods
277
            handleMethod(method, res, httpRequest, localContext);
283
            if (method.equals(HTTPConstants.POST)) {
284
                String postBody = sendPostData((HttpPost)httpRequest);
285
                res.setQueryString(postBody);
286
            } else if (method.equals(HTTPConstants.PUT) || method.equals(HTTPConstants.PATCH)) {
287
                String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
288
                res.setQueryString(entityBody);
289
            }
290
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
278
            HttpResponse httpResponse = httpClient.execute(httpRequest, localContext); // perform the sample
291
279
292
            // Needs to be done after execute to pick up all the headers
280
            // Needs to be done after execute to pick up all the headers
Lines 378-383 Link Here
378
    }
366
    }
379
367
380
    /**
368
    /**
369
     * Calls sendPostData if method is POST and sendEntityData if method is PUT or PATCH
370
     * Field HTTPSampleResult#queryString of result is modified in the 2 cases
371
     * @param method String HTTP method
372
     * @param result {@link HTTPSampleResult}
373
     * @param httpRequest {@link HttpRequestBase}
374
     * @param localContext {@link HttpContext}
375
     * @throws IOException
376
     */
377
    protected void handleMethod(String method, HTTPSampleResult result,
378
            HttpRequestBase httpRequest, HttpContext localContext) throws IOException {
379
        // Handle the various methods
380
        if (method.equals(HTTPConstants.POST)) {
381
            String postBody = sendPostData((HttpPost)httpRequest);
382
            result.setQueryString(postBody);
383
        } else if (method.equals(HTTPConstants.PUT) || method.equals(HTTPConstants.PATCH)) {
384
            String entityBody = sendEntityData(( HttpEntityEnclosingRequestBase)httpRequest);
385
            result.setQueryString(entityBody);
386
        }
387
    }
388
389
    /**
390
     * Create HTTPSampleResult filling url, method and SampleLabel.
391
     * Monitor field is computed calling isMonitor()
392
     * @param url URL
393
     * @param method HTTP Method
394
     * @return {@link HTTPSampleResult}
395
     */
396
    protected HTTPSampleResult createSampleResult(URL url, String method) {
397
        HTTPSampleResult res = new HTTPSampleResult();
398
        res.setMonitor(isMonitor());
399
400
        res.setSampleLabel(url.toString()); // May be replaced later
401
        res.setHTTPMethod(method);
402
        res.setURL(url);
403
        
404
        return res;
405
    }
406
407
    /**
381
     * Holder class for all fields that define an HttpClient instance;
408
     * Holder class for all fields that define an HttpClient instance;
382
     * used as the key to the ThreadLocal map of HttpClient instances.
409
     * used as the key to the ThreadLocal map of HttpClient instances.
383
     */
410
     */
Lines 558-564 Link Here
558
        return httpClient;
585
        return httpClient;
559
    }
586
    }
560
587
561
    private void setupRequest(URL url, HttpRequestBase httpRequest, HTTPSampleResult res)
588
    /**
589
     * Setup following elements on httpRequest:
590
     * <ul>
591
     * <li>ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING</li>
592
     * <li>Socket and connection timeout</li>
593
     * <li>Redirect handling</li>
594
     * <li>Keep Alive header or Connection Close</li>
595
     * <li>Calls setConnectionHeaders to setup headers</li>
596
     * <li>Calls setConnectionCookie to setup Cookie</li>
597
     * </ul>
598
     * @param url
599
     * @param httpRequest
600
     * @param res
601
     * @throws IOException
602
     */
603
    protected void setupRequest(URL url, HttpRequestBase httpRequest, HTTPSampleResult res)
562
        throws IOException {
604
        throws IOException {
563
605
564
    HttpParams requestParams = httpRequest.getParams();
606
    HttpParams requestParams = httpRequest.getParams();
Lines 648-654 Link Here
648
     * @return a String containing the cookie details (for the response)
690
     * @return a String containing the cookie details (for the response)
649
     * May be null
691
     * May be null
650
     */
692
     */
651
    private String setConnectionCookie(HttpRequest request, URL url, CookieManager cookieManager) {
693
    protected String setConnectionCookie(HttpRequest request, URL url, CookieManager cookieManager) {
652
        String cookieHeader = null;
694
        String cookieHeader = null;
653
        if (cookieManager != null) {
695
        if (cookieManager != null) {
654
            cookieHeader = cookieManager.getCookieHeaderForURL(url);
696
            cookieHeader = cookieManager.getCookieHeaderForURL(url);
Lines 672-678 Link Here
672
     *            for this <code>UrlConfig</code>
714
     *            for this <code>UrlConfig</code>
673
     * @param cacheManager the CacheManager (may be null)
715
     * @param cacheManager the CacheManager (may be null)
674
     */
716
     */
675
    private void setConnectionHeaders(HttpRequestBase request, URL url, HeaderManager headerManager, CacheManager cacheManager) {
717
    protected void setConnectionHeaders(HttpRequestBase request, URL url, HeaderManager headerManager, CacheManager cacheManager) {
676
        if (headerManager != null) {
718
        if (headerManager != null) {
677
            CollectionProperty headers = headerManager.getHeaders();
719
            CollectionProperty headers = headerManager.getHeaders();
678
            if (headers != null) {
720
            if (headers != null) {
Lines 790-796 Link Here
790
    }
832
    }
791
833
792
    // TODO needs cleaning up
834
    // TODO needs cleaning up
793
    private String sendPostData(HttpPost post)  throws IOException {
835
    /**
836
     * 
837
     * @param post {@link HttpPost}
838
     * @return String posted body if computable
839
     * @throws IOException
840
     */
841
    protected String sendPostData(HttpPost post)  throws IOException {
794
        // Buffer to hold the post body, except file content
842
        // Buffer to hold the post body, except file content
795
        StringBuilder postedBody = new StringBuilder(1000);
843
        StringBuilder postedBody = new StringBuilder(1000);
796
        HTTPFileArg files[] = getHTTPFiles();
844
        HTTPFileArg files[] = getHTTPFiles();
Lines 1008-1014 Link Here
1008
     * @throws  UnsupportedEncodingException for invalid charset name
1056
     * @throws  UnsupportedEncodingException for invalid charset name
1009
     * @throws IOException cannot really occur for ByteArrayOutputStream methods
1057
     * @throws IOException cannot really occur for ByteArrayOutputStream methods
1010
     */
1058
     */
1011
    private String sendEntityData( HttpEntityEnclosingRequestBase entity) throws IOException {
1059
    protected String sendEntityData( HttpEntityEnclosingRequestBase entity) throws IOException {
1012
        // Buffer to hold the entity body
1060
        // Buffer to hold the entity body
1013
        StringBuilder entityBody = new StringBuilder(1000);
1061
        StringBuilder entityBody = new StringBuilder(1000);
1014
        boolean hasEntityBody = false;
1062
        boolean hasEntityBody = false;

Return to bug 55175