Skip to main content

[Jersey] Embedded Grizzly with MVC templates

1 reply [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Paul Sandoz

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
> ------------------------------------------------------------------
>
http://maven.apache.org/maven-v4_0_0.xsd
> ">
> 4.0.0
> middleware.application
> WSserver
> 1.0.0
>
> WSserver
>
>

>
> org.codehaus.mojo
> exec-maven-plugin
> 1.1.1
>
>
>
compile >
> java
>

>

>

>
>
> middleware.application.wsserver.Server
>

>
>
>
> org.apache.maven.plugins
> maven-compiler-plugin
>
> 1.6
> 1.6
>

>
> >
>
>

>
>
> com.sun.jersey
> jersey-server
> 1.1.4.1
>

>
> com.sun.jersey
> jersey-json
> 1.1.4.1
>

>
> com.sun.grizzly
> grizzly-servlet-webserver
> 1.9.18-e
>

>
> log4j
> log4j
> 1.2.14
>

>

>
> javax.annotation
> jsr250-api
> 1.0
>

>
> >
> ------------------------------------------------------------------
> 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)

[att1.html]