Author: scamp
Date: Mon Jun 13 15:41:47 2005
New Revision: 190523

URL: http://svn.apache.org/viewcvs?rev=190523&view=rev
Log: (empty)

Added:
    incubator/muse/trunk/src/ieeedemo/src/java/HttpHeader.java

Added: incubator/muse/trunk/src/ieeedemo/src/java/HttpHeader.java
URL: 
http://svn.apache.org/viewcvs/incubator/muse/trunk/src/ieeedemo/src/java/HttpHeader.java?rev=190523&view=auto
==============================================================================
--- incubator/muse/trunk/src/ieeedemo/src/java/HttpHeader.java (added)
+++ incubator/muse/trunk/src/ieeedemo/src/java/HttpHeader.java Mon Jun 13 
15:41:47 2005
@@ -0,0 +1,131 @@
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * HttpHeader
+ *
+ * This class is used to parse a String containing the Http Headers pulled 
from a Socket.
+ *
+ * <p/>
+ * User: SACAM
+ * Date: Jun 13, 2005
+ */
+public class HttpHeader
+{
+    /**
+     * Internal Map to hold the parsed headers
+     */
+    private Map m_headers = new HashMap();
+
+    /**
+     * Header Constants to be used as a reference for header lookups
+     */
+    public static final String ACCEPT = "Accept";
+    public static final String ACCEPT_CHARSET = "Accept-Charset";
+    public static final String ACCEPT_ENCODING = "Accept-Encoding";
+    public static final String ACCEPT_LANGUAGE = "Accept-Language";
+    public static final String AUTHORIZATION = "Authorization";
+    public static final String CACHE_CONTROL = "Cache-Control";
+    public static final String CONNECTION = "Connection";
+    public static final String CONTENT_LENGTH = "Content-Length";
+    public static final String DATE = "Date";
+    public static final String EXPECT = "Expect";
+    public static final String FROM = "From";
+    public static final String HOST = "Host";
+    public static final String IF_MATCH = "If-Match";
+    public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
+    public static final String IF_NONE_MATCH = "If-None-Match";
+    public static final String IF_RANGE = "If-Range";
+    public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
+    public static final String MAX_FORWARDS = "Max-Forwards";
+    public static final String PRAGMA = "Pragma";
+    public static final String PROXY_AUTHORIZATION = "Proxy-Authorization";
+    public static final String RANGE = "Range";
+    public static final String REFERER = "Referer";
+    public static final String TE = "TE";
+    public static final String TRAILER = "Trailer";
+    public static final String TRANSFER_ENCODING = "Transfer-Encoding";
+    public static final String UPGRADE = "Upgrade";
+    public static final String USER_AGENT = "User-Agent";
+    public static final String VIA = "Via";
+    public static final String WARNING = "Warning";
+
+
+    public HttpHeader(String headersString)
+    {
+        parseHeaders(headersString);
+    }
+
+    /**
+     * This method tokenizes and parses the incoming header String
+     *
+     * @param headersString
+     */
+    private void parseHeaders(String headersString)
+    {
+        System.out.println("Entered headers: " + headersString);
+        //parse the header string into a map
+
+        String[] strings = headersString.split("\n");
+        for (int i = 0; i < strings.length; i++)
+        {
+            String header = strings[i];
+            String[] values = header.split(": ");
+            m_headers.put(values[0].trim(), values[1].trim());
+        }
+
+        System.out.println("Parsed Headers: " +toString());//debug only
+    }
+
+    /**
+     * Returns the header given a header name.
+     *
+     * @param headerName The name of the header to be retrieved.
+     * @return The header value
+     */
+    public String getHeader(String headerName)
+    {
+        if (m_headers.containsKey(headerName))
+        {
+            return (String) m_headers.get(headerName);
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Overrideen toString() to dump the parsed headers.
+     *
+     * @return The parsed headers.
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        Iterator iterator = m_headers.keySet().iterator();
+        while (iterator.hasNext())
+        {
+            String key = (String) iterator.next();
+            sb.append(key + " : " + m_headers.get(key));
+        }
+        return sb.toString();
+    }
+    public static void main(String[] args)
+    {
+        HttpHeader header = new HttpHeader("Content-Type: text/xml; 
charset=utf-8\n" +
+                " Accept: application/soap+xml, application/dime, 
multipart/related, text/*\n" +
+                " User-Agent: Axis/1.2\n" +
+                " Host: 192.168.2.120:8001\n" +
+                " Cache-Control: no-cache\n" +
+                " Pragma: no-cache\n" +
+                " SOAPAction: \"\"\n" +
+                " Content-Length: 2950\n");
+        String content_length = header.getHeader(HttpHeader.CONTENT_LENGTH);
+        int i = Integer.parseInt(content_length);
+        System.out.println(content_length);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to