users@jersey.java.net

Re: [Jersey] Embedded Grizzly with MVC templates

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Dec 2009 20:35:29 +0100

                        
On Dec 29, 2009, at 5:08 PM, Dean Lane wrote:

> Thank you for the response Paul. I'm using the latest non-snapshot
> code. It was 1.9.18-e at the time I posted this query.
>
> I've come to suspect that it doesn't support JSPs yet. I've since
> switched to a normal deployable web application and things are
> preceding much smoother.
>

OK. I see to recall, from the Grizzly users list, that Grizzly may be
able to support JSPs but we may need to wait until everyone gets back
from holiday to know the answer.

Paul.

> Dean
>
> On Tue, Dec 29, 2009 at 3:14 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
> Hi Dean,
>
> Cross posting to the grizzly users list.
>
> What version of Grizzly are you using?
>
> I cannot recall if the latest Grizzly servlet container now supports
> JSPs or not.
>
> Paul.
>
> On Dec 18, 2009, at 10:43 PM, Dean Lane wrote:
>
>> Please excuse this probably very poorly worded question and
>> description.
>>
>> I am very new to all of this stuff but I was interested in testing
>> the embedded Grizzly server with the MVC style templates described
>> in the bookstore sample application.
>>
>> So, I am trying to combine the two samples (bookstore and https-
>> clientserver-grizzly).
>>
>> Should this be possible?
>>
>> What I've done up to this point appears to be doing the right thing
>> until it fails. It fails when it tries to get a RequestDispatcher
>> from the servletContext in JSPTemplateProcessor. Stepping through
>> the code shows that servletContext is an instance of
>> ServletContextImpl and the getRequestDispatcher() method appears to
>> need to be overridden.
>>
>> I assume that I'm missing something with the initialization of the
>> server.
>>
>> Tips, google keywords or anything to point me in the right
>> direction would be much appreciated.
>>
>> Thanks,
>> Dean
>>
>> ------------------------------------------------------------------
>> Main Server Class:
>> ------------------------------------------------------------------
>> ------------------------------------------------------------------
>> package middleware.application.wsserver;
>>
>> import java.io.IOException;
>> import java.net.URI;
>>
>> import javax.ws.rs.core.UriBuilder;
>> import javax.annotation.security.*;
>>
>> import middleware.application.wsserver.auth.SecurityFilter;
>>
>> import com.sun.grizzly.SSLConfig;
>> import com.sun.grizzly.http.embed.GrizzlyWebServer;
>> import com.sun.grizzly.http.servlet.ServletAdapter;
>> import com.sun.grizzly.ssl.SSLSelectorThread;
>> import
>> com
>> .sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory;
>> import com.sun.jersey.api.core.ResourceConfig;
>> import com.sun.jersey.spi.container.servlet.ServletContainer;
>>
>> public class Server
>> {
>> private static GrizzlyWebServer webServer;
>>
>> public static final URI BASE_URI = getBaseURI();
>> public static final String CONTENT = "JERSEY HTTPS EXAMPLE\n";
>>
>> private static URI getBaseURI() {
>> return UriBuilder.fromUri("https://
>> localhost/").port(getPort(4463)).build();
>> }
>>
>> private static int getPort(int defaultPort) {
>> String port = System.getenv("JERSEY_HTTP_PORT");
>> if (null != port) {
>> try {
>> return Integer.parseInt(port);
>> } catch (NumberFormatException e) {
>> }
>> }
>> return defaultPort;
>> }
>>
>> protected static void startServer() {
>>
>> webServer = new GrizzlyWebServer(getPort(4463), ".", true);
>>
>> // add Jersey resource servlet
>>
>> ServletAdapter jerseyAdapter = new ServletAdapter();
>>
>> jerseyAdapter
>> .addInitParameter("com.sun.jersey.config.property.packages",
>>
>> "middleware
>> .application
>> .wsserver
>> ;middleware
>> .application.wsserver.auth;middleware.application.resources");
>> jerseyAdapter.setContextPath("/");
>> jerseyAdapter.setServletInstance(new ServletContainer());
>>
>> // add security filter (which handles http basic
>> authentication)
>>
>>
>> jerseyAdapter
>> .addInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
>> SecurityFilter.class.getName());
>>
>> jerseyAdapter
>> .addInitParameter(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES,
>> RolesAllowedResourceFilterFactory.class.getName());
>>
>>
>> jerseyAdapter.addInitParameter(ResourceConfig.FEATURE_REDIRECT,
>> "true");
>>
>> jerseyAdapter
>> .addInitParameter(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
>>
>> jerseyAdapter
>> .addInitParameter(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
>> "/(images|css|jsp)/.*");
>>
>> webServer.addGrizzlyAdapter(jerseyAdapter, new String[]{"/
>> *"});
>>
>>
>> // Grizzly ssl configuration
>>
>> SSLConfig sslConfig = new SSLConfig();
>>
>> // sslConfig.setNeedClientAuth(true); // don't work - known
>> grizzly bug, will be fixed in 2.0.0
>>
>> // set up security context
>> sslConfig.setKeyStoreFile("./security/keystore_server"); //
>> contains server keypair
>> sslConfig.setKeyStorePass("asdfgh");
>> sslConfig.setTrustStoreFile("./security/
>> truststore_server"); // contains client certificate
>> sslConfig.setTrustStorePass("asdfgh");
>>
>> webServer.setSSLConfig(sslConfig);
>>
>> // turn server side client certificate authentication on
>>
>> ((SSLSelectorThread)
>> webServer.getSelectorThread()).setNeedClientAuth(false);
>>
>> try {
>> // start Grizzly embedded server //
>> System.out.println("Jersey app started. Try out " +
>> BASE_URI + "\nHit CTRL + C to stop it...");
>> webServer.start();
>> } catch (Exception ex) {
>> System.out.println(ex.getMessage());
>> }
>> }
>>
>> public static void stopServer() {
>> webServer.stop();
>> }
>>
>> public static void main(String[] args) throws
>> InterruptedException, IOException {
>> startServer();
>> }
>>
>> }
>>
>> ------------------------------------------------------------------
>> POM
>> ------------------------------------------------------------------
>> <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>middleware.application</groupId>
>> <artifactId>WSserver</artifactId>
>> <version>1.0.0</version>
>> <build>
>> <finalName>WSserver</finalName>
>> <plugins>
>> <!-- Maven Exec Plug-In: http://mojo.codehaus.org/exec-maven-plugin/
>> -->
>> <plugin>
>> <groupId>org.codehaus.mojo</groupId>
>> <artifactId>exec-maven-plugin</artifactId>
>> <version>1.1.1</version>
>> <executions>
>> <execution>
>> <phase>compile</phase>
>> <goals>
>> <goal>java</goal>
>> </goals>
>> </execution>
>> </executions>
>> <configuration>
>>
>> <mainClass>middleware.application.wsserver.Server</mainClass>
>> </configuration>
>> </plugin>
>>
>> <plugin>
>> <groupId>org.apache.maven.plugins</groupId>
>> <artifactId>maven-compiler-plugin</artifactId>
>> <configuration>
>> <source>1.6</source>
>> <target>1.6</target>
>> </configuration>
>> </plugin>
>> </plugins>
>> </build>
>> <repositories>
>> </repositories>
>> <dependencies>
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>> <artifactId>jersey-server</artifactId>
>> <version>1.1.4.1</version>
>> </dependency>
>> <dependency>
>> <groupId>com.sun.jersey</groupId>
>> <artifactId>jersey-json</artifactId>
>> <version>1.1.4.1</version>
>> </dependency>
>> <dependency>
>> <groupId>com.sun.grizzly</groupId>
>> <artifactId>grizzly-servlet-webserver</artifactId>
>> <version>1.9.18-e</version>
>> </dependency>
>> <dependency>
>> <groupId>log4j</groupId>
>> <artifactId>log4j</artifactId>
>> <version>1.2.14</version>
>> </dependency>
>> <!-- For J2EE Annotations
>> RolesAllowed,PermitAll,DenyAll,RunAs -->
>> <dependency>
>> <groupId>javax.annotation</groupId>
>> <artifactId>jsr250-api</artifactId>
>> <version>1.0</version>
>> </dependency>
>> </dependencies>
>> </project>
>>
>> ------------------------------------------------------------------
>> Stack Trace
>> ------------------------------------------------------------------
>> Dec 18, 2009 3:29:48 PM com.sun.grizzly.http.servlet.ServletAdapter
>> doService
>> SEVERE: service exception:
>> java.lang.UnsupportedOperationException: Not supported yet.
>> at
>> com
>> .sun
>> .grizzly
>> .http
>> .servlet
>> .ServletContextImpl.getRequestDispatcher(ServletContextImpl.java:351)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .container
>> .servlet.JSPTemplateProcessor.writeTo(JSPTemplateProcessor.java:113)
>> at
>> com
>> .sun
>> .jersey.spi.template.ResolvedViewable.writeTo(ResolvedViewable.java:
>> 102)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .template
>> .ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:81)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .template
>> .ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:58)
>> at
>> com
>> .sun
>> .jersey
>> .spi.container.ContainerResponse.write(ContainerResponse.java:266)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:814)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:740)
>> at
>> com
>> .sun
>> .jersey
>> .server
>> .impl
>> .application
>> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:731)
>> at
>> com
>> .sun
>> .jersey
>> .spi.container.servlet.WebComponent.service(WebComponent.java:372)
>> at
>> com
>> .sun
>> .jersey
>> .spi
>> .container.servlet.ServletContainer.service(ServletContainer.java:
>> 452)
>> at
>> com
>> .sun
>> .jersey
>> .spi
>> .container.servlet.ServletContainer.service(ServletContainer.java:
>> 633)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>> at
>> com
>> .sun
>> .grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:
>> 188)
>> at
>> com
>> .sun
>> .grizzly
>> .http
>> .servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:137)
>> at
>> com
>> .sun
>> .grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:
>> 376)
>> at
>> com
>> .sun
>> .grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:324)
>> at
>> com
>> .sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:
>> 166)
>> at
>> com
>> .sun
>> .grizzly
>> .tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:180)
>> at
>> com
>> .sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:
>> 166)
>> at
>> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:
>> 789)
>> at
>> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:697)
>> at
>> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:952)
>> at
>> com
>> .sun
>> .grizzly
>> .http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:166)
>> at
>> com
>> .sun
>> .grizzly
>> .DefaultProtocolChain
>> .executeProtocolFilter(DefaultProtocolChain.java:135)
>> at
>> com
>> .sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:
>> 102)
>> at
>> com
>> .sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:
>> 88)
>> at
>> com
>> .sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:
>> 76)
>> at
>> com
>> .sun
>> .grizzly
>> .ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
>> at
>> com
>> .sun
>> .grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:
>> 57)
>> at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
>> at com.sun.grizzly.util.AbstractThreadPool
>> $Worker.doWork(AbstractThreadPool.java:330)
>> at com.sun.grizzly.util.AbstractThreadPool
>> $Worker.run(AbstractThreadPool.java:309)
>> at java.lang.Thread.run(Thread.java:619)
>
>