From svn-return-6463-apmail-forrest-svn-archive=forrest.apache.org@forrest.apache.org Thu Jan 11 23:59:09 2007 Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 18964 invoked from network); 11 Jan 2007 23:59:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jan 2007 23:59:07 -0000 Received: (qmail 77002 invoked by uid 500); 11 Jan 2007 23:59:14 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 76970 invoked by uid 500); 11 Jan 2007 23:59:14 -0000 Mailing-List: contact svn-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Forrest Developers List" List-Id: Delivered-To: mailing list svn@forrest.apache.org Received: (qmail 76955 invoked by uid 99); 11 Jan 2007 23:59:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jan 2007 15:59:14 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Jan 2007 15:59:06 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id CEF941A981A; Thu, 11 Jan 2007 15:58:05 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r495447 - /forrest/trunk/whiteboard/plugins/org.apache.forrest.plugin.output.solr/src/java/org/apache/forrest/http/client/PostFile.java Date: Thu, 11 Jan 2007 23:58:05 -0000 To: svn@forrest.apache.org From: thorsten@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070111235805.CEF941A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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; }