You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by th...@apache.org on 2007/01/12 00:58:05 UTC
svn commit: r495447 -
/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java
Author: thorsten
Date: Thu Jan 11 15:58:05 2007
New Revision: 495447
URL: http://svn.apache.org/viewvc?view=rev&rev=495447
Log:
adding support for input stream to the postFile and changed the constructor to the stream. This enables support for cli environment since the source can now be cocoon.// based and not like before http:// only.
We should consider to move this util methode to the forrest core.
Modified:
forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java
Modified: forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java
URL: http://svn.apache.org/viewvc/forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java?view=diff&rev=495447&r1=495446&r2=495447
==============================================================================
--- forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java (original)
+++ forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java Thu Jan 11 15:58:05 2007
@@ -23,52 +23,69 @@
private int statusCode;
/**
- * @param destinationUrl - the url of the server listener (e.g. servlet)
- * @param srcUrl - the src url of the file to post
+ * @param destinationUrl -
+ * the url of the server listener (e.g. servlet)
+ * @param srcUrl -
+ * the src url of the file to post
* @throws MalformedURLException
* @throws IOException
*/
- public PostFile(String destinationUrl, String srcUrl) throws MalformedURLException,
- IOException {
+ public PostFile(String destinationUrl, InputStream srcStream)
+ throws MalformedURLException, IOException {
this.destinationUrl = destinationUrl;
- this.srcUrl = srcUrl;
client = new HttpClient();
- filePost = prepareFilePost(destinationUrl, srcUrl);
+ filePost = prepareFilePost(destinationUrl, srcStream);
statusCode = client.executeMethod(filePost);
}
-
- public void post(String destinationUrl, String srcUrl) throws MalformedURLException, IOException{
+
+ public void post(String destinationUrl, String srcUrl)
+ throws MalformedURLException, IOException {
this.destinationUrl = destinationUrl;
this.srcUrl = srcUrl;
client = new HttpClient();
- filePost = prepareFilePost(destinationUrl, srcUrl);
+ filePost = prepareFilePost(destinationUrl, srcUrl);
statusCode = client.executeMethod(filePost);
}
- public int statusCode(){
+
+ public int statusCode() {
return statusCode;
}
- public String getResponseCharSet(){
+
+ public String getResponseCharSet() {
return filePost.getResponseCharSet();
}
- public String getResponseBodyAsString(){
+
+ public String getResponseBodyAsString() {
return filePost.getResponseBodyAsString();
}
- public InputStream getResponseBodyAsStream()
- throws MalformedURLException, IOException {
+
+ public InputStream getResponseBodyAsStream() throws MalformedURLException,
+ IOException {
return filePost.getResponseBodyAsStream();
}
- private PostMethod prepareFilePost(String solrBase, String src)
+ private PostMethod prepareFilePost(String solrBase, String srcUrl)
+ throws IOException, MalformedURLException {
+ PostMethod filePost = new PostMethod(solrBase);
+ filePost.addRequestHeader("Content-type", "text/xml; charset=utf-8");
+ filePost.addRequestHeader("User-Agent", AGENT);
+ filePost.setRequestBody(new URL(srcUrl).openStream());
+ return filePost;
+ }
+
+ private PostMethod prepareFilePost(String solrBase, InputStream src)
throws IOException, MalformedURLException {
PostMethod filePost = new PostMethod(solrBase);
filePost.addRequestHeader("Content-type", "text/xml; charset=utf-8");
filePost.addRequestHeader("User-Agent", AGENT);
- filePost.setRequestBody(new URL(src).openStream());
+ filePost.setRequestBody(src);
return filePost;
}
+
public String getsolrBase() {
return destinationUrl;
}
+
public String getSrc() {
return srcUrl;
}