You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/08/03 19:43:27 UTC

tomee git commit: TOMEE-1621 ensuring EJBException are sent to the exception mapper chain properly

Repository: tomee
Updated Branches:
  refs/heads/master 3ea255664 -> 3acaaffe7


TOMEE-1621 ensuring EJBException are sent to the exception mapper chain properly


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

Branch: refs/heads/master
Commit: 3acaaffe70040acff34019c154b0ac7b9ba80137
Parents: 3ea2556
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Mon Aug 3 19:43:20 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Mon Aug 3 19:43:20 2015 +0200

----------------------------------------------------------------------
 .../server/cxf/rs/CxfRsHttpListener.java        |   2 +-
 .../server/cxf/rs/EJBAccessExceptionMapper.java |  30 -----
 .../server/cxf/rs/EJBExceptionMapper.java       |  38 +++++++
 .../cxf/rs/EJBAccessExceptionMapperTest.java    | 110 -------------------
 .../server/cxf/rs/EJBExceptionMapperTest.java   | 110 +++++++++++++++++++
 5 files changed, 149 insertions(+), 141 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/3acaaffe/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
index e3eaae4..4f3f21d 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
@@ -463,7 +463,7 @@ public class CxfRsHttpListener implements RsHttpListener {
 
     private static void addMandatoryProviders(final Collection<Object> instances) {
         instances.add(new WadlDocumentMessageBodyWriter());
-        instances.add(EJBAccessExceptionMapper.INSTANCE);
+        instances.add(new EJBExceptionMapper());
         instances.add(new ValidationExceptionMapper());
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/3acaaffe/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapper.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapper.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapper.java
deleted file mode 100644
index e569344..0000000
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapper.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.openejb.server.cxf.rs;
-
-import javax.ejb.EJBAccessException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-
-public class EJBAccessExceptionMapper implements ExceptionMapper<EJBAccessException> {
-    public static final EJBAccessExceptionMapper INSTANCE = new EJBAccessExceptionMapper();
-
-    @Override
-    public Response toResponse(EJBAccessException throwable) {
-        return Response.status(Response.Status.FORBIDDEN).build();
-    }
-}

http://git-wip-us.apache.org/repos/asf/tomee/blob/3acaaffe/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapper.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapper.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapper.java
new file mode 100644
index 0000000..5bf66ee
--- /dev/null
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapper.java
@@ -0,0 +1,38 @@
+/*
+ * 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.openejb.server.cxf.rs;
+
+import javax.ejb.EJBException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Providers;
+
+public class EJBExceptionMapper implements ExceptionMapper<EJBException> {
+    @Context
+    private Providers providers;
+
+    @Override
+    public Response toResponse(final EJBException ejbException) {
+        final Exception cause = ejbException.getCausedByException();
+        if (cause != null) {
+            final Class causeClass = cause.getClass();
+            return providers.getExceptionMapper(causeClass).toResponse(cause);
+        }
+        throw ejbException;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/3acaaffe/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapperTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapperTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapperTest.java
deleted file mode 100644
index dba3957..0000000
--- a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBAccessExceptionMapperTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.openejb.server.cxf.rs;
-
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.openejb.OpenEjbContainer;
-import org.apache.openejb.config.DeploymentFilterable;
-import org.apache.openejb.server.cxf.rs.beans.SimpleEJB;
-import org.apache.openejb.util.NetworkUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import javax.annotation.security.RolesAllowed;
-import javax.ejb.EJB;
-import javax.ejb.Lock;
-import javax.ejb.LockType;
-import javax.ejb.Singleton;
-import javax.ejb.embeddable.EJBContainer;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.Response;
-import java.util.Properties;
-
-import static org.junit.Assert.assertEquals;
-
-@SuppressWarnings("FieldCanBeLocal")
-public class EJBAccessExceptionMapperTest {
-    private static EJBContainer container;
-    private static RESTIsCoolOne service;
-    private static int port = -1;
-
-    @BeforeClass
-    public static void start() throws Exception {
-        port = NetworkUtil.getNextAvailablePort();
-        final Properties properties = new Properties();
-        properties.setProperty("httpejbd.port", Integer.toString(port));
-        properties.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*openejb-cxf-rs.*");
-        properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
-        container = EJBContainer.createEJBContainer(properties);
-        service = (RESTIsCoolOne) container.getContext().lookup("java:/global/openejb-cxf-rs/RESTIsCoolOne");
-    }
-
-    @AfterClass
-    public static void close() throws Exception {
-        if (container != null) {
-            container.close();
-        }
-    }
-
-
-    @Test
-    public void rest() {
-        final Response response = WebClient.create("http://localhost:" + port + "/openejb-cxf-rs").path("/ejbsecu/rest").get();
-        assertEquals(403, response.getStatus());
-    }
-
-
-    @Singleton
-    @RolesAllowed("Something that does not exit at all")
-    @Lock(LockType.READ)
-    @Path("/ejbsecu")
-    public static class RESTIsCoolOne {
-        @EJB
-        private SimpleEJB simpleEJB;
-        @javax.ws.rs.core.Context
-        Request request;
-
-        @Path("/normal")
-        @GET
-        public String normal() {
-            return simpleEJB.ok();
-        }
-
-        @Path("/rest")
-        @GET
-        public String rest() {
-            return simpleEJB.ok();
-        }
-
-        @Path("/param")
-        @GET
-        public String param(@QueryParam("arg") @DefaultValue("true") final String p) {
-            return p;
-        }
-
-        @Path("/field")
-        @GET
-        public boolean field() {
-            return "GET".equals(request.getMethod());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/tomee/blob/3acaaffe/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapperTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapperTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapperTest.java
new file mode 100644
index 0000000..75d8b0c
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/EJBExceptionMapperTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.openejb.server.cxf.rs;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.openejb.OpenEjbContainer;
+import org.apache.openejb.config.DeploymentFilterable;
+import org.apache.openejb.server.cxf.rs.beans.SimpleEJB;
+import org.apache.openejb.util.NetworkUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.annotation.security.RolesAllowed;
+import javax.ejb.EJB;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.ejb.embeddable.EJBContainer;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Request;
+import javax.ws.rs.core.Response;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+@SuppressWarnings("FieldCanBeLocal")
+public class EJBExceptionMapperTest {
+    private static EJBContainer container;
+    private static RESTIsCoolOne service;
+    private static int port = -1;
+
+    @BeforeClass
+    public static void start() throws Exception {
+        port = NetworkUtil.getNextAvailablePort();
+        final Properties properties = new Properties();
+        properties.setProperty("httpejbd.port", Integer.toString(port));
+        properties.setProperty(DeploymentFilterable.CLASSPATH_INCLUDE, ".*openejb-cxf-rs.*");
+        properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
+        container = EJBContainer.createEJBContainer(properties);
+        service = (RESTIsCoolOne) container.getContext().lookup("java:/global/openejb-cxf-rs/RESTIsCoolOne");
+    }
+
+    @AfterClass
+    public static void close() throws Exception {
+        if (container != null) {
+            container.close();
+        }
+    }
+
+
+    @Test
+    public void rest() {
+        final Response response = WebClient.create("http://localhost:" + port + "/openejb-cxf-rs").path("/ejbsecu/rest").get();
+        assertEquals(500, response.getStatus());
+    }
+
+
+    @Singleton
+    @RolesAllowed("Something that does not exit at all")
+    @Lock(LockType.READ)
+    @Path("/ejbsecu")
+    public static class RESTIsCoolOne {
+        @EJB
+        private SimpleEJB simpleEJB;
+        @javax.ws.rs.core.Context
+        Request request;
+
+        @Path("/normal")
+        @GET
+        public String normal() {
+            return simpleEJB.ok();
+        }
+
+        @Path("/rest")
+        @GET
+        public String rest() {
+            return simpleEJB.ok();
+        }
+
+        @Path("/param")
+        @GET
+        public String param(@QueryParam("arg") @DefaultValue("true") final String p) {
+            return p;
+        }
+
+        @Path("/field")
+        @GET
+        public boolean field() {
+            return "GET".equals(request.getMethod());
+        }
+    }
+}