dev@grizzly.java.net

Re: Pls help: Integrate Grizzly with jGuard

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Tue, 01 Jan 2013 20:47:16 -0800

What is the code at:

net.sf.jguard.jee.util.WebappUtil.getWebappHomePath(WebappUtil.java:50)



?

> mars.fu_at_armorize.com <mailto:mars.fu_at_armorize.com>
> January 1, 2013 2:41 AM
> Dear Grizzly experts,
> We plan to integrate jGuard into our rest server written by jersey and
> grizzly. But we got null pointer exception when invoking
> contextInitialized() of jguard listeners. Need your help to give us an
> directiion. Thank you very much.
>
> Here is our program fragment to add jguard listener when create grizzly
> web server.
>
> protected static GrizzlyWebServer startServer() throws IOException {
>
> httpScheme = "http";
>
> ServletAdapter jAdapter = new ServletAdapter();
>
> jAdapter.setContextPath("/");
> jAdapter.setServletInstance(new ServletContainer());
>
>
> jAdapter.addContextParameter("authenticationConfigurationLocation",
> "classpath:jGuardAuthentication.xml");
> jAdapter.addContextParameter("authenticationScope", "local");
>
> jAdapter.addContextParameter("authorizationConfigurationLocation",
> "classpath:jGuardAuthorization.xml");
> jAdapter.addContextParameter("authorizationScope", "local");
> jAdapter.addContextParameter("enableJMX", "false");
> Map<String,String> map = new HashMap<String,String>();
> map.put("configurationLocation", "classpath:jGuardFilter.xml");
>
>
> jAdapter.addServletListener("net.sf.jguard.jee.listeners.SessionListene
> r");
>
> jAdapter.addServletListener("net.sf.jguard.jee.listeners.ContextListene
> r");
>
> jAdapter.addFilter(new AccessFilter(),"AccessFilter",map);
>
> GrizzlyWebServer ws = new GrizzlyWebServer(serviceHost,
> servicePort, "", false);
>
> ws.addGrizzlyAdapter(jAdapter, new String[] {"/"});
> ws.setCoreThreads(maxRestServiceThreadNo);
> ws.setMaxThreads(maxRestServiceThreadNo);
>
> System.out.println( "Start running the server..." );
>
> ws.start();
> return ws;
> }
>
> And we got the following exception:
> WARN: GRIZZLY0052: Exception invoking contextInitialized() on
> ServletContextListener: net.sf.jguard.jee.listeners.ContextListener.
> java.lang.NullPointerException
> at
> net.sf.jguard.jee.util.WebappUtil.getWebappHomePath(WebappUtil.java:50)
> at
> net.sf.jguard.jee.listeners.ContextListener.contextInitialized(ContextL
> istener.java:98)
> at
> com.sun.grizzly.http.servlet.ServletContextImpl.initListeners(ServletCo
> ntextImpl.java:173)
> at
> com.sun.grizzly.http.servlet.ServletAdapter.configureServletEnv(Servlet
> Adapter.java:527)
> at
> com.sun.grizzly.http.servlet.ServletAdapter.start(ServletAdapter.java:3
> 36)
> at
> com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.start(GrizzlyAdapterChai
> n.java:135)
> at
> com.sun.grizzly.http.SelectorThread.initEndpoint(SelectorThread.java:11
> 89)
> at
> com.sun.grizzly.http.SelectorThread.listen(SelectorThread.java:1242)
> at
> com.sun.grizzly.http.embed.GrizzlyWebServer.start(GrizzlyWebServer.java
> :678)
> at
> com.armorize.hackalert.si.api.engine.Main.startServer(Main.java:279)
> at
> com.armorize.hackalert.si.api.engine.Main.main(Main.java:197)
>
>
> Here is the fragment of pom.xml we used:
> <dependencies>
> <dependency>
> <groupId>com.arm.loggly</groupId>
> <artifactId>logglylog4j</artifactId>
> <version>0.0.2</version>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-server</artifactId>
> <version>1.13</version>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-client</artifactId>
> <version>1.13</version>
> </dependency>
> <dependency>
> <groupId>com.sun.grizzly</groupId>
> <artifactId>grizzly-webserver</artifactId>
> <version>1.9.51</version>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-grizzly</artifactId>
> <version>1.13</version>
> </dependency>
> <dependency>
> <groupId>log4j</groupId>
> <artifactId>log4j</artifactId>
> <version>1.2.17</version>
> </dependency>
> <dependency>
> <groupId>com.amazonaws</groupId>
> <artifactId>aws-java-sdk</artifactId>
> <version>1.3.2</version>
> </dependency>
> <dependency>
> <groupId>com.google.code.gson</groupId>
> <artifactId>gson</artifactId>
> <version>2.2.1</version>
> </dependency>
> <dependency>
> <groupId>quartz</groupId>
> <artifactId>quartz</artifactId>
> <version>1.5.2</version>
> </dependency>
> <dependency>
> <groupId>javax.mail</groupId>
> <artifactId>mail</artifactId>
> <version>1.4.5</version>
> </dependency>
> <dependency>
> <groupId>org.apache.commons</groupId>
> <artifactId>commons-lang3</artifactId>
> <version>3.1</version>
> </dependency>
> <dependency>
> <groupId>net.sf.jguard</groupId>
> <artifactId>jguard-core</artifactId>
> <version>1.0.4</version>
> </dependency>
> <dependency>
> <groupId>net.sf.jguard</groupId>
> <artifactId>jguard-jee</artifactId>
> <version>1.0.4</version>
> </dependency>
> </dependencies>