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 2012/06/05 20:38:36 UTC

svn commit: r1346518 - in /openejb/trunk/openejb/examples: ./ deltaspike-exception-handling/ deltaspike-exception-handling/src/ deltaspike-exception-handling/src/main/ deltaspike-exception-handling/src/main/java/ deltaspike-exception-handling/src/main/...

Author: rmannibucau
Date: Tue Jun  5 18:38:35 2012
New Revision: 1346518

URL: http://svn.apache.org/viewvc?rev=1346518&view=rev
Log:
adding deltaspike-exception-handling example

Added:
    openejb/trunk/openejb/examples/deltaspike-exception-handling/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/pom.xml
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSExceptionHandler.java
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSRuntimeException.java
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSValidator.java
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/resources/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/resources/META-INF/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/resources/META-INF/beans.xml
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/
    openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/ExceptionHandlingDemoTest.java
Modified:
    openejb/trunk/openejb/examples/pom.xml

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/pom.xml?rev=1346518&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/deltaspike-exception-handling/pom.xml (added)
+++ openejb/trunk/openejb/examples/deltaspike-exception-handling/pom.xml Tue Jun  5 18:38:35 2012
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>deltaspike-exception-handling</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: DeltaSpike Exception Handling</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.4</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-3</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.deltaspike.core</groupId>
+      <artifactId>deltaspike-core-impl</artifactId>
+      <version>0.2-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.deltaspike.core</groupId>
+      <artifactId>deltaspike-core-api</artifactId>
+      <version>0.2-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.10</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- The <scope>test</scope> guarantees that none of your runtime code
+      is dependent on any OpenEJB classes. -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>arquillian-openejb-embedded-4</artifactId>
+      <version>4.1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>ziplock</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- This section allows you to configure where to publish libraries for
+    sharing. It is not required and may be deleted. For more information see:
+    http://maven.apache.org/plugins/maven-deploy-plugin/ -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+</project>

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSExceptionHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSExceptionHandler.java?rev=1346518&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSExceptionHandler.java (added)
+++ openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSExceptionHandler.java Tue Jun  5 18:38:35 2012
@@ -0,0 +1,16 @@
+package org.superbiz.deltaspike.exceptionhandling;
+
+import java.util.logging.Logger;
+import org.apache.deltaspike.core.api.exception.control.annotation.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.annotation.Handles;
+import org.apache.deltaspike.core.api.exception.control.event.ExceptionEvent;
+
+@ExceptionHandler
+public class OSExceptionHandler {
+    private static final Logger LOGGER = Logger.getLogger(OSExceptionHandler.class.getName());
+
+    public void printExceptions(@Handles final ExceptionEvent<OSRuntimeException> evt) {
+        LOGGER.severe("==> a bad OS was mentionned");
+        evt.handled();
+    }
+}

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSRuntimeException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSRuntimeException.java?rev=1346518&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSRuntimeException.java (added)
+++ openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSRuntimeException.java Tue Jun  5 18:38:35 2012
@@ -0,0 +1,4 @@
+package org.superbiz.deltaspike.exceptionhandling;
+
+public class OSRuntimeException extends RuntimeException {
+}

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSValidator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSValidator.java?rev=1346518&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSValidator.java (added)
+++ openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/java/org/superbiz/deltaspike/exceptionhandling/OSValidator.java Tue Jun  5 18:38:35 2012
@@ -0,0 +1,17 @@
+package org.superbiz.deltaspike.exceptionhandling;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent;
+
+public class OSValidator {
+    @Inject
+    private Event<ExceptionToCatchEvent> exceptionEvent;
+
+    public void validOS(final String os) {
+        if (os.toLowerCase().contains("win")) {
+            final Exception ex = new OSRuntimeException(); // can be a caugh exceptino
+            exceptionEvent.fire(new ExceptionToCatchEvent(ex));
+        }
+    }
+}

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/src/main/resources/META-INF/beans.xml?rev=1346518&view=auto
==============================================================================
    (empty)

Added: openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/ExceptionHandlingDemoTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/ExceptionHandlingDemoTest.java?rev=1346518&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/ExceptionHandlingDemoTest.java (added)
+++ openejb/trunk/openejb/examples/deltaspike-exception-handling/src/test/java/org/superbiz/deltaspike/exceptionhandling/ExceptionHandlingDemoTest.java Tue Jun  5 18:38:35 2012
@@ -0,0 +1,40 @@
+package org.superbiz.deltaspike.exceptionhandling;
+
+import javax.inject.Inject;
+import org.apache.deltaspike.core.impl.config.DefaultConfigSourceProvider;
+import org.apache.deltaspike.core.spi.config.ConfigSourceProvider;
+import org.apache.ziplock.JarLocation;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class ExceptionHandlingDemoTest {
+    @Inject
+    private OSValidator validator;
+
+    @Deployment
+    public static WebArchive jar() {
+        return ShrinkWrap.create(WebArchive.class)
+                .addPackage(OSValidator.class.getPackage())
+                .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
+                // DeltaSpike libs (api and impl)
+                .addAsLibraries(JarLocation.jarLocation(ConfigSourceProvider.class))
+                .addAsLibraries(JarLocation.jarLocation(DefaultConfigSourceProvider.class));
+    }
+
+    @Test
+    public void check() {
+        assertNotNull(validator);
+        validator.validOS("Linux");
+        validator.validOS("windows"); // should throw a handled exception
+        validator.validOS("Mac OS");
+    }
+}

Modified: openejb/trunk/openejb/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1346518&r1=1346517&r2=1346518&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Tue Jun  5 18:38:35 2012
@@ -52,6 +52,7 @@
     <module>datasource-definition</module>
     <module>decorators</module>
     <module>deltaspike-configproperty</module>
+    <module>deltaspike-exception-handling</module>
     <module>deltaspike-i18n</module>
     <module>dynamic-dao-implementation</module>
     <module>dynamic-datasource-routing</module>