chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1537202 - in /chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/ chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apac...
Date Wed, 30 Oct 2013 17:49:52 GMT
Author: fmui
Date: Wed Oct 30 17:49:51 2013
New Revision: 1537202

URL: http://svn.apache.org/r1537202
Log:
CMIS-733: Server: added content redirection

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java?rev=1537202&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java
Wed Oct 30 17:49:51 2013
@@ -0,0 +1,44 @@
+/*
+ * 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.chemistry.opencmis.commons.data;
+
+/**
+ * Content stream redirecting to another location. (AtomPub binding and Browser
+ * binding server only.)
+ */
+public interface RedirectingContentStream {
+
+    /**
+     * Returns the HTTP status code, for example 301 (moved permanently) or 307
+     * (temporary redirect).
+     * 
+     * @return the HTTP status code
+     */
+    int getStatus();
+
+    /**
+     * Returns the location to redirect to.
+     * 
+     * This should be an absolute URL, although many clients can also handle a
+     * relative path.
+     * 
+     * @return the location to redirect to
+     */
+    String getLocation();
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/data/RedirectingContentStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java?rev=1537202&r1=1537201&r2=1537202&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/AbstractServiceCall.java
Wed Oct 30 17:49:51 2013
@@ -30,6 +30,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.ContentLengthContentStream;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.LastModifiedContentStream;
+import org.apache.chemistry.opencmis.commons.data.RedirectingContentStream;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.impl.CmisEnumHelper;
 import org.apache.chemistry.opencmis.commons.impl.DateTimeHelper;
@@ -113,9 +114,9 @@ public abstract class AbstractServiceCal
     /**
      * Sets certain HTTP headers if the server implementation requested them.
      * 
-     * @return <code>true</code> if the request has been served by this method
-     *         (e.g. status code 304 was send), <code>false</code> if the
-     *         content should be served.
+     * @return {@code true} if the request has been served by this method (for
+     *         example status code 304 was send), {@code false} if the content
+     *         should be served.
      */
     public boolean sendContentStreamHeaders(ContentStream content, HttpServletRequest request,
             HttpServletResponse response) throws IOException {
@@ -147,6 +148,28 @@ public abstract class AbstractServiceCal
             }
         }
 
+        // check if redirection is needed
+        if (content instanceof RedirectingContentStream) {
+            RedirectingContentStream rcs = (RedirectingContentStream) content;
+            // close stream
+            if (content.getStream() != null) {
+                content.getStream().close();
+            }
+
+            if (rcs.getLocation() != null) {
+                response.setHeader("Location", rcs.getLocation());
+            }
+
+            int status = rcs.getStatus();
+            if (status < 300 || status >= 400) {
+                status = HttpServletResponse.SC_TEMPORARY_REDIRECT;
+            }
+
+            response.setStatus(status);
+
+            return true;
+        }
+
         // check if cache headers should be set
         if (content instanceof CacheHeaderContentStream) {
             CacheHeaderContentStream chcs = (CacheHeaderContentStream) content;



Mime
View raw message