Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty 9 embedded Servlet 3.0 annotations without war file

Traditionally annotation scanning is part of the WebApp layer.
Embedded Jetty focuses on direct declarations.

Johannes Brodwall's solution is creative, but only addresses a small subset of what, and how, annotations can be wired up. (which might be sufficient in most cases)
Examples: 
 * There's no good way to handle @HandlesType and ServletContainerInitializer his way.
 * There's no support for @MultipartConfig without a WebAppContext.metadata to hold that information
 * There's no support for @ServletSecurity without a WebAppContext.metadata to hold that information

Your example, however, uses @MultipartConfig, which is something that belongs in the WebAppContext's metadata.
That information, found during annotation scanning, isn't retained in a ServletContextHandler.


--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Expert advice, services and support from from the Jetty & CometD experts

On Fri, Jan 16, 2015 at 7:26 AM, Christian Reuschling <reuschling@xxxxxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

we have no war file, nor some extra classpath, but simply want to add our servlet object instance
to the embedded server, by taking it's servlet 3.0 parameters into account.

All the documentation on Jetty, and all examples and snippets we found for embedded + servlet 3.0
annotations deals with specifying a war file or a classpath, which will be scanned by
AnnotationConfiguration then.

We tried a lot, but we were not able to do the same by simply adding the servlet with
context.addServlet().

Here is our code:


        Server server = new Server(iPort);

        // tried: ServletHandler handler = new ServletHandler();
        // tried: WebAppContext contextHandler = new WebAppContext();
        ServletContextHandler contextHandler = new ServletContextHandler();
        contextHandler.setContextPath("/");

        // tried: contextHandler.setConfigurations(new Configuration[] {
        //             new AnnotationConfiguration() });
        // tried: contextHandler.setConfigurationDiscovered(true);

        contextHandler.addServlet(new ServletHolder(new ExampleServlet()), "/*");
        server.setHandler(contextHandler);

        server.start();


The Servlet is a simple HttpServlet with following annotations:

@WebServlet(urlPatterns = { "/example/*" }, loadOnStartup = 1, initParams =
{
        @WebInitParam(name = "name1", value = "val1"),
        @WebInitParam(name = "name2", value = "val2")
})
@MultipartConfig(fileSizeThreshold = 1024*1024*10)
public class ExampleServlet extends HttpServlet
{....}



How is it possible that the embedded Jetty server simply takes the annotations of the Servlet
Object added to the server with context/handler.addServlet(..) into account, and nothing else, as
the most simple scenario.


Thanks for all answers!

Christian



- --
______________________________________________________________________________
Christian Reuschling, Dipl.-Ing.(BA)
Software Engineer

Knowledge Management Department
German Research Center for Artificial Intelligence DFKI GmbH
Trippstadter Straße 122, D-67663 Kaiserslautern, Germany

Phone: +49.631.20575-1250
mailto:reuschling@xxxxxxx  http://www.dfki.uni-kl.de/~reuschling/

- ------------Legal Company Information Required by German Law------------------
Geschäftsführung: Prof. Dr. Dr. h.c. mult. Wolfgang Wahlster (Vorsitzender)
                  Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats: Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313=
______________________________________________________________________________
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iEYEARECAAYFAlS5H6cACgkQ6EqMXq+WZg/P3wCfY8Fjvk+KTgFsh13QG/FvVaH+
lkMAnjIgWeu07XYxaee56wKMNOszdglP
=g7VS
-----END PGP SIGNATURE-----
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top