Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 41534 invoked from network); 29 Sep 2006 14:46:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Sep 2006 14:46:58 -0000 Received: (qmail 40172 invoked by uid 500); 29 Sep 2006 14:46:58 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 40086 invoked by uid 500); 29 Sep 2006 14:46:58 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 40048 invoked by uid 99); 29 Sep 2006 14:46:58 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 29 Sep 2006 07:46:58 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:57210] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 54/75-13110-1E13D154 for ; Fri, 29 Sep 2006 07:46:57 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 131E11A984D; Fri, 29 Sep 2006 07:46:55 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r451315 - in /jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods: DavMethodBase.java XmlRequestEntity.java Date: Fri, 29 Sep 2006 14:46:54 -0000 To: commits@jackrabbit.apache.org From: angela@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060929144655.131E11A984D@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: angela Date: Fri Sep 29 07:46:54 2006 New Revision: 451315 URL: http://svn.apache.org/viewvc?view=rev&rev=451315 Log: DavMethodBase: - separate RequestEntity impl. for xml documents - missing close on response stream - preprocessing the multistatus caused getResponseDocument to return null. Added: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java (with props) Modified: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java Modified: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java?view=diff&rev=451315&r1=451314&r2=451315 ============================================================================== --- jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java (original) +++ jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/DavMethodBase.java Fri Sep 29 07:46:54 2006 @@ -18,7 +18,6 @@ import org.apache.commons.httpclient.methods.EntityEnclosingMethod; import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.HttpConnection; import org.apache.commons.httpclient.HttpMethodBase; @@ -30,8 +29,6 @@ import org.apache.jackrabbit.webdav.header.Header; import org.apache.jackrabbit.webdav.xml.XmlSerializable; import org.apache.jackrabbit.webdav.xml.DomUtil; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -41,7 +38,6 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -55,6 +51,7 @@ static final DocumentBuilderFactory BUILDER_FACTORY = DomUtil.BUILDER_FACTORY; private boolean success; + private Document responseDocument; private MultiStatus multiStatus; public DavMethodBase(String uri) { @@ -107,19 +104,27 @@ * @see DavMethod#getResponseBodyAsDocument() */ public Document getResponseBodyAsDocument() throws IOException { - InputStream in = getResponseBodyAsStream(); - if (in == null) { - return null; - } - try { - DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder(); - Document document = docBuilder.parse(in); - return document; - } catch (ParserConfigurationException e) { - throw new IOException(e.getMessage()); - } catch (SAXException e) { - throw new IOException(e.getMessage()); - } + if (responseDocument != null) { + // response has already been read + return responseDocument; + } else { + // read response and try to build a xml document + InputStream in = getResponseBodyAsStream(); + if (in == null) { + return null; + } + try { + DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder(); + responseDocument = docBuilder.parse(in); + return responseDocument; + } catch (ParserConfigurationException e) { + throw new IOException(e.getMessage()); + } catch (SAXException e) { + throw new IOException(e.getMessage()); + } finally { + in.close(); + } + } } /** @@ -179,12 +184,7 @@ * @throws IOException */ public void setRequestBody(Document requestBody) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - OutputFormat format = new OutputFormat("xml", "UTF-8", false); - XMLSerializer serializer = new XMLSerializer(out, format); - serializer.setNamespaces(true); - serializer.asDOMSerializer().serialize(requestBody); - setRequestEntity(new StringRequestEntity(out.toString(), "text/xml", "UTF-8")); + setRequestEntity(new XmlRequestEntity(requestBody)); } /** Added: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java?view=auto&rev=451315 ============================================================================== --- jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java (added) +++ jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java Fri Sep 29 07:46:54 2006 @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.webdav.client.methods; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.commons.httpclient.methods.RequestEntity; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.xml.serialize.OutputFormat; +import org.apache.xml.serialize.XMLSerializer; +import org.w3c.dom.Document; + +import java.io.OutputStream; +import java.io.IOException; +import java.io.ByteArrayOutputStream; + +/** + * XmlRequestEntity... + */ +public class XmlRequestEntity implements RequestEntity { + + private static Logger log = LoggerFactory.getLogger(XmlRequestEntity.class); + + private final RequestEntity delegatee; + + public XmlRequestEntity(Document xmlDocument) throws IOException { + super(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + OutputFormat format = new OutputFormat("xml", "UTF-8", false); + XMLSerializer serializer = new XMLSerializer(out, format); + serializer.setNamespaces(true); + serializer.asDOMSerializer().serialize(xmlDocument); + delegatee = new StringRequestEntity(out.toString(), "text/xml", "UTF-8"); + } + + public boolean isRepeatable() { + return delegatee.isRepeatable(); + } + + public String getContentType() { + return delegatee.getContentType(); + } + + public void writeRequest(OutputStream out) throws IOException { + delegatee.writeRequest(out); + } + + public long getContentLength() { + return delegatee.getContentLength(); + } +} \ No newline at end of file Propchange: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods/XmlRequestEntity.java ------------------------------------------------------------------------------ svn:keywords = author date id revision url