incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r731082 - in /incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post: SlingPostConstants.java impl/SlingPostServlet.java impl/operations/NopOperation.java
Date Sat, 03 Jan 2009 20:29:59 GMT
Author: fmeschbe
Date: Sat Jan  3 12:29:59 2009
New Revision: 731082

URL: http://svn.apache.org/viewvc?rev=731082&view=rev
Log:
SLING-804 Implement NopOperation and register it

Added:
    incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
  (with props)
Modified:
    incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
    incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java

Modified: incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java?rev=731082&r1=731081&r2=731082&view=diff
==============================================================================
--- incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
(original)
+++ incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/SlingPostConstants.java
Sat Jan  3 12:29:59 2009
@@ -99,6 +99,17 @@
     public static final String OPERATION_MOVE = "move";
 
     /**
+     * Name of the predefined null operation (value is "nop").
+     * <p>
+     * The null operation is a pseudo operation, which has no effects
+     * whatsoever except setting the response status. The null operation may
+     * be accompanied with the {@link #RP_NOP_STATUS} parameter to indicate
+     * the actual response status to set and the {@link #RP_STATUS} parameter
+     * to indicate how to send the actual response status.
+     */
+    public static final String OPERATION_NOP = "nop";
+    
+    /**
      * Name of the request parameter used to indicate the resource to apply the
      * operation to (value is ":applyTo").
      * <p>
@@ -246,6 +257,29 @@
     public static final String STATUS_VALUE_BROWSER = "browser";
 
     /**
+     * Optional request parameter to indicate the actual response status to
+     * send back as a result of calling the #OPERATION_NOP (value is ":nopstatus").
+     * <p>
+     * This parameter is expected to be single-valued and by an integer being a
+     * valid HTTP status code. If this parameter is missing or the parameter
+     * value cannot be converted to a HTTP status code (integer in the range
+     * [100..999]), the default status code 200/OK is returned.
+     * 
+     * @see #OPERATION_NOP
+     * @see #RP_STATUS
+     */
+    public static final String RP_NOP_STATUS = RP_PREFIX + "nopstatus";
+    
+    /**
+     * The default response status sent back by a {@link #OPERATION_NOP} if the
+     * {@link #RP_NOP_STATUS} parameter is not provided or the parameter value
+     * cannot be converted into a valid response status code (value is 200).
+     * 
+     * @see #RP_NOP_STATUS
+     */
+    public static final int NOPSTATUS_VALUE_DEFAULT = 200;
+    
+    /**
      * Optional request parameter: if provided, added at the end of the computed
      * (or supplied) redirect URL
      */

Modified: incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java?rev=731082&r1=731081&r2=731082&view=diff
==============================================================================
--- incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
(original)
+++ incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/SlingPostServlet.java
Sat Jan  3 12:29:59 2009
@@ -42,6 +42,7 @@
 import org.apache.sling.servlets.post.impl.operations.DeleteOperation;
 import org.apache.sling.servlets.post.impl.operations.ModifyOperation;
 import org.apache.sling.servlets.post.impl.operations.MoveOperation;
+import org.apache.sling.servlets.post.impl.operations.NopOperation;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
@@ -50,18 +51,22 @@
 
 /**
  * POST servlet that implements the sling client library "protocol"
- *
+ * 
  * @scr.component immediate="true" label="%servlet.post.name"
  *                description="%servlet.post.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.property name="service.description" value="Sling Post Servlet"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
- *
+ * 
  * Use this as the default servlet for POST requests for Sling
  * @scr.property name="sling.servlet.resourceTypes"
  *               value="sling/servlet/default" private="true"
  * @scr.property name="sling.servlet.methods" value="POST" private="true"
- * @scr.reference name="postProcessor" interface="org.apache.sling.servlets.post.SlingPostProcessor"
cardinality="0..n" policy="dynamic"
+ * 
+ * Get all SlingPostProcessors
+ * @scr.reference name="postProcessor"
+ *                interface="org.apache.sling.servlets.post.SlingPostProcessor"
+ *                cardinality="0..n" policy="dynamic"
  */
 public class SlingPostServlet extends SlingAllMethodsServlet {
 
@@ -127,6 +132,7 @@
             new MoveOperation());
         postOperations.put(SlingPostConstants.OPERATION_DELETE,
             new DeleteOperation());
+        postOperations.put(SlingPostConstants.OPERATION_NOP, new NopOperation());
     }
 
     @Override

Added: incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java?rev=731082&view=auto
==============================================================================
--- incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
(added)
+++ incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
Sat Jan  3 12:29:59 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.sling.servlets.post.impl.operations;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.servlets.HtmlResponse;
+import org.apache.sling.servlets.post.SlingPostConstants;
+import org.apache.sling.servlets.post.SlingPostOperation;
+import org.apache.sling.servlets.post.SlingPostProcessor;
+
+/**
+ * The <code>NopOperation</code> class implements no operation at all. It just
+ * sets the response status accroding to the <i>:nopstatus</i> parameter if
+ * availables. Otherwise the status is set as 200/OK.
+ */
+public class NopOperation implements SlingPostOperation {
+
+    public void run(SlingHttpServletRequest request, HtmlResponse response,
+            SlingPostProcessor[] processors) {
+
+        // get the :nopstatus parameter for a specific code
+        int status = SlingPostConstants.NOPSTATUS_VALUE_DEFAULT;
+        String nopStatusString = request.getParameter(SlingPostConstants.RP_NOP_STATUS);
+        if (nopStatusString != null) {
+            try {
+                int nopStatusPar = Integer.parseInt(nopStatusString);
+                if (nopStatusPar >= 100 && nopStatusPar <= 999) {
+                    status = nopStatusPar;
+                }
+            } catch (NumberFormatException nfe) {
+                // illegal number, use default
+            }
+        }
+
+        response.setStatus(status, "Null Operation Status: " + status);
+    }
+
+}

Propchange: incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/NopOperation.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message