You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/09/29 16:46:54 UTC
svn commit: r451315 - in
/jackrabbit/trunk/jcr-server/client/src/java/org/apache/jackrabbit/webdav/client/methods:
DavMethodBase.java XmlRequestEntity.java
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;
+
+/**
+ * <code>XmlRequestEntity</code>...
+ */
+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