[MOBY-guts] biomoby commit

Gary Schlitz gss at pub.open-bio.org
Tue Mar 30 21:54:30 UTC 2004


gss
Tue Mar 30 16:54:30 EST 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/core/org/smoby/tools/common/http
In directory pub.open-bio.org:/tmp/cvs-serv27602/org/smoby/tools/common/http

Modified Files:
	HTTPRequest.java 
Log Message:
Use NameValuePair objects rather than ParameterValue objects;
fix POST method in send()

moby-live/S-MOBY/ref-impl/core/org/smoby/tools/common/http HTTPRequest.java,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/core/org/smoby/tools/common/http/HTTPRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/core/org/smoby/tools/common/http/HTTPRequest.java	2004/03/20 00:29:15	1.2
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/core/org/smoby/tools/common/http/HTTPRequest.java	2004/03/30 21:54:30	1.3
@@ -38,7 +38,7 @@
     private int method = HTTP_GET;
 	
 	/**
-	 * A list of ParameterValue objects.
+	 * A list of NameValuePair objects.
 	 */
 	private List params = new ArrayList();
     
@@ -65,12 +65,12 @@
     
     public void addParameter(String paramName, String paramValue)
     {
-    	params.add(new ParameterValue(paramName, paramValue));
+    	params.add(new NameValuePair(paramName, paramValue));
     }
     
     public void addHeader(String headerName, String headerValue)
     {
-        headers.add(new ParameterValue(headerName, headerValue));
+        headers.add(new NameValuePair(headerName, headerValue));
     }
 	
 	/**
@@ -100,16 +100,24 @@
 		if (method == HTTP_GET) {
             methodObject = new GetMethod(getURLString());
         }
-        else if (method == HTTP_POST) {
+        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);
         }
         
         // Add request headers to the method
         //
         for (Iterator it = headers.iterator(); it.hasNext();)
         {
-        	ParameterValue pv = (ParameterValue) it.next();
-            methodObject.addRequestHeader(pv.getName(), pv.getValue());
+        	NameValuePair nvp = (NameValuePair) it.next();
+            methodObject.addRequestHeader(nvp.getName(), nvp.getValue());
         }
         
         // Try to execute the method up to three times (some errors are recoverable)
@@ -142,23 +150,27 @@
 	 */
 	private String getURLString()
 	{
-		StringBuffer sb = new StringBuffer();
-		
-		sb.append(serverURL);
         
-        Iterator it = params.iterator();
-		for (int i = 0; it.hasNext(); i++)
+		if (method == HTTP_POST) {
+			return serverURL;
+		}
+		else
 		{
-			if (i == 0) {
-				sb.append("?");
-			} else {
-				sb.append("&");
+			StringBuffer sb = new StringBuffer(serverURL);
+	        Iterator it = params.iterator();
+			for (int i = 0; it.hasNext(); i++)
+			{
+				if (i == 0) {
+					sb.append("?");
+				} else {
+					sb.append("&");
+				}
+	            NameValuePair nvp = (NameValuePair) it.next();
+				sb.append(nvp.getName());
+				sb.append("=");
+				sb.append(nvp.getValue());
 			}
-            ParameterValue pv = (ParameterValue) it.next();
-			sb.append(pv.getName());
-			sb.append("=");
-			sb.append(pv.getValue());
+			return sb.toString();
 		}
-		return sb.toString();
 	}
 }
\ No newline at end of file




More information about the MOBY-guts mailing list