Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F06E18C50 for ; Thu, 6 Aug 2015 11:25:02 +0000 (UTC) Received: (qmail 50174 invoked by uid 500); 6 Aug 2015 11:25:02 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 50108 invoked by uid 500); 6 Aug 2015 11:25:02 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 50099 invoked by uid 99); 6 Aug 2015 11:25:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Aug 2015 11:25:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 61378E03EC; Thu, 6 Aug 2015 11:25:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergeyb@apache.org To: commits@cxf.apache.org Message-Id: <65729f49ac2e44f398969b609ad09fc1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: cxf git commit: [CXF-6522] Updating the tl proxy code to unwrap target exceptions, patch from Ievgen Tarasov applied Date: Thu, 6 Aug 2015 11:25:02 +0000 (UTC) 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 Authored: Thu Aug 6 12:24:45 2015 +0100 Committer: Sergey Beryozkin 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 extends AbstractThreadLocalProxy + " 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 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); + } + } +}