Hi Guys,
I am still having troubling getting doc root to work with a Grizzly2
HttpServer. I get a 404 when I try a a url in the docroot directory.
Here is the code I am using in a junit test program in my project. Can
any one guide me as to what I am doing wrong. Thanks.
//Begin code fragment for server creation and startup
URI uri = getBaseUri();
ServletHandler servletHandler = getServletHandler();
//See function def further below
org.glassfish.grizzly.http.server.HttpServer server =
GrizzlyServerFactory.createHttpServer(
uri,
servletHandler,
false
);
//Following code was added to enable docroot to be the
webapp dir under target/classes of my maven project
ServerConfiguration serverConfiguration =
server.getServerConfiguration();
String cwd = System.getProperty("user.dir");
String docRootFolder = cwd + "/target/classes/webapp";
serverConfiguration.addHttpHandler(new
StaticHttpHandler(docRootFolder), servletHandler.getContextPath());
server.start();
//End code fragment for server creation and startup
//Begin function that creates ServletHandler for my spring based app
public ServletHandler getServletHandler() {
if (servletHandler == null) {
servletHandler = new ServletHandler();
servletHandler.setServletInstance(getServlet());
servletHandler.setContextPath(contextRoot);
//Context params
servletHandler.addContextParameter("contextConfigLocation",
getAsString(springContextLocations));
//Init params
//jerseyAdapter.addInitParameter("contextConfigLocation",
contextLocations);
servletHandler.addInitParameter("com.sun.jersey.config.property.packages",
getAsString(packagesToScan));
//Servlet listeners
servletHandler.addServletListener("org.springframework.web.context.ContextLoaderListener");
servletHandler.addServletListener("org.springframework.web.context.request.RequestContextListener");
}
return servletHandler;
}
//End function that creates ServletHandler for my spring based app
On 01/07/2012 10:05 AM, Farrukh Najmi wrote:
>
> It looks like the following thread may answer my questions. Will try
> it out. Thanks.
>
> http://jersey.576304.n2.nabble.com/Grizzly-Jersey-REST-and-static-HTML-td7079979.html
>
>
> On 01/06/2012 06:09 PM, Farrukh Najmi wrote:
>> Hi Guys,
>>
>> This is a dumb question but...
>>
>> I am using a Grizzly2 embedded server created via
>> com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory to host a
>> jersey based REST endpoint using a
>> org.glassfish.grizzly.servlet.ServletHandler.
>>
>> Certain requests on that endpoint return a web page that needs to
>> reference some javascript files.
>> I am not sure where to place the javascript files nor how to
>> configure the HttpSerfver or ServletHandler instance so it can find
>> the files.
>>
>> Any pointers would be terrific. Thanks.
>>
>
>
--
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com