tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1184878 - in /openejb/trunk/openejb: assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/ examples/webapps/rest-example/ examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/ examples/webapps/rest-example...
Date Sun, 16 Oct 2011 17:39:05 GMT
Author: rmannibucau
Date: Sun Oct 16 17:39:05 2011
New Revision: 1184878

URL: http://svn.apache.org/viewvc?rev=1184878&view=rev
Log:
using EJBContainers for rest-example

Modified:
    openejb/trunk/openejb/assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/EmbeddedTomEEContainer.java
    openejb/trunk/openejb/examples/webapps/rest-example/pom.xml
    openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
    openejb/trunk/openejb/examples/webapps/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java

Modified: openejb/trunk/openejb/assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/EmbeddedTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/EmbeddedTomEEContainer.java?rev=1184878&r1=1184877&r2=1184878&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/EmbeddedTomEEContainer.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/EmbeddedTomEEContainer.java
Sun Oct 16 17:39:05 2011
@@ -12,6 +12,8 @@ import javax.naming.Context;
 import javax.validation.ValidationException;
 import java.io.File;
 import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -20,6 +22,7 @@ import java.util.Map;
 public class EmbeddedTomEEContainer extends EJBContainer {
     public static final String TOMEE_EJBCONTAINER_HTTP_PORT = "tomee.ejbcontainer.http.port";
     private static EmbeddedTomEEContainer tomEEContainer;
+    private static final List<String> CONTAINER_NAMES = Arrays.asList(EmbeddedTomEEContainer.class.getName(),
"tomee-embedded", "embedded-tomee");
 
     private Container container = new Container();
     private String appId;
@@ -55,7 +58,8 @@ public class EmbeddedTomEEContainer exte
             }
 
             if ((provider == null && ejbContainerProviders > 1)
-                    || (!provider.equals(EmbeddedTomEEContainer.class) && !provider.equals(EmbeddedTomEEContainer.class.getName())))
{
+                    || (!provider.equals(EmbeddedTomEEContainer.class)
+                            && !CONTAINER_NAMES.contains(provider))) {
                 return null;
             }
 

Modified: openejb/trunk/openejb/examples/webapps/rest-example/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webapps/rest-example/pom.xml?rev=1184878&r1=1184877&r2=1184878&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/webapps/rest-example/pom.xml (original)
+++ openejb/trunk/openejb/examples/webapps/rest-example/pom.xml Sun Oct 16 17:39:05 2011
@@ -139,6 +139,18 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-cxf-rs</artifactId>
+      <version>${openejb.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>tomee-webservices</artifactId>
+      <version>${openejb.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>2.0.1</version>

Modified: openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java?rev=1184878&r1=1184877&r2=1184878&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
(original)
+++ openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/service/UserService.java
Sun Oct 16 17:39:05 2011
@@ -51,7 +51,7 @@ public class UserService {
         return dao.list(first, max);
     }
 
-    @Path("/show") @GET public User show(@PathParam("id") long id) {
+    @Path("/show/{id}") @GET public User show(@PathParam("id") long id) {
         return dao.find(id);
     }
 

Modified: openejb/trunk/openejb/examples/webapps/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/webapps/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java?rev=1184878&r1=1184877&r2=1184878&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/webapps/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java
(original)
+++ openejb/trunk/openejb/examples/webapps/rest-example/src/test/java/org/superbiz/rest/dao/UserServiceTest.java
Sun Oct 16 17:39:05 2011
@@ -1,7 +1,7 @@
 package org.superbiz.rest.dao;
 
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.tomee.embedded.EmbeddedTomEEContainer;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -10,10 +10,15 @@ import org.superbiz.rest.model.User;
 
 import javax.ejb.embeddable.EJBContainer;
 import javax.naming.NamingException;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
 import java.io.File;
 import java.io.IOException;
 import java.util.Properties;
 
+import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertNotNull;
 
 /**
@@ -27,7 +32,7 @@ public class UserServiceTest {
         webApp = createWebApp();
         Properties p = new Properties();
         p.setProperty(EJBContainer.APP_NAME, "test");
-        p.setProperty(EJBContainer.PROVIDER, EmbeddedTomEEContainer.class.getName()); //
need web feature
+        p.setProperty(EJBContainer.PROVIDER, "tomee-embedded"); // need web feature
         p.setProperty(EJBContainer.MODULES, webApp.getAbsolutePath());
         p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1"); // random
port
         container = EJBContainer.createEJBContainer(p);
@@ -38,8 +43,10 @@ public class UserServiceTest {
             container.close();
         }
         if (webApp != null) {
-            if (!webApp.delete()) {
-                webApp.deleteOnExit();
+            try {
+                FileUtils.forceDelete(webApp);
+            } catch (IOException e) {
+                FileUtils.deleteQuietly(webApp);
             }
         }
     }
@@ -48,6 +55,14 @@ public class UserServiceTest {
         UserDAO dao = (UserDAO) container.getContext().lookup("java:global/" + webApp.getName()
+ "/UserDAO");
         User user = dao.create("foo", "dummy", "foo@dummy.org");
         assertNotNull(dao.find(user.getId()));
+
+        String uri = "http://127.0.0.1:" + System.getProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT)
+ "/" + webApp.getName();
+        UserServiceClientAPI client = JAXRSClientFactory.create(uri, UserServiceClientAPI.class);
+        User retrievedUser = client.show(user.getId());
+        assertNotNull(retrievedUser);
+        assertEquals("foo", retrievedUser.getFullname());
+        assertEquals("dummy", retrievedUser.getPassword());
+        assertEquals("foo@dummy.org", retrievedUser.getEmail());
     }
 
     private static File createWebApp() throws IOException {
@@ -56,8 +71,19 @@ public class UserServiceTest {
             throw new RuntimeException("can't create " + file.getAbsolutePath());
         }
 
-        FileUtils.copyDirectory(new File("target/classes"), new File(file, "WEB-INF/classes"),
TrueFileFilter.INSTANCE);
+        FileUtils.copyDirectory(new File("target/classes"), new File(file, "WEB-INF/classes"));
 
         return file;
     }
+
+    /**
+       * a simple copy of the unique method i want to use from my service.
+       * It allows to use cxf proxy to call remotely our rest service.
+       * Any other way to do it is good.
+       */
+    @Path("/api/user")
+    @Produces({ "text/xml", "application/json" })
+    public static interface UserServiceClientAPI {
+        @Path("/show/{id}") @GET User show(@PathParam("id") long id);
+    }
 }



Mime
View raw message