incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1308838 - in /sling/trunk/bundles/servlets/post/src: main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java
Date Tue, 03 Apr 2012 12:13:04 GMT
Author: bdelacretaz
Date: Tue Apr  3 12:13:04 2012
New Revision: 1308838

URL: http://svn.apache.org/viewvc?rev=1308838&view=rev
Log:
SLING-2453 - fix NPE in constructor

Added:
    sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java
Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java?rev=1308838&r1=1308837&r2=1308838&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxy.java
Tue Apr  3 12:13:04 2012
@@ -40,9 +40,14 @@ import org.apache.sling.servlets.post.Po
 public class HtmlResponseProxy extends HtmlResponse {
 
     private final PostResponse postResponse;
+    private boolean createRequest;
 
     public HtmlResponseProxy(final PostResponse postResponse) {
+        if(postResponse == null) {
+            throw new IllegalArgumentException("Null PostResponse, cannot build HtmlResponseProxy");
+        }
         this.postResponse = postResponse;
+        postResponse.setCreateRequest(createRequest);
     }
 
     public PostResponse getPostResponse() {
@@ -129,7 +134,12 @@ public class HtmlResponseProxy extends H
     }
 
     public void setCreateRequest(boolean isCreateRequest) {
-        postResponse.setCreateRequest(isCreateRequest);
+        createRequest = isCreateRequest;
+        if(postResponse != null) {
+            // ugly...needed because of SLING-2453, this is called
+            // by the base class's constructor before postResponse is set
+            postResponse.setCreateRequest(isCreateRequest);
+        }
     }
 
     public void setError(Throwable error) {

Added: sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java?rev=1308838&view=auto
==============================================================================
--- sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java
(added)
+++ sling/trunk/bundles/servlets/post/src/test/java/org/apache/sling/servlets/post/impl/helper/HtmlResponseProxyTest.java
Tue Apr  3 12:13:04 2012
@@ -0,0 +1,116 @@
+/*
+ * 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.helper;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.servlets.post.PostResponse;
+import org.junit.Test;
+
+public class HtmlResponseProxyTest {
+    
+    @Test
+    public void testConstructor() {
+        new HtmlResponseProxy(POST_RESPONSE);
+    }
+    
+    private static final PostResponse POST_RESPONSE = new PostResponse() {
+        
+        public void setTitle(String title) {
+        }
+        
+        public void setStatus(int code, String message) {
+        }
+        
+        public void setReferer(String referer) {
+        }
+        
+        public void setPath(String path) {
+        }
+        
+        public void setParentLocation(String parentLocation) {
+        }
+        
+        public void setLocation(String location) {
+        }
+        
+        public void setError(Throwable error) {
+        }
+        
+        public void setCreateRequest(boolean isCreateRequest) {
+        }
+        
+        public void send(HttpServletResponse response, boolean setStatus) throws IOException
{
+        }
+        
+        public void onMoved(String srcPath, String dstPath) {
+        }
+        
+        public void onModified(String path) {
+        }
+        
+        public void onDeleted(String path) {
+        }
+        
+        public void onCreated(String path) {
+        }
+        
+        public void onCopied(String srcPath, String dstPath) {
+        }
+        
+        public void onChange(String type, String... arguments) {
+        }
+        
+        public boolean isSuccessful() {
+            return false;
+        }
+        
+        public boolean isCreateRequest() {
+            return false;
+        }
+        
+        public String getStatusMessage() {
+            return null;
+        }
+        
+        public int getStatusCode() {
+            return 0;
+        }
+        
+        public String getReferer() {
+            return null;
+        }
+        
+        public String getPath() {
+            return null;
+        }
+        
+        public String getParentLocation() {
+            return null;
+        }
+        
+        public String getLocation() {
+            return null;
+        }
+        
+        public Throwable getError() {
+            return null;
+        }
+    };
+}



Mime
View raw message