KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > sampler > HTTPSampleResult


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampleResult.java,v 1.10.2.2 2004/12/18 13:36:54 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.http.sampler;
20
21 import java.net.URL JavaDoc;
22
23 import org.apache.jmeter.samplers.SampleResult;
24
25 /**
26  * This is a specialisation of the SampleResult class for the HTTP protocol.
27  *
28  * @author <a HREF="mailto:jsalvata@apache.org">Jordi Salvat i Alabart</a>
29  * @version $Revision: 1.10.2.2 $ updated on $Date: 2004/12/18 13:36:54 $
30  */

31 public class HTTPSampleResult extends SampleResult
32 {
33     public HTTPSampleResult()
34     {
35         super();
36     }
37     
38     public HTTPSampleResult(long elapsed)
39     {
40         super(elapsed,true);
41     }
42     
43     /**
44      * Construct a 'parent' result for an already-existing result, essentially
45      * cloning it
46      *
47      * @param res existing sample result
48      */

49     public HTTPSampleResult(HTTPSampleResult res)
50     {
51         super(res);
52
53         setHTTPMethod(res.getHTTPMethod());
54         setURL(res.getURL());
55         setCookies(res.getCookies());
56     }
57
58     private String JavaDoc method;
59     
60     public void setHTTPMethod(String JavaDoc method) {
61         this.method= method;
62     }
63     public String JavaDoc getHTTPMethod() {
64         return method;
65     }
66     
67     private String JavaDoc redirectLocation;
68
69     public void setRedirectLocation(String JavaDoc redirectLocation)
70     {
71         this.redirectLocation= redirectLocation;
72     }
73     public String JavaDoc getRedirectLocation()
74     {
75         return redirectLocation;
76     }
77
78     /**
79      * Determine whether this result is a redirect.
80      *
81      * @return true iif res is an HTTP redirect response
82      */

83     public boolean isRedirect()
84     {
85         final String JavaDoc[] REDIRECT_CODES= { "301", "302", "303" }; // NOT 304!
86
String JavaDoc code= getResponseCode();
87         for (int i= 0; i < REDIRECT_CODES.length; i++)
88         {
89             if (REDIRECT_CODES[i].equals(code))
90                 return true;
91         }
92         return false;
93     }
94     
95     
96     /* (non-Javadoc)
97      * @see org.apache.jmeter.samplers.SampleResult#getSamplerData()
98      */

99     public String JavaDoc getSamplerData()
100     {
101         StringBuffer JavaDoc sb= new StringBuffer JavaDoc();
102         sb.append(getHTTPMethod());
103         URL JavaDoc u= super.getURL();
104         if (u != null)
105         {
106             sb.append(' ');
107             sb.append(u.toString());
108         }
109         String JavaDoc s= super.getSamplerData();
110         if (s != null)
111         {
112             sb.append('\n');
113             sb.append(s);
114         }
115         return sb.toString();
116     }
117     
118     private String JavaDoc cookies=""; // never null
119
/**
120      * @return cookies as a string
121      */

122     public String JavaDoc getCookies()
123     {
124         return cookies;
125     }
126
127     /**
128      * @param string representing the cookies
129      */

130     public void setCookies(String JavaDoc string)
131     {
132         cookies = string;
133     }
134
135     private String JavaDoc queryString = ""; // never null
136
/**
137      * Fetch the query string
138      *
139      * @return the query string
140      */

141     public String JavaDoc getQueryString()
142     {
143         return queryString;
144     }
145
146     /**
147      * Save the query string
148      *
149      * @param string the query string
150      */

151     public void setQueryString(String JavaDoc string)
152     {
153         queryString = string;
154     }
155
156 }
157
Popular Tags