Author: bdelacretaz
Date: Wed Aug 5 11:16:03 2015
New Revision: 1694179
URL: http://svn.apache.org/r1694179
Log:
SLING-4921 - use ClientAbortException to differentiate client/network problems
from other IOEXception
Added:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/ClientAbortException.java
sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/log/ClientAbortExceptionTest.java
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerResponse.java
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=1694179&r1=1694178&r2=1694179&view=diff
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Wed Aug 5 11:16:03 2015
@@ -18,7 +18,6 @@
*/
package org.apache.sling.engine.impl;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
@@ -53,6 +52,7 @@ import org.apache.sling.commons.mime.Mim
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.engine.SlingRequestProcessor;
import org.apache.sling.engine.impl.filter.ServletFilterManager;
+import org.apache.sling.engine.impl.helper.ClientAbortException;
import org.apache.sling.engine.impl.helper.RequestListenerManager;
import org.apache.sling.engine.impl.helper.SlingServletContext;
import org.apache.sling.engine.impl.request.RequestData;
@@ -216,13 +216,8 @@ public class SlingMainServlet extends Ge
requestProcessor.doProcessRequest(request,
(HttpServletResponse) res,
resolver);
- } catch (IOException ioe) {
-
- // SLING-3498: Jetty with NIO does not have a wrapped
- // SocketException any longer but a plain IOException
- // from the NIO Socket channel. Hence we don't care for
- // unwrapping and just log at DEBUG level
- log.debug("service: Probably client aborted request or any
other network problem", ioe);
+ } catch (ClientAbortException cae) {
+ log.debug("service: ClientAbortException, probable cause is
client aborted request or network problem", cae);
} catch (Throwable t) {
Added:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/ClientAbortException.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/ClientAbortException.java?rev=1694179&view=auto
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/ClientAbortException.java
(added)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/ClientAbortException.java
Wed Aug 5 11:16:03 2015
@@ -0,0 +1,33 @@
+/*
+ * 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.engine.impl.helper;
+
+import java.io.IOException;
+
+/** Wrap an IOException to signal that its cause is most
+ * certainly a client abort/disconnect. Similar to
+ * what Tomcat does with its ClientAbortException
+ */
+public class ClientAbortException extends IOException {
+ private static final long serialVersionUID = -7269258822867058291L;
+
+ public ClientAbortException(IOException cause) {
+ super(cause);
+ }
+}
Modified:
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerResponse.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerResponse.java?rev=1694179&r1=1694178&r2=1694179&view=diff
==============================================================================
---
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerResponse.java
(original)
+++
sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/log/RequestLoggerResponse.java
Wed Aug 5 11:16:03 2015
@@ -35,6 +35,8 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
+import org.apache.sling.engine.impl.helper.ClientAbortException;
+
class RequestLoggerResponse extends HttpServletResponseWrapper {
// the content type header name
@@ -370,30 +372,50 @@ class RequestLoggerResponse extends Http
@Override
public void write(int b) throws IOException {
- this.delegatee.write(b);
- this.count++;
+ try {
+ this.delegatee.write(b);
+ this.count++;
+ } catch(IOException ioe) {
+ throw new ClientAbortException(ioe);
+ }
}
@Override
public void write(byte[] b) throws IOException {
- this.delegatee.write(b);
- this.count += b.length;
+ try {
+ this.delegatee.write(b);
+ this.count += b.length;
+ } catch(IOException ioe) {
+ throw new ClientAbortException(ioe);
+ }
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
- this.delegatee.write(b, off, len);
- this.count += len;
+ try {
+ this.delegatee.write(b, off, len);
+ this.count += len;
+ } catch(IOException ioe) {
+ throw new ClientAbortException(ioe);
+ }
}
@Override
public void flush() throws IOException {
- this.delegatee.flush();
+ try {
+ this.delegatee.flush();
+ } catch(IOException ioe) {
+ throw new ClientAbortException(ioe);
+ }
}
@Override
public void close() throws IOException {
- this.delegatee.close();
+ try {
+ this.delegatee.close();
+ } catch(IOException ioe) {
+ throw new ClientAbortException(ioe);
+ }
}
}
Added:
sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/log/ClientAbortExceptionTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/log/ClientAbortExceptionTest.java?rev=1694179&view=auto
==============================================================================
---
sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/log/ClientAbortExceptionTest.java
(added)
+++
sling/trunk/bundles/engine/src/test/java/org/apache/sling/engine/impl/log/ClientAbortExceptionTest.java
Wed Aug 5 11:16:03 2015
@@ -0,0 +1,97 @@
+/*
+ * 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.engine.impl.log;
+
+import java.io.IOException;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.engine.impl.helper.ClientAbortException;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Verify that RequestLoggerResponse wraps IOException in
ClientAbortException */
+@RunWith(JMock.class)
+public class ClientAbortExceptionTest {
+
+ private Mockery context;
+ private RequestLoggerResponse r;
+
+ @Before
+ public void setup() throws IOException {
+ context = new JUnit4Mockery() {{
+ setImposteriser(ClassImposteriser.INSTANCE);
+ }};
+
+ final ServletOutputStream sos = new ServletOutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ throw new IOException("Always fails, on purpose");
+ }
+
+ @Override
+ public void flush() throws IOException {
+ throw new IOException("Always fails, on purpose");
+ }
+
+ @Override
+ public void close() throws IOException {
+ throw new IOException("Always fails, on purpose");
+ }
+ };
+ final HttpServletResponse raw =
context.mock(HttpServletResponse.class);
+ context.checking(new Expectations() {{
+ allowing(raw).getOutputStream();
+ will(returnValue(sos));
+ }});
+
+ r = new RequestLoggerResponse(raw);
+ }
+
+ @Test(expected=ClientAbortException.class)
+ public void writeInt() throws IOException {
+ r.getOutputStream().write(42);
+ }
+
+ @Test(expected=ClientAbortException.class)
+ public void writeSimpleByteArray() throws IOException {
+ r.getOutputStream().write("foo".getBytes());
+ }
+
+ @Test(expected=ClientAbortException.class)
+ public void writeByteArray() throws IOException {
+ final byte [] data = "bar".getBytes();
+ r.getOutputStream().write(data, 0, data.length);
+ }
+
+ @Test(expected=ClientAbortException.class)
+ public void flush() throws IOException {
+ r.getOutputStream().flush();
+ }
+
+ @Test(expected=ClientAbortException.class)
+ public void close() throws IOException {
+ r.getOutputStream().close();
+ }
+}