Quantcast

Embedding in Jetty without web.xml

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Embedding in Jetty without web.xml

Philip Healy
Hello,

  I am trying to set up a Wicket application to execute in an embedded Jetty
instance.  The Wicket application is not deployed as a webapp (so there so
web.xml), as I am trying to avoid using unnecessary directory structure and
config files). The Wicket application classes are available on the
classpath.  I am using the following to configure the Wicket filter and
start the Jetty server:


// Create server and root context
Server server = new Server();
Connector connector = new SocketConnector();
connector.setPort(8080);
server.addConnector(connector);
Context context = new Context(server, "/");

// Add wicket filter
FilterHolder filterHolder = new FilterHolder(WicketFilter.class);
filterHolder.setInitParameter("applicationClassName",
    TestWebApplication.class.getCanonicalName());
context.addFilter(filterHolder, "/*", org.mortbay.jetty.Handler.DEFAULT);

// Start server
server.start();
server.join();


I added the following to the  init() method of the WebApplication subclass:

mount("/test", PackageName.forPackage(this.getClass().getPackage()));

Although the server starts, the Wicket application is not available at
http://localhost:8080/test/, I get a Jetty-generated 404 message.  Any
ideas?

Regards,
Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Embedding in Jetty without web.xml

Eelco Hillenius
Actually, WicketFilter does try to read web.xml. See WicketFilter#init.

You could file a feature request to let the framework be more lenient
so that it doesn't fail when web.xml is not available. We can at least
think about that. To solve your problem now, I suggest you make a copy
of WicketFilter for your own purposes and rip the web.xml reading code
out and get your filter path somewhere else.

Eelco

On Jan 29, 2008 4:21 PM, Philip Healy <[hidden email]> wrote:

> Hello,
>
>   I am trying to set up a Wicket application to execute in an embedded Jetty
> instance.  The Wicket application is not deployed as a webapp (so there so
> web.xml), as I am trying to avoid using unnecessary directory structure and
> config files). The Wicket application classes are available on the
> classpath.  I am using the following to configure the Wicket filter and
> start the Jetty server:
>
>
> // Create server and root context
> Server server = new Server();
> Connector connector = new SocketConnector();
> connector.setPort(8080);
> server.addConnector(connector);
> Context context = new Context(server, "/");
>
> // Add wicket filter
> FilterHolder filterHolder = new FilterHolder(WicketFilter.class);
> filterHolder.setInitParameter("applicationClassName",
>     TestWebApplication.class.getCanonicalName());
> context.addFilter(filterHolder, "/*", org.mortbay.jetty.Handler.DEFAULT);
>
> // Start server
> server.start();
> server.join();
>
>
> I added the following to the  init() method of the WebApplication subclass:
>
> mount("/test", PackageName.forPackage(this.getClass().getPackage()));
>
> Although the server starts, the Wicket application is not available at
> http://localhost:8080/test/, I get a Jetty-generated 404 message.  Any
> ideas?
>
> Regards,
> Philip
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Embedding in Jetty without web.xml

Peter Ertl-3
Dont change wicket, it's fine :-)

Actually I got this working without any web.xml or WEB-INF/ and it's  
possible!

The things is: When you use the wicket filter you also need to add the  
DefaultServlet (or any servlet that is mapped to your wicket filter  
path)

it looks like that in my AppLauncherJetty.class

   context.addServlet(DefaultServlet.class, "/*")  // or whatever you  
wicket filter path is

in jetty a filter is just _decorating_ a request. but the request  
needs a _target_ which the DefaultServlet in that case is.

otherwise you get a 404!

even though wicket filter eventually does not call chain.doFilter(..)  
jetty still needs the servlet.

Try and see.

Regards
Peter


Am 30.01.2008 um 01:27 schrieb Eelco Hillenius:

> Actually, WicketFilter does try to read web.xml. See  
> WicketFilter#init.
>
> You could file a feature request to let the framework be more lenient
> so that it doesn't fail when web.xml is not available. We can at least
> think about that. To solve your problem now, I suggest you make a copy
> of WicketFilter for your own purposes and rip the web.xml reading code
> out and get your filter path somewhere else.
>
> Eelco
>
> On Jan 29, 2008 4:21 PM, Philip Healy <[hidden email]> wrote:
>> Hello,
>>
>>  I am trying to set up a Wicket application to execute in an  
>> embedded Jetty
>> instance.  The Wicket application is not deployed as a webapp (so  
>> there so
>> web.xml), as I am trying to avoid using unnecessary directory  
>> structure and
>> config files). The Wicket application classes are available on the
>> classpath.  I am using the following to configure the Wicket filter  
>> and
>> start the Jetty server:
>>
>>
>> // Create server and root context
>> Server server = new Server();
>> Connector connector = new SocketConnector();
>> connector.setPort(8080);
>> server.addConnector(connector);
>> Context context = new Context(server, "/");
>>
>> // Add wicket filter
>> FilterHolder filterHolder = new FilterHolder(WicketFilter.class);
>> filterHolder.setInitParameter("applicationClassName",
>>    TestWebApplication.class.getCanonicalName());
>> context.addFilter(filterHolder, "/*",  
>> org.mortbay.jetty.Handler.DEFAULT);
>>
>> // Start server
>> server.start();
>> server.join();
>>
>>
>> I added the following to the  init() method of the WebApplication  
>> subclass:
>>
>> mount("/test", PackageName.forPackage(this.getClass().getPackage()));
>>
>> Although the server starts, the Wicket application is not available  
>> at
>> http://localhost:8080/test/, I get a Jetty-generated 404 message.  
>> Any
>> ideas?
>>
>> Regards,
>> Philip
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Embedding in Jetty without web.xml

Peter Ertl-3
In reply to this post by Eelco Hillenius
Also you should do this instead:

> Context context = new Context(server, "/", Context.SESSIONS);


you write:

>> Context context = new Context(server, "/");

Loading...