Most of your issues are you don't know that Jetty 11 is part of the Jakarta
EE 9 "big bang" which changed the namespace from `javax.<spec>` to
`jakarta.<spec>`, rendering the old spec namespace invalid and unusable.

> compile 'org.eclipse.jetty:jetty-server:11.0.0'
> compile 'javax.servlet:servlet-api:2.5'

Jetty 11 is a Jakarta EE 9 `jakarta.servlet` container.
That `javax.servlet` dependency is bad, and should not be used at all.
If you have any component needing it, you have a bad component in use for
Jetty 11.

> implementation group: 'io.swagger', name: 'swagger-jersey2-jaxrs',
version: '1.5.3'

That has a dependency on javax.servlet, so that `swagger-jersey2-jaxrs`
will not work with Jetty 11. (You'll want Jetty 10 for that)
https://search.maven.org/artifact/io.swagger/swagger-jersey2-jaxrs/1.5.3/jar

> compile 'org.springframework.data:spring-data-redis:1.8.0.RELEASE'
> compile 'redis.clients:jedis:2.9.0'

Those have cdi, javax.servlet, javax.el, and other dependencies that are
still on `javax.*` namespace.

In short, you'll either need to upgrade all of your dependencies to ones
that use Jakarta EE 9 on `jakarta.<spec>` or downgrade to Jetty 10.
You cannot mix and match both `javax.<spec>` and `jakarta.<spec>` like that.

Joakim Erdfelt / [email protected]


On Mon, Apr 26, 2021 at 7:07 PM Aniruddha Tekade via jetty-users <
[email protected]> wrote:

> Hello,
>
> I am trying to add a swagger configuration into my jetty server but when I
> try to add the
> ServletContainer and then attach ServletHolder to it, it fails. Seems like
> ServletContainer is not able to find any such constructor -
>
> package com.example.hfs;
>
> import com.cloudian.hfs.handlers.*;
> import jakarta.servlet.Servlet;
> import org.eclipse.jetty.server.HttpConfiguration;
> import org.eclipse.jetty.server.HttpConnectionFactory;
> import org.eclipse.jetty.server.Server;
> import org.eclipse.jetty.server.ServerConnector;
> import org.eclipse.jetty.server.handler.ContextHandler;
> import org.eclipse.jetty.server.handler.ContextHandlerCollection;
> import org.eclipse.jetty.server.handler.ResourceHandler;
> import org.eclipse.jetty.servlet.DefaultServlet;
> import org.eclipse.jetty.util.thread.QueuedThreadPool;
> import io.swagger.jaxrs.listing.ApiListingResource;
> import org.eclipse.jetty.servlet.ServletContextHandler;
> import org.eclipse.jetty.servlet.ServletHolder;
> import org.glassfish.jersey.server.ResourceConfig;
> import org.glassfish.jersey.servlet.ServletContainer;
> import io.swagger.jaxrs.config.BeanConfig;
>
>
>
> public class StartHFS {
>
>     public static void main(String[] args) throws Exception {
>         System.out.println("StartHFS");
>
>         // Build the Swagger Bean
>         buildSwagger();
>
>         // Create and configure a ThreadPool.
>         QueuedThreadPool threadPool = new QueuedThreadPool();
>         threadPool.setName("server");
>
>         // Create a Server instance.
>         Server server = new Server(threadPool);
>
>         // HTTP configuration and connection factory.
>         HttpConfiguration httpConfig = new HttpConfiguration();
>         HttpConnectionFactory http11 = new HttpConnectionFactory(httpConfig);
>
>         // Create a ServerConnector to accept connections from clients.
>         ServerConnector connector = new ServerConnector(server, 1, 1, http11);
>         connector.setPort(8080);
>         connector.setHost("0.0.0.0");
>         connector.setAcceptQueueSize(128);
>         server.addConnector(connector);
>
>         addHandlers(server);
>
>         // Start the Server so it starts accepting connections from clients.
>         server.start();
>         server.join();
>
>         System.out.println("StartHFS DONE");
>     }
>
>     static void addHandlers(final Server server) throws Exception {
>         ContextHandlerCollection contexts = new ContextHandlerCollection();
>         server.setHandler(contexts);
>
>         ContextHandler logHandler = new ContextHandler("/log");
>         logHandler.setHandler(new LoggingHandler());
>         contexts.addHandler(logHandler);
>
>         ContextHandler helloHandler = new ContextHandler("/hello");
>         helloHandler.setHandler(new HelloHandler());
>         contexts.addHandler(helloHandler);
>
>         ContextHandler featureStoreHandler = new 
> ContextHandler("/featurestore");
>         featureStoreHandler.setHandler(new FeatureStoreHandler());
>         contexts.addHandler(featureStoreHandler);
>
>         ContextHandler featureGroupsHandler = new 
> ContextHandler("/featuregroups");
>         featureGroupsHandler.setHandler(new FeatureGroupsHandler());
>         contexts.addHandler(featureGroupsHandler);
>
>         ContextHandler recordsHandler = new ContextHandler("/FeatureGroup");
>         recordsHandler.setHandler(new RecordsHandler());
>         contexts.addHandler(recordsHandler);
>
>         // Handler for HFS API, swagger.
>         contexts.addHandler(buildHfsContext());
>     }
>
>     private static ContextHandler buildHfsContext() {
>         ResourceConfig resourceConfig = new ResourceConfig();
>         resourceConfig.packages(StartHFS.class.getPackage().getName(),
>                 FeatureStoreHandler.class.getPackage().getName(),
>                 FeatureGroupsHandler.class.getPackage().getName(),
>                 HelloHandler.class.getPackage().getName(),
>                 LoggingHandler.class.getPackage().getName(),
>                 RecordsHandler.class.getPackage().getName(),
>                 ApiListingResource.class.getPackage().getName());
>         ServletContainer servletContainer = new 
> ServletContainer(resourceConfig);
>         ServletHolder servletHolder = new ServletHolder(servletContainer); 
> //"default", DefaultServlet.class);
>         ServletContextHandler servletContextHandler = new 
> ServletContextHandler( ServletContextHandler.SESSIONS );
>         servletContextHandler.setContextPath( "/hfs" );
>         servletContextHandler.addServlet( servletHolder, "/hfs/*");
>         return servletContextHandler;
>     }
>
> }
>
> In above code -
> ServletHolder servletHolder = new ServletHolder(servletContainer);
> this line from buildHfsContext() method is failing. I am particularly
> trying to configure the SwaggerConfig for my main class. And I am referring
> a solution from https://github.com/SriramKeerthi/swagger-jersey2-jetty
>
> My build.gradle contains dependencies -
>
> dependencies {
>     testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
>     testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
>     compile 'org.eclipse.jetty:jetty-server:11.0.0'
>     compile 'org.eclipse.jetty:jetty-servlet:11.0.0'
>     compile 'org.eclipse.jetty:jetty-util:11.0.0'
>     compile 'org.springframework.data:spring-data-redis:1.8.0.RELEASE'
>     compile 'redis.clients:jedis:2.9.0'
>     implementation group: 'org.json', name: 'json', version: '20201115'
>     implementation group: 'io.swagger', name: 'swagger-jersey2-jaxrs', 
> version: '1.5.3'
>     compile 'javax.servlet:servlet-api:2.5'
> }
>
> Can someone help me out? I am blocked by this situation at the moment.
>
> Best,
> Aniruddha
> ========
> ᐧ
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users

Reply via email to