A reminder this is the Main function I am working with for jetty 11.
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; /** * This class launches the web application in an embedded Jetty container. * This is the entry point to your application. The Java * command that is used for launching should fire this main method. */ public class Main { public static void main(String[] args) throws Exception{ // The port that we should run on can be set into an environment variable // Look for that variable and default to 8080 if it isn't there. String webPort = System.getenv("PORT"); if (webPort == null || webPort.isEmpty()) { webPort = "8080"; } final Server server = new Server(Integer.valueOf(webPort)); final WebAppContext root = new WebAppContext(); root.setContextPath("/"); root.setParentLoaderPriority(true); final String webappDirLocation = "src/main/webapp/"; root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml"); root.setResourceBase(webappDirLocation); server.setHandler(root); server.start(); server.join(); } } <http://www.backbutton.co.uk/> On Mon, 5 Apr 2021, 01:31 Som Lima, <somplastic...@gmail.com> wrote: > Thank you I also agree that is the correct jetty reponse. > > I am using embedded jetty 11. > Using webAppContext for configuration. > we also have agreed that > " in jetty 11 there is indeed no ClassList, so that part is "broken". ". > > What other method of configuration I have available for adding > features as and when I need them > to the embedded jetty 11 org.eclipse.jetty.server.Server object apart > from using ServletContextHandler ? > > Please send me link showing the instructions. > > > > > > On Sun, 4 Apr 2021, 23:23 Greg Wilkins, <gr...@webtide.com> wrote: > >> Som, >> >> Without a web.xml, the Jersey servlet is not setup to handle requests. >> Without Jersey, there is nothing in Jetty to map any request to >> MyResource. >> >> Unless there is something annotated or in a discovered webfragment, then >> Jetty has no handler for that request and 404 is the correct response. >> >> regards >> >> >> >> On Mon, 5 Apr 2021 at 00:10, Som Lima <somplastic...@gmail.com> wrote: >> >>> Let me put it another way. >>> If I remove web.xml why does the following code give me 404 in jetty >>> 11 ? >>> >>> >>> import jakarta.ws.rs.GET; >>> import jakarta.ws.rs.Path; >>> import jakarta.ws.rs.Produces; >>> import jakarta.ws.rs.core.MediaType; >>> >>> /** >>> * Root resource (exposed at "myresource" path) >>> */ >>> @Path("myresource") >>> public class MyResource { >>> >>> /** >>> * Method handling HTTP GET requests. The returned object will be >>> sent >>> * to the client as "text/plain" media type. >>> * >>> * @return String that will be returned as a text/plain response. >>> */ >>> @GET >>> @Produces(MediaType.TEXT_PLAIN) >>> public String getIt() { >>> return "got, it!"; >>> } >>> } >>> >>> On Sun, 4 Apr 2021, 15:03 Joakim Erdfelt, <joa...@webtide.com> wrote: >>> >>>> <welcome-file-list> is only used when Jetty is in charge of serving >>>> static content. >>>> Or said another way, when there is a request for a resource that >>>> doesn't match a url-pattern that the webapp has specified, then the servlet >>>> spec Default Servlet kicks in and determines static content, welcome-files, >>>> etc ... >>>> >>>> You have jersey setup with <url-pattern>/*</url-pattern>, which means >>>> Jersey is responsible for 100% of content served. >>>> Jetty is not involved in much with that configuration. >>>> >>>> I don't understand this kind of configuration, Jersey usage should be >>>> focused, only on REST api resources, not 100% of content, including static >>>> and default servlet. >>>> I would recommend that you specify jersey on a narrow focused >>>> url-pattern, like `/api/*` and leave the other requests for resources to >>>> Jetty (it can serve static content WAY BETTER than Jersey can). >>>> >>>> Joakim Erdfelt / joa...@webtide.com >>>> >>>> >>>> On Sat, Apr 3, 2021 at 1:55 AM Som Lima <somplastic...@gmail.com> >>>> wrote: >>>> >>>>> >>>>> IF I have the web.xml then localhost:8080/myresource works fine >>>>> BUT the index.jsp is not picked with localhost:8080 or >>>>> http://localhost/index.jsp >>>>> I got an 404. >>>>> URI: / >>>>> STATUS: 404 >>>>> >>>>> IF I remove the web.xml then the index.jsp is picked up which is what >>>>> is meant to happen with jetty because it's built in functionality >>>>> assumes an index.jsp file is there and will pick it and publish it. >>>>> But the I get a 404 with localhost:8080/myresource now. >>>>> I want both index.jsp to be picked up and have the jersey >>>>> functionality localhost:8080/myresource with the web.xml >>>>> but I can only have one or the other. >>>>> >>>>> <?xml version="1.0" encoding="UTF-8"?> >>>>> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi=" >>>>> http://www.w3.org/2001/XMLSchema-instance" >>>>> xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee >>>>> https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" >>>>> version="5.0"> >>>>> >>>>> <servlet> >>>>> <servlet-name>Jersey Web Application</servlet-name> >>>>> >>>>> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> >>>>> <init-param> >>>>> >>>>> <param-name>jersey.config.server.provider.packages</param-name> >>>>> <param-value>com.example</param-value> >>>>> </init-param> >>>>> <load-on-startup>1</load-on-startup> >>>>> </servlet> >>>>> <servlet-mapping> >>>>> <servlet-name>Jersey Web Application</servlet-name> >>>>> <url-pattern>/*</url-pattern> >>>>> </servlet-mapping> >>>>> >>>>> <!-- no effect --> >>>>> <welcome-file-list> >>>>> <welcome-file>index.jsp</welcome-file> >>>>> </welcome-file-list> >>>>> >>>>> </web-app> >>>>> >>>>> >>>>> import jakarta.ws.rs.GET; >>>>> import jakarta.ws.rs.Path; >>>>> import jakarta.ws.rs.Produces; >>>>> import jakarta.ws.rs.core.MediaType; >>>>> >>>>> /** >>>>> * Root resource (exposed at "myresource" path) >>>>> */ >>>>> @Path("myresource") >>>>> public class MyResource { >>>>> >>>>> /** >>>>> * Method handling HTTP GET requests. The returned object will be >>>>> sent >>>>> * to the client as "text/plain" media type. >>>>> * >>>>> * @return String that will be returned as a text/plain response. >>>>> */ >>>>> @GET >>>>> @Produces(MediaType.TEXT_PLAIN) >>>>> public String getIt() { >>>>> return "got, it!"; >>>>> } >>>>> } >>>>> >>>>> >>>>> >>>>> Preferably I also want the Rest API Config to work as well as the >>>>> index.jsp so that I can call the resource localhost:8080/v1/myresource >>>>> >>>>> import jakarta.ws.rs.ApplicationPath; >>>>> import jakarta.ws.rs.core.Application; >>>>> >>>>> @ApplicationPath("v1") >>>>> public class RestAppConfig extends Application{ >>>>> } >>>>> >>>>> >>>>> _______________________________________________ >>>>> jetty-users mailing list >>>>> jetty-users@eclipse.org >>>>> To unsubscribe from this list, visit >>>>> https://www.eclipse.org/mailman/listinfo/jetty-users >>>>> >>>> _______________________________________________ >>>> jetty-users mailing list >>>> jetty-users@eclipse.org >>>> To unsubscribe from this list, visit >>>> https://www.eclipse.org/mailman/listinfo/jetty-users >>>> >>> _______________________________________________ >>> jetty-users mailing list >>> jetty-users@eclipse.org >>> To unsubscribe from this list, visit >>> https://www.eclipse.org/mailman/listinfo/jetty-users >>> >> >> >> -- >> Greg Wilkins <gr...@webtide.com> CTO http://webtide.com >> _______________________________________________ >> jetty-users mailing list >> jetty-users@eclipse.org >> To unsubscribe from this list, visit >> https://www.eclipse.org/mailman/listinfo/jetty-users >> >
_______________________________________________ jetty-users mailing list jetty-users@eclipse.org To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users