- Timestamp:
- Dec 7, 2010, 11:07:13 AM (13 years ago)
- Location:
- branches/gregorys
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gregorys/build.xml
r3754 r4061 91 91 classpathref="classpath" 92 92 debug="true" 93 deprecation="true"> 93 deprecation="true" 94 includeantruntime="false"> 94 95 <compilerarg value="-Xlint:unchecked" /> 95 96 </javac> -
branches/gregorys/src/pse/shared/Client.java
r3758 r4061 1 1 /* 2 Copyright (C) 2010 Gregory Vincic3 License: http://www.gnu.org/licenses/gpl-3.0.txt2 Copyright (C) 2010 Gregory Vincic 3 License: http://www.gnu.org/licenses/gpl-3.0.txt 4 4 */ 5 5 package pse.shared; 6 6 7 import java.io.*; 7 8 import org.apache.commons.httpclient.*; 8 9 import org.apache.commons.httpclient.methods.*; 9 10 import org.apache.commons.httpclient.methods.multipart.*; 10 import java.io.*;11 11 12 12 /** 13 Wrapper for apaches HttpClient.13 Wrapper for apaches HttpClient. 14 14 */ 15 15 public class Client 16 16 { 17 18 /**19 Sends a multipart POST request to the given url with the given parts as parameters.20 @param url to send the request to21 @param parts parameters to send22 */23 public InputStream post(String url, Parts parts) throws IOException24 {25 PostMethod postMethod;26 27 MultipartRequestEntity entity;28 Integer statusCode;29 InputStream in;30 31 httpClient = new HttpClient();32 postMethod = new PostMethod(url);33 entity = new MultipartRequestEntity(parts.toArray(), postMethod.getParams());34 35 postMethod.setRequestEntity(entity);36 statusCode = httpClient.executeMethod(postMethod);37 return postMethod.getResponseBodyAsStream();38 }17 18 /** 19 Sends a multipart POST request to the given url with the given parts as parameters. 20 @param url to send the request to 21 @param parts parameters to send 22 */ 23 public InputStream post(String url, Parts parts) throws IOException 24 { 25 PostMethod postMethod; 26 HttpClient httpClient; 27 MultipartRequestEntity entity; 28 Integer statusCode; 29 InputStream in; 30 31 httpClient = new HttpClient(); 32 postMethod = new PostMethod(url); 33 entity = new MultipartRequestEntity(parts.toArray(), postMethod.getParams()); 34 35 postMethod.setRequestEntity(entity); 36 statusCode = httpClient.executeMethod(postMethod); 37 return postMethod.getResponseBodyAsStream(); 38 } 39 39 } -
branches/gregorys/src/pse/shared/Parts.java
r3758 r4061 1 1 /* 2 Copyright (C) 2010 Gregory Vincic3 License: http://www.gnu.org/licenses/gpl-3.0.txt2 Copyright (C) 2010 Gregory Vincic 3 License: http://www.gnu.org/licenses/gpl-3.0.txt 4 4 */ 5 5 package pse.shared; … … 7 7 import java.io.File; 8 8 import java.io.IOException; 9 import java.net.URI; 10 import java.util.ArrayList; 9 11 import java.util.List; 10 import java.util.ArrayList; 11 import java.net.URI; 12 import org.apache.commons.httpclient.*; 12 13 import org.apache.commons.httpclient.methods.multipart.*; 13 import org.apache.commons.httpclient.*;14 14 15 15 /** 16 Parts are parameters send with the httpclient.16 Parts are parameters send with the httpclient. 17 17 */ 18 18 public class Parts extends ArrayList<Part> 19 19 { 20 public Parts(int size) 21 { 22 super(size); 23 } 24 25 26 public void add(String name, String value) 27 { 28 Part part; 29 part = new StringPart(name, value); 30 this.add(part); 31 } 32 33 34 public void add(String name, List<String> value) 35 { 36 Part part; 37 for(String v : value) 38 { 39 part = new StringPart(name, v); 40 this.add(part); 41 } 42 } 43 44 45 public void add(String name, URI uri) throws IOException 46 { 47 File file; 48 FilePartSource source; 49 FilePart part; 50 51 file = new File(uri); 52 source = new FilePartSource(file); 53 part = new FilePart(name, source); 54 this.add(part); 55 } 56 57 58 public Part[] toArray() 59 { 60 Part[] list; 61 list = new Part[this.size()]; 62 for(int i = 0; i < this.size(); i++) 63 { 64 list[i] = this.get(i); 65 } 66 return list; 67 } 20 public Parts(int size) 21 { 22 super(size); 23 } 24 25 public void add(String name, String value) 26 { 27 Part part; 28 part = new StringPart(name, value); 29 this.add(part); 30 } 31 32 public void add(String name, List<String> value) 33 { 34 Part part; 35 for(String v : value) 36 { 37 part = new StringPart(name, v); 38 this.add(part); 39 } 40 } 41 42 public void add(String name, URI uri) throws IOException 43 { 44 File file; 45 FilePartSource source; 46 FilePart part; 47 48 file = new File(uri); 49 source = new FilePartSource(file); 50 part = new FilePart(name, source); 51 this.add(part); 52 } 53 54 public Part[] toArray() 55 { 56 Part[] list; 57 list = new Part[this.size()]; 58 for(int i = 0; i < this.size(); i++) 59 { 60 list[i] = this.get(i); 61 } 62 return list; 63 } 68 64 }
Note: See TracChangeset
for help on using the changeset viewer.