[MOBY-guts] biomoby commit

Gary Schlitz gss at pub.open-bio.org
Thu Nov 4 22:22:29 UTC 2004


gss
Thu Nov  4 17:22:29 EST 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/http
In directory pub.open-bio.org:/tmp/cvs-serv31274/src/org/smoby/http

Modified Files:
	HTTPRequest.java 
Log Message:
Misc fixes

moby-live/S-MOBY/ref-impl/core/src/org/smoby/http HTTPRequest.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/http/HTTPRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/http/HTTPRequest.java	2004/05/24 22:05:35	1.1
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/src/org/smoby/http/HTTPRequest.java	2004/11/04 22:22:29	1.2
@@ -16,18 +16,21 @@
 public class HTTPRequest
 {
 	/**
-	 * Constant meaning to use HTTP GET as the method for communicating
-	 * with the registration server.
+	 * Constant meaning to use HTTP GET as the method
 	 */
 	public final static int HTTP_GET = 0;
 	
 	/**
-	 * Constant meaning to use HTTP POST as the method for communicating
-	 * with the registration server.
+	 * Constant meaning to use HTTP POST as the method
 	 */
 	public final static int HTTP_POST = 1;
 	
 	/**
+	 * Constant meaning to use HTTP HEAD as the method
+	 */
+	public final static int HTTP_HEAD = 2;
+	
+	/**
 	 * The URL of the server to be contacted
 	 */
 	private String serverURL = null;
@@ -63,6 +66,11 @@
         return new HTTPRequest(serverURL, HTTP_POST);
     }
     
+    public static HTTPRequest newHeadRequest(String uri)
+    {
+    	return new HTTPRequest(uri, HTTP_HEAD);
+    }
+    
     public void addParameter(String paramName, String paramValue)
     {
     	params.add(new NameValuePair(paramName, paramValue));
@@ -97,20 +105,27 @@
 	{
         HttpMethod methodObject = null;
         
-		if (method == HTTP_GET) {
-            methodObject = new GetMethod(getURLString());
-        }
-        else if (method == HTTP_POST)
-        {
-            methodObject = new PostMethod(getURLString());
-            NameValuePair[] paramArray = new NameValuePair[params.size()];
-	        Iterator it = params.iterator();
-	        for (int i = 0; i < paramArray.length; i++)
-	        {
-	        	paramArray[i] = (NameValuePair) it.next();
-	        }
-	        ((PostMethod) methodObject).setRequestBody(paramArray);
-        }
+        switch (method)
+		{
+        	case HTTP_GET :
+                methodObject = new GetMethod(getURLString());
+                break;
+            
+            case HTTP_POST :
+                methodObject = new PostMethod(getURLString());
+                NameValuePair[] paramArray = new NameValuePair[params.size()];
+    	        Iterator it = params.iterator();
+    	        for (int i = 0; i < paramArray.length; i++)
+    	        {
+    	        	paramArray[i] = (NameValuePair) it.next();
+    	        }
+    	        ((PostMethod) methodObject).setRequestBody(paramArray);
+    	        break;
+    	    
+    	    case HTTP_HEAD :
+    	    	methodObject = new HeadMethod(getURLString());
+    	    	break;
+		}
         
         // Add request headers to the method
         //
@@ -136,8 +151,8 @@
         
         try {
             methodObject.getResponseBodyAsString();
-        } catch (IOException e) {
-            throw new HTTPException("Couldn't get response body", e);
+        } catch (Throwable t) {
+            throw new HTTPException("Couldn't get response body", t);
         }
         methodObject.releaseConnection();
         




More information about the MOBY-guts mailing list