Repository: cxf
Updated Branches:
  refs/heads/master dbd709e6e -> a515dcaaf


[CXF-6522] Updating the tl proxy code to unwrap target exceptions, patch from 
Ievgen Tarasov applied


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a515dcaa
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a515dcaa
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a515dcaa

Branch: refs/heads/master
Commit: a515dcaaf4c25974ccfe4bb625106499a2ef7f86
Parents: dbd709e
Author: Sergey Beryozkin <[email protected]>
Authored: Thu Aug 6 12:24:45 2015 +0100
Committer: Sergey Beryozkin <[email protected]>
Committed: Thu Aug 6 12:24:45 2015 +0100

----------------------------------------------------------------------
 .../impl/tl/ThreadLocalInvocationHandler.java   |   7 +-
 .../tl/ThreadLocalInvocationHandlerTest.java    | 120 +++++++++++++++++++
 2 files changed, 126 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a515dcaa/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
----------------------------------------------------------------------
diff --git 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
index 17278d3..4ee383b 100644
--- 
a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
+++ 
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandler.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.impl.tl;
 
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 
@@ -43,6 +44,10 @@ public class ThreadLocalInvocationHandler<T> extends 
AbstractThreadLocalProxy<T>
                                                    + " Check if 
ContextProvider supporting this class is registered");
             }
         }
-        return m.invoke(target, args);
+        try {
+            return m.invoke(target, args);
+        } catch (InvocationTargetException e) {
+            throw e.getCause();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a515dcaa/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
----------------------------------------------------------------------
diff --git 
a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
new file mode 100644
index 0000000..8cf176e
--- /dev/null
+++ 
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalInvocationHandlerTest.java
@@ -0,0 +1,120 @@
+/**
+ * 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.cxf.jaxrs.impl.tl;
+
+import java.lang.annotation.AnnotationFormatError;
+import java.lang.reflect.Proxy;
+import java.net.SocketException;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class ThreadLocalInvocationHandlerTest {
+
+    private static final String CHECKED_EXCEPTION_MSG = "Throwing a checked 
exception.";
+    private static final String UNCHECKED_EXCEPTION_MSG = "Throwing an 
unchecked exception.";
+    private static final String ERROR_MSG = "Throwing an error.";
+    private static final String THROWABLE_MSG = "Throwing a throwable.";
+
+    private TestIface testIface;
+
+    private ExpectedException expectedException = ExpectedException.none();
+
+    @Rule
+    public ExpectedException getExpectedExceptionRule() {
+        return expectedException;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        ThreadLocalInvocationHandler<TestClass> subject = new 
ThreadLocalInvocationHandler<>();
+        subject.set(new TestClass());
+
+        testIface = (TestIface) 
Proxy.newProxyInstance(ThreadLocalInvocationHandler.class.getClassLoader(),
+                new Class[] {TestIface.class}, subject);
+    }
+
+    @Test
+    public void testCheckedExceptionPropagation() throws Exception {
+        expectedException.expect(SocketException.class);
+        expectedException.expectMessage(CHECKED_EXCEPTION_MSG);
+
+        testIface.throwCheckedException();
+    }
+
+    @Test
+    public void testUncheckedExceptionPropagation() {
+        expectedException.expect(IndexOutOfBoundsException.class);
+        expectedException.expectMessage(UNCHECKED_EXCEPTION_MSG);
+
+        testIface.throwUncheckedException();
+    }
+
+    @Test
+    public void testErrorPropagation() {
+        expectedException.expect(AnnotationFormatError.class);
+        expectedException.expectMessage(ERROR_MSG);
+
+        testIface.throwError();
+    }
+
+    @Test
+    public void testThrowablePropagation() throws Throwable {
+        expectedException.expect(Throwable.class);
+        expectedException.expectMessage(THROWABLE_MSG);
+
+        testIface.throwThrowable();
+    }
+
+    private interface TestIface {
+        void throwCheckedException() throws Exception;
+
+        void throwUncheckedException();
+
+        void throwError();
+
+        void throwThrowable() throws Throwable;
+    }
+
+    private class TestClass implements TestIface {
+
+        @Override
+        public void throwCheckedException() throws Exception {
+            throw new SocketException(CHECKED_EXCEPTION_MSG);
+        }
+
+        @Override
+        public void throwUncheckedException() {
+            throw new IndexOutOfBoundsException(UNCHECKED_EXCEPTION_MSG);
+        }
+
+        @Override
+        public void throwError() {
+            throw new AnnotationFormatError(ERROR_MSG);
+        }
+
+        @Override
+        public void throwThrowable() throws Throwable {
+            throw new Throwable(THROWABLE_MSG);
+        }
+    }
+}

Reply via email to