geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r567195 - in /geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec: Header.java HttpMessage.java HttpRequestEncoder.java HttpRequestMessage.java
Date Sat, 18 Aug 2007 00:52:57 GMT
Author: jgenender
Date: Fri Aug 17 17:52:56 2007
New Revision: 567195

URL: http://svn.apache.org/viewvc?view=rev&rev=567195
Log:
More coding

Removed:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/Header.java
Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java?view=diff&rev=567195&r1=567194&r2=567195
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java Fri
Aug 17 17:52:56 2007
@@ -19,6 +19,8 @@
  */
 package org.apache.ahc.codec;
 
+import org.apache.ahc.util.NameValuePair;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.ArrayList;
@@ -26,9 +28,8 @@
 
 public class HttpMessage {
     
-    protected List<Header> headers = new ArrayList<Header>();
+    protected List<NameValuePair> headers = new ArrayList<NameValuePair>();
     protected List<Cookie> cookies = new ArrayList<Cookie>();
-    protected Map<String, String> attributes = new HashMap<String,String>();
     protected String contentType;
     protected int contentLength;
     protected byte[] content = null;
@@ -60,28 +61,21 @@
         this.cookies.add(cookie);
     }
 
-    public String getAttribute(String name){
-        return attributes.get(name);
-    }
-
-    public Map<String, String> getAttributes() {
-        return attributes;
-    }
 
-    public List<Header> getHeaders() {
+    public List<NameValuePair> getHeaders() {
         return headers;
     }
 
-    public void setHeaders(List<Header> headers) {
+    public void setHeaders(List<NameValuePair> headers) {
         this.headers = headers;
     }
 
-    public void addHeader(Header header){
+    public void addHeader(NameValuePair header){
         headers.add(header);
     }
 
     public void addHeader(String name, String value){
-        headers.add(new Header(name,value));
+        headers.add(new NameValuePair(name,value));
     }
 
     public String getContentType() {

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?view=diff&rev=567195&r1=567194&r2=567195
==============================================================================
--- 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
Fri Aug 17 17:52:56 2007
@@ -25,10 +25,12 @@
 import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.ByteBuffer;
+import org.apache.ahc.util.NameValuePair;
 
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Collections;
+import java.util.List;
 import java.nio.charset.CharsetEncoder;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
@@ -57,6 +59,7 @@
         HttpRequestMessage msg = (HttpRequestMessage) message;
 
         ByteBuffer buf = ByteBuffer.allocate(256);
+
         // Enable auto-expand for easier encoding
         buf.setAutoExpand(true);
 
@@ -68,11 +71,51 @@
             buf.putString(msg.getPath(), encoder);
             buf.putString(" HTTP/1.1", encoder);
             buf.put(CRLF);
+
+            //This header is required for HTTP/1.1
             buf.putString("Host: ", encoder);
             buf.putString(url.getHost(), encoder);
             buf.putString(":", encoder);
             buf.putString(url.getPort() + "", encoder);
             buf.put(CRLF);
+
+            //Process any headers we have
+            List<NameValuePair> headers = msg.getHeaders();
+            for (NameValuePair header : headers) {
+                String name = header.getName();
+                String value = header.getValue();
+
+                buf.putString(name, encoder);
+                buf.putString(": ", encoder);
+                buf.putString(value, encoder);
+                buf.put(CRLF);
+            }
+
+            //Process cookies
+            //NOTE: I am just passing the name value pairs and not doing management of the
expiration or path
+            //As that will be left up to the user.  A possible enhancement is to make use
of a CookieManager
+            //to handle these issues for the request
+            List<Cookie> cookies = msg.getCookies();
+            if (cookies.size() > 0) {
+                buf.putString("Cookie: ", encoder);
+                for (Cookie cookie : cookies) {
+                    String name = cookie.getName();
+                    String value = cookie.getValue();
+
+                    buf.putString(name, encoder);
+                    buf.putString("=", encoder);
+                    buf.putString(value, encoder);
+                    buf.putString("; ", encoder);
+                }
+                buf.put(CRLF);
+            }
+
+            //If this is a POST, then we need a content length and type
+            if (msg.getRequestMethod().equals(HttpRequestMessage.REQUEST_POST)) {
+
+            }
+
+            //Blank line
             buf.put(CRLF);
         } catch (CharacterCodingException ex) {
             ex.printStackTrace();

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?view=diff&rev=567195&r1=567194&r2=567195
==============================================================================
--- 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
Fri Aug 17 17:52:56 2007
@@ -35,6 +35,7 @@
 
     private String requestMethod = REQUEST_GET;
     private String path;
+    private Map<String, String> attributes = new HashMap<String,String>();
 
 
     public HttpRequestMessage(String path) {
@@ -61,14 +62,6 @@
         throw new ProtocolException("Invalid request method type.");
     }
 
-    public void setAttributes(Map<String, String> attributes) {
-        this.attributes.putAll(attributes);
-    }
-
-    public void setATtributes(String name, String value){
-        attributes.put(name, value);
-    }
-
     public String getPath() {
         return path;
     }
@@ -77,5 +70,21 @@
         if (path == null || path.trim().length() == 0)
             path = "/";
         this.path = path;
+    }
+
+    public String getAttribute(String name){
+        return attributes.get(name);
+    }
+
+    public Map<String, String> getAttributes() {
+        return attributes;
+    }
+
+    public void setAttributes(Map<String, String> attributes) {
+        this.attributes.putAll(attributes);
+    }
+
+    public void setAttribute(String name, String value){
+        attributes.put(name, value);
     }
 }



Mime
View raw message