User: starksm
Date: 02/02/15 21:36:56
Modified: src/main/org/jboss/test/web/test HttpClient.java
WebIntegrationUnitTestCase.java
Log:
Remove the sleep delay
Revision Changes Path
1.5 +118 -121 jbosstest/src/main/org/jboss/test/web/test/HttpClient.java
Index: HttpClient.java
===================================================================
RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/web/test/HttpClient.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HttpClient.java 23 Dec 2001 00:00:20 -0000 1.4
+++ HttpClient.java 16 Feb 2002 05:36:56 -0000 1.5
@@ -14,132 +14,129 @@
import sun.misc.BASE64Encoder;
/** A simple socket based client for accesing http content.
-
-@author [EMAIL PROTECTED]
-@version $Revision: 1.4 $
-*/
+ *
+ * @author [EMAIL PROTECTED]
+ * @version $Revision: 1.5 $
+ */
public class HttpClient
{
- URL reqURL;
- int responseCode = -1;
- String response;
- StringBuffer content;
- HashMap headers = new HashMap();
-
- /** Creates new HttpClient */
- public HttpClient(String url) throws IOException
- {
- this.reqURL = new URL(url);
- }
- public HttpClient(URL url) throws IOException
- {
- this.reqURL = url;
- }
-
- public int getResponseCode() throws IOException
- {
- if( responseCode < 0 )
- transfer();
- return responseCode;
- }
- public String getResponseMessage() throws IOException
- {
- if( responseCode < 0 )
- transfer();
- return response;
- }
- public StringBuffer getContent() throws IOException
- {
- if( responseCode < 0 )
- transfer();
- return content;
- }
-
- public int transfer() throws IOException
- {
- String host = reqURL.getHost();
- int port = reqURL.getPort();
- if( port < 0 )
- port = 80;
- Socket conn = new Socket(host, port);
- OutputStream os = conn.getOutputStream();
- writeHeader(os);
-
-System.out.println("REMOVE THIS SLEEP WHEN include_ejb.jsp WORKS!");
-try{Thread.currentThread().sleep(5000);}catch(Exception e){}
- InputStream is = conn.getInputStream();
- readHeader(is);
- os.close();
- is.close();
- return responseCode;
- }
-
- private void writeHeader(OutputStream os)
- {
- PrintWriter pw = new PrintWriter(os);
- pw.write("GET " + reqURL.getPath() + " HTTP/1.1\r\n");
- pw.write("Accept: */*\r\n");
- pw.write("User-Agent: JBossTest WebClient\r\n");
- pw.write("Host: localhost:8080\r\n");
- pw.write("Connection: close\r\n");
- String userInfo = reqURL.getUserInfo();
- if( userInfo != null )
- {
- BASE64Encoder encoder = new BASE64Encoder();
- byte[] userInfoBytes = userInfo.getBytes();
- String authInfo = "Basic " + encoder.encode(userInfoBytes);
- pw.write("Authorization: " + authInfo+"\r\n");
- }
- pw.write("\r\n");
- pw.flush();
- }
-
- private void readHeader(InputStream is) throws IOException
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- String line;
- while( (line = reader.readLine()) != null )
- {
- // Check for "\r\n\r\n" end of headers marker
- if( line.length() == 0 )
- break;
-
- if( responseCode < 0 )
+ URL reqURL;
+ int responseCode = -1;
+ String response;
+ StringBuffer content;
+ HashMap headers = new HashMap();
+
+ /** Creates new HttpClient */
+ public HttpClient(String url) throws IOException
+ {
+ this.reqURL = new URL(url);
+ }
+ public HttpClient(URL url) throws IOException
+ {
+ this.reqURL = url;
+ }
+
+ public int getResponseCode() throws IOException
+ {
+ if( responseCode < 0 )
+ transfer();
+ return responseCode;
+ }
+ public String getResponseMessage() throws IOException
+ {
+ if( responseCode < 0 )
+ transfer();
+ return response;
+ }
+ public StringBuffer getContent() throws IOException
+ {
+ if( responseCode < 0 )
+ transfer();
+ return content;
+ }
+
+ public int transfer() throws IOException
+ {
+ String host = reqURL.getHost();
+ int port = reqURL.getPort();
+ if( port < 0 )
+ port = 80;
+ Socket conn = new Socket(host, port);
+ OutputStream os = conn.getOutputStream();
+ writeHeader(os);
+ InputStream is = conn.getInputStream();
+ readHeader(is);
+ os.close();
+ is.close();
+ return responseCode;
+ }
+
+ private void writeHeader(OutputStream os)
+ {
+ PrintWriter pw = new PrintWriter(os);
+ pw.write("GET " + reqURL.getPath() + " HTTP/1.1\r\n");
+ pw.write("Accept: */*\r\n");
+ pw.write("User-Agent: JBossTest WebClient\r\n");
+ pw.write("Host: localhost:8080\r\n");
+ pw.write("Connection: close\r\n");
+ String userInfo = reqURL.getUserInfo();
+ if( userInfo != null )
+ {
+ BASE64Encoder encoder = new BASE64Encoder();
+ byte[] userInfoBytes = userInfo.getBytes();
+ String authInfo = "Basic " + encoder.encode(userInfoBytes);
+ pw.write("Authorization: " + authInfo+"\r\n");
+ }
+ pw.write("\r\n");
+ pw.flush();
+ }
+
+ private void readHeader(InputStream is) throws IOException
+ {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ String line;
+ while( (line = reader.readLine()) != null )
+ {
+ // Check for "\r\n\r\n" end of headers marker
+ if( line.length() == 0 )
+ break;
+
+ if( responseCode < 0 )
+ {
+ // Parse the intial line for the "HTTP/1.x 200 OK" response
+ System.out.println("HttpClient.reponse = "+line);
+ response = line.substring(13);
+ line = line.substring(9, 12);
+ responseCode = Integer.parseInt(line);
+ }
+ else
+ {
+ int separator = line.indexOf(':');
+ if( separator > 0 )
{
- // Parse the intial line for the "HTTP/1.x 200 OK" response
- System.out.println("HttpClient.reponse = "+line);
- response = line.substring(13);
- line = line.substring(9, 12);
- responseCode = Integer.parseInt(line);
+ String key = line.substring(0, separator);
+ String value = line.substring(separator+1);
+ headers.put(key, value);
}
else
{
- int separator = line.indexOf(':');
- if( separator > 0 )
- {
- String key = line.substring(0, separator);
- String value = line.substring(separator+1);
- headers.put(key, value);
- }
- else
- {
- System.out.println("Invalid header '"+line+"'");
- }
+ System.out.println("Invalid header '"+line+"'");
}
- }
- content = new StringBuffer();
- while( (line = reader.readLine()) != null )
- {
- if( line.length() == 0 )
- break;
- content.append(line);
- content.append('\n');
- }
- }
-
- public static void main(String[] args) throws IOException
- {
- HttpClient hc = new
HttpClient("http://jduke:theduke@localhost:8080/jbosstest/restricted/SecureServlet");
- System.out.println(hc.transfer());
- }
+ }
+ }
+ content = new StringBuffer();
+ while( (line = reader.readLine()) != null )
+ {
+ if( line.length() == 0 )
+ break;
+ content.append(line);
+ content.append('\n');
+ }
+ }
+
+ public static void main(String[] args) throws IOException
+ {
+ HttpClient hc = new
HttpClient("http://jduke:theduke@localhost:8080/jbosstest/restricted/SecureServlet");
+ System.out.println(hc.transfer());
+ }
}
1.13 +2 -3
jbosstest/src/main/org/jboss/test/web/test/WebIntegrationUnitTestCase.java
Index: WebIntegrationUnitTestCase.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/web/test/WebIntegrationUnitTestCase.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- WebIntegrationUnitTestCase.java 29 Jan 2002 22:00:07 -0000 1.12
+++ WebIntegrationUnitTestCase.java 16 Feb 2002 05:36:56 -0000 1.13
@@ -33,12 +33,11 @@
The secure access tests require a user named 'jduke' with a password of 'theduke'
with a role of 'AuthorizedUser' in the servlet container.
- @author [EMAIL PROTECTED]
- @version $Revision: 1.12 $
+ @author [EMAIL PROTECTED]
+ @version $Revision: 1.13 $
*/
public class WebIntegrationUnitTestCase extends JBossTestCase
{
-
private String baseURL = "http://jduke:theduke@localhost:" +
Integer.getInteger("web.port", 8080) + "/";
public WebIntegrationUnitTestCase(String name)
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development