geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r567831 - in /geronimo/sandbox/AsyncHttpClient/src: main/java/org/apache/ahc/codec/ test/catalina/webapps/ROOT/ test/java/org/apache/ahc/
Date Mon, 20 Aug 2007 21:17:27 GMT
Author: jgenender
Date: Mon Aug 20 14:17:21 2007
New Revision: 567831

URL: http://svn.apache.org/viewvc?rev=567831&view=rev
Log:
Set parameters and test POST

Added:
    geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/params.jsp
Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
    geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java?rev=567831&r1=567830&r2=567831&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
Mon Aug 20 14:17:21 2007
@@ -64,15 +64,14 @@
 
         try {
             //If we have content, lets create the query string
-            int attrCount = msg.getAttributes().size();
+            int attrCount = msg.getParameters().size();
             String urlAttrs = "";
             if (attrCount > 0){
                 NameValuePair attrs[] = new NameValuePair[attrCount];
-                Set<Map.Entry<String,String>> set = msg.getAttributes().entrySet();
+                Set<Map.Entry<String,String>> set = msg.getParameters().entrySet();
                 int i = 0;
                 for (Map.Entry<String, String> entry: set){
-                    attrs[i].setName(entry.getKey());
-                    attrs[i++].setValue(entry.getValue());
+                    attrs[i++] = new NameValuePair(entry.getKey(), entry.getValue());
                 }
                 urlAttrs = EncodingUtil.formUrlEncode(attrs, Charset.defaultCharset().toString());
             }

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=567831&r1=567830&r2=567831&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
Mon Aug 20 14:17:21 2007
@@ -35,7 +35,7 @@
 
     private String requestMethod = REQUEST_GET;
     private String path;
-    private Map<String, String> attributes = new HashMap<String,String>();
+    private Map<String, String> parameters = new HashMap<String,String>();
 
 
     public HttpRequestMessage(String path) {
@@ -72,19 +72,19 @@
         this.path = path;
     }
 
-    public String getAttribute(String name){
-        return attributes.get(name);
+    public String getParameter(String name){
+        return parameters.get(name);
     }
 
-    public Map<String, String> getAttributes() {
-        return attributes;
+    public Map<String, String> getParameters() {
+        return parameters;
     }
 
-    public void setAttributes(Map<String, String> attributes) {
-        this.attributes.putAll(attributes);
+    public void setParameters(Map<String, String> parameters) {
+        this.parameters.putAll(parameters);
     }
 
-    public void setAttribute(String name, String value){
-        attributes.put(name, value);
+    public void setParameter(String name, String value){
+        parameters.put(name, value);
     }
 }

Added: geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/params.jsp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/params.jsp?rev=567831&view=auto
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/params.jsp (added)
+++ geronimo/sandbox/AsyncHttpClient/src/test/catalina/webapps/ROOT/params.jsp Mon Aug 20
14:17:21 2007
@@ -0,0 +1 @@
+<%= request.getParameter("TEST1") %> <%= request.getParameter("TEST2") %>
\ No newline at end of file

Modified: geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java?rev=567831&r1=567830&r2=567831&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/test/java/org/apache/ahc/AsyncHttpClientTest.java
Mon Aug 20 14:17:21 2007
@@ -33,7 +33,7 @@
 
     public void testHtmlConnection() throws Exception {
         TestCallback callback = new TestCallback();
-        doConnection(callback, "http://localhost:8282","/", false);
+        doGetConnection(callback, "http://localhost:8282","/", false);
 
         HttpResponseMessage msg = callback.getMessage();
         assertEquals("\nHello World!", msg.getStringContent());
@@ -41,7 +41,7 @@
 
     public void testSSLHtmlConnection() throws Exception {
         TestCallback callback = new TestCallback();
-        doConnection(callback, "https://localhost:8383","/", false);
+        doGetConnection(callback, "https://localhost:8383","/", false);
 
         HttpResponseMessage msg = callback.getMessage();
         assertEquals("\nHello World!", msg.getStringContent());
@@ -56,7 +56,7 @@
         fis.read(realFile);
         
         TestCallback callback = new TestCallback();
-        doConnection(callback, "http://localhost:8282","/pwrd_apache.gif", false);
+        doGetConnection(callback, "http://localhost:8282","/pwrd_apache.gif", false);
 
         HttpResponseMessage msg = callback.getMessage();
 
@@ -72,20 +72,50 @@
         fis.read(realFile);
 
         TestCallback callback = new TestCallback();
-        doConnection(callback, "https://localhost:8383","/pwrd_apache.gif", false);
+        doGetConnection(callback, "https://localhost:8383","/pwrd_apache.gif", false);
 
         HttpResponseMessage msg = callback.getMessage();
 
         assertTrue(Arrays.equals(realFile,msg.getContent()));
     }
 
-    private void doConnection(TestCallback callback, String url, String uri, boolean testForException)
throws Exception {
+    public void testGetParameters() throws Exception {
+        TestCallback callback = new TestCallback();
+        doGetConnection(callback, "http://localhost:8282","/params.jsp", false);
+
+        HttpResponseMessage msg = callback.getMessage();
+        assertEquals("Test One Test Two", msg.getStringContent());
+    }
+
+    public void testPostParameters() throws Exception {
+        TestCallback callback = new TestCallback();
+        doPostConnection(callback, "http://localhost:8282","/params.jsp", false);
+
+        HttpResponseMessage msg = callback.getMessage();
+        assertEquals("Test One Test Two", msg.getStringContent());
+    }
+
+    private void doGetConnection(TestCallback callback, String url, String uri, boolean testForException)
throws Exception {
+        HttpRequestMessage request = new HttpRequestMessage(uri);
+        request.setParameter("TEST1","Test One");
+        request.setParameter("TEST2","Test Two");
+        doConnection(callback, url, request, false);
+    }
+
+    private void doPostConnection(TestCallback callback, String url, String uri, boolean
testForException) throws Exception {
+        HttpRequestMessage request = new HttpRequestMessage(uri);
+        request.setParameter("TEST1","Test One");
+        request.setParameter("TEST2","Test Two");
+        request.setRequestMethod(HttpRequestMessage.REQUEST_POST);
+        doConnection(callback, url, request, false);
+    }
+
+    private void doConnection(TestCallback callback, String url, HttpRequestMessage request,
boolean testForException) throws Exception {
         URL url_connect = new URL(url);
 
         AsyncHttpClient ahc = new AsyncHttpClient(url_connect, callback);
         ahc.connect();
 
-        HttpRequestMessage request = new HttpRequestMessage(uri);
         ahc.sendRequest(request);
 
         //We are done...Thread would normally end...



Mime
View raw message