dev@grizzly.java.net

One by one .....

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 03 Dec 2008 17:56:55 -0500

:-)

-------- Original Message --------
Subject: svn commit: r1786 - trunk/jersey/contribs/spring: .
src/test/java/com/sun/jersey/spring
Date: Wed, 03 Dec 2008 09:38:30 +0000
From: bsnaresh_at_dev.java.net
Reply-To: commits_at_jersey.dev.java.net
To: commits_at_jersey.dev.java.net

Author: bsnaresh
Date: 2008-12-03 09:38:27+0000
New Revision: 1786

Modified:
    trunk/jersey/contribs/spring/pom.xml
 
trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java

Log:
Replaced the Jetty container with embedded Grizzly

Modified: trunk/jersey/contribs/spring/pom.xml
Url:
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/contribs/spring/pom.xml?view=diff&rev=1786&p1=trunk/jersey/contribs/spring/pom.xml&p2=trunk/jersey/contribs/spring/pom.xml&r1=1785&r2=1786
==============================================================================
--- trunk/jersey/contribs/spring/pom.xml (original)
+++ trunk/jersey/contribs/spring/pom.xml 2008-12-03 09:38:27+0000
@@ -62,22 +62,17 @@
          </dependency>

          <!-- testing -->
+
          <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- <version>${project.version}</version>
+ <groupId>com.sun.grizzly</groupId>
+ <artifactId>grizzly-servlet-webserver</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
              <scope>test</scope>
          </dependency>
          <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- <version>6.1.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-util</artifactId>
- <version>6.1.3</version>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>${project.version}</version>
              <scope>test</scope>
          </dependency>
          <dependency>

Modified:
trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java
Url:
https://jersey.dev.java.net/source/browse/jersey/trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java?view=diff&rev=1786&p1=trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java&p2=trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java&r1=1785&r2=1786
==============================================================================
---
trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java
(original)
+++
trunk/jersey/contribs/spring/src/test/java/com/sun/jersey/spring/AbstractResourceTest.java
2008-12-03 09:38:27+0000
@@ -24,10 +24,7 @@
  import java.util.HashMap;
  import java.util.Map;

-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.springframework.web.context.ContextLoaderServlet;
+
  import org.testng.annotations.AfterClass;
  import org.testng.annotations.BeforeClass;

@@ -35,6 +32,9 @@
  import com.sun.jersey.api.client.WebResource;
  import com.sun.jersey.api.core.PackagesResourceConfig;
  import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+
+import com.sun.grizzly.http.embed.GrizzlyWebServer;
+import com.sun.grizzly.http.servlet.ServletAdapter;
  import java.util.logging.Level;
  import java.util.logging.Logger;

@@ -57,8 +57,9 @@
      private final int _port;
      private final String _servletPath;

- private Server _server;

+ private GrizzlyWebServer ws ;
+
      public AbstractResourceTest() {
          _springConfig = System.getProperty( "applicationContext",
APPLICATION_CONTEXT_SPRING25_XML );
          _port = 9999;
@@ -71,41 +72,45 @@
      @BeforeClass
      @SuppressWarnings("unused")
      public void setUp() throws Exception {
- startJetty( _port, _servletPath );
+ startGrizzly(_port, _servletPath);
      }
-
- private void startJetty( int port, String servletPath ) throws
Exception {
- LOGGER.info( "Starting jetty on port " + port + "..." );

- _server = new Server(port);
- final Context context = new Context(_server, "/",
Context.SESSIONS);
-
- final Map<String,String> contextParams = new HashMap<String,
String>();
- contextParams.put( "contextConfigLocation", "classpath:" +
_springConfig );
- context.setInitParams( contextParams );
-
-
- final ServletHolder springServletHolder = new ServletHolder(
ContextLoaderServlet.class );
-
- springServletHolder.setInitOrder( 1 );
- context.addServlet( springServletHolder, "/*" );
-
-
- final ServletHolder sh = new ServletHolder(SpringServlet.class);
- sh.setInitParameter(
"com.sun.jersey.config.property.resourceConfigClass",
+ /**
+ * Starts the embedded Grizzly server.
+ * @param port
+ * @param servletPath
+ * @throws java.lang.Exception
+ */
+ private void startGrizzly(int port, String servletPath) throws
Exception {
+ final Map<String, String> initParams = new HashMap<String,
String>();
+
+ initParams.put(
"com.sun.jersey.config.property.resourceConfigClass",
                   PackagesResourceConfig.class.getName() );
- sh.setInitParameter( PackagesResourceConfig.PROPERTY_PACKAGES,
+ initParams.put( PackagesResourceConfig.PROPERTY_PACKAGES,
                   "com.sun.jersey.spring.jerseymanaged" );
- sh.setInitOrder( 2 );
- context.addServlet(sh, servletPath + "/*");
-
- _server.start();
- LOGGER.info( "Successfully started jetty." );
+
+ LOGGER.info("Starting grizzly...");
+ ws = new GrizzlyWebServer(port);
+ ServletAdapter sa = new ServletAdapter();
+ sa.setServletInstance(SpringServlet.class.newInstance());
+
sa.addServletListener("org.springframework.web.context.ContextLoaderListener");
+
sa.addContextParameter("contextConfigLocation","classpath:"+_springConfig);
+ sa.addInitParameter(
"com.sun.jersey.config.property.resourceConfigClass",
+ PackagesResourceConfig.class.getName() );
+ sa.addInitParameter( PackagesResourceConfig.PROPERTY_PACKAGES,
+ "com.sun.jersey.spring.jerseymanaged" );
+ sa.setServletPath(servletPath);
+ ws.addGrizzlyAdapter(sa);
+ ws.start();
      }
-
- private void stopJetty() throws Exception {
+
+ /**
+ * Stop the embedded Grizzly server.
+ * @throws java.lang.Exception
+ */
+ private void stopGrizzly() throws Exception {
          try {
- _server.stop();
+ ws.stop();
          } catch( Exception e ) {
              LOGGER.log(Level.WARNING, "Could not stop jetty...", e );
          }
@@ -114,7 +119,7 @@
      @AfterClass
      public void tearDown() throws Exception {
          LOGGER.info( "tearDown..." );
- stopJetty();
+ stopGrizzly();
          LOGGER.info( "done..." );
      }

@@ -132,4 +137,4 @@
          return "http://localhost:" + _port + _servletPath + "/";
      }

-}
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: commits-help_at_jersey.dev.java.net