Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty 8 standalone and Servlet 3.0 without web.xml

Works with spring too.

$ jar -tvf webapps/webapp-3.0-bare-spring.war 
     0 Thu Jan 15 12:32:52 MST 2015 META-INF/
   131 Thu Jan 15 12:32:52 MST 2015 META-INF/MANIFEST.MF
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/lib/
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/org/
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/org/eclipse/
     0 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/org/eclipse/demo/
  4467 Mon Oct 08 12:19:26 MST 2012 WEB-INF/lib/aopalliance-1.0.jar
442400 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-core-3.1.0.RELEASE.jar
 53079 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-asm-3.1.0.RELEASE.jar
829601 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-context-3.1.0.RELEASE.jar
176283 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-_expression_-3.1.0.RELEASE.jar
540819 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-web-3.1.0.RELEASE.jar
 60686 Thu Sep 27 08:14:48 MST 2012 WEB-INF/lib/commons-logging-1.1.1.jar
589253 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-beans-3.1.0.RELEASE.jar
331474 Thu Jan 15 12:27:02 MST 2015 WEB-INF/lib/spring-aop-3.1.0.RELEASE.jar
  1699 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/org/eclipse/demo/TimeServlet.class
  1086 Thu Jan 15 12:32:52 MST 2015 WEB-INF/classes/org/eclipse/demo/MyAppInitializer.class

Code for MyAppInitializer.java

package org.eclipse.demo;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletContext;

import org.springframework.web.WebApplicationInitializer;

public class MyAppInitializer implements WebApplicationInitializer
{

    @Override
    public void onStartup(ServletContext context)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        context.setAttribute("my.app.init","Initialized at: " + sdf.format(new Date()));
    }
}

and Code for TimeServlet.java

package org.eclipse.demo;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(urlPatterns="/time")
public class TimeServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        out.println("(From " + MyAppInitializer.class.getName() + "): " 
            + req.getServletContext().getAttribute("my.app.init"));
        out.println("(From servlet): " + new Date());
    }
}

The server console:

2015-01-15 12:33:35.626:INFO:oejs.Server:jetty-8.1.16.v20140903
2015-01-15 12:33:35.640:INFO:oejdp.ScanningAppProvider:Deployment monitor /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps at interval 1
2015-01-15 12:33:35.646:INFO:oejd.DeploymentManager:Deployable added: /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare-spring.war
2015-01-15 12:33:35.676:INFO:oejw.WebInfConfiguration:Extract jar:file:/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare-spring.war!/ to /tmp/jetty-0.0.0.0-8080-webapp-3.0-bare-spring.war-_webapp-3.0-bare-spring-any-/webapp
2015-01-15 12:33:36.432:INFO:w.0-bare-spring:Spring WebApplicationInitializers detected on classpath: [org.eclipse.demo.MyAppInitializer@70941f0a]
2015-01-15 12:33:36.659:INFO:oejdp.ScanningAppProvider:Deployment monitor /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/contexts at interval 1
2015-01-15 12:33:36.673:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
2015-01-15 12:33:36.907:INFO:oejus.SslContextFactory:Enabled Protocols [SSLv2Hello, TLSv1, TLSv1.1, TLSv1.2] of [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2]
2015-01-15 12:33:36.911:INFO:oejs.AbstractConnector:Started SslSelectChannelConnector@0.0.0.0:8443
^C2015-01-15 12:34:18.476:INFO:oejs.Server:Graceful shutdown SslSelectChannelConnector@0.0.0.0:8443
2015-01-15 12:34:18.476:INFO:oejs.Server:Graceful shutdown SelectChannelConnector@0.0.0.0:8080
2015-01-15 12:34:18.477:INFO:oejs.Server:Graceful shutdown o.e.j.w.WebAppContext{/webapp-3.0-bare-spring,file:/tmp/jetty-0.0.0.0-8080-webapp-3.0-bare-spring.war-_webapp-3.0-bare-spring-any-/webapp/},/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare-spring.war
2015-01-15 12:34:19.534:INFO:oejsl.ELContextCleaner:javax.el.BeanELResolver purged
2015-01-15 12:34:19.534:INFO:oejsh.ContextHandler:stopped o.e.j.w.WebAppContext{/webapp-3.0-bare-spring,file:/tmp/jetty-0.0.0.0-8080-webapp-3.0-bare-spring.war-_webapp-3.0-bare-spring-any-/webapp/},/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare-spring.war

The test case:

(From org.eclipse.demo.MyAppInitializer): Initialized at: 2015-01-15T12:33:36-0700
(From servlet): Thu Jan 15 12:34:12 MST 2015
$




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

On Thu, Jan 15, 2015 at 12:24 PM, Nir Barel <nirba@xxxxxxxxxxxxxx> wrote:
Hi

Well it doesn't work for spring... Anyone know what is missing?

Sent securely from my iPad

From: Joakim Erdfelt
Sent: Thursday, January 15, 2015 at 21:23:27
To: Nir Barel
Cc: jetty-users@xxxxxxxxxxx

Subject: Re: [jetty-users] Jetty 8 standalone and Servlet 3.0 without web.xml

You didn't say spring, so I went with standard Servlet 3.0 behavior.

The source for TimeServlet.

package org.eclipse.demo;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
@WebServlet(urlPatterns="/time")
public class TimeServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        resp.setContentType("text/plain");
        resp.getWriter().println(new Date());
    }
}

Its a rather simple class.



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

On Thu, Jan 15, 2015 at 11:39 AM, Nir Barel <nirba@xxxxxxxxxxxxxx> wrote:
Hi

You use @WebServlet annotation and not spring WebApplicationInitializer that doesn't use it as I understand from their docs.

I still don't understand how jetty should start spring framework just by searching for WebApplicationInitializer classes??

Can you share the code of TimeServlet?

Sent securely from my iPad

From: Joakim Erdfelt
Sent: Thursday, January 15, 2015 at 19:55:48
To: JETTY user mailing list
Subject: Re: [jetty-users] Jetty 8 standalone and Servlet 3.0 without web.xml

It works here ...

$ jar -tvf webapps/webapp-3.0-bare.war 
     0 Thu Jan 15 10:42:14 MST 2015 META-INF/
   131 Thu Jan 15 10:42:14 MST 2015 META-INF/MANIFEST.MF
     0 Thu Jan 15 10:42:14 MST 2015 WEB-INF/
     0 Thu Jan 15 10:42:14 MST 2015 WEB-INF/classes/
     0 Thu Jan 15 10:42:14 MST 2015 WEB-INF/classes/org/
     0 Thu Jan 15 10:42:14 MST 2015 WEB-INF/classes/org/eclipse/
     0 Thu Jan 15 10:42:14 MST 2015 WEB-INF/classes/org/eclipse/demo/
  1055 Thu Jan 15 10:42:14 MST 2015 WEB-INF/classes/org/eclipse/demo/TimeServlet.class
  3756 Thu Jan 15 10:42:06 MST 2015 META-INF/maven/org.eclipse.jetty.demo/webapp-3.0-bare/pom.xml
   136 Thu Jan 15 10:42:14 MST 2015 META-INF/maven/org.eclipse.jetty.demo/webapp-3.0-bare/pom.properties

Running the server :

2015-01-15 10:51:57.553:INFO:oejs.Server:jetty-8.1.16.v20140903
2015-01-15 10:51:57.568:INFO:oejdp.ScanningAppProvider:Deployment monitor /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps at interval 1
2015-01-15 10:51:57.573:INFO:oejd.DeploymentManager:Deployable added: /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare.war
2015-01-15 10:51:57.600:INFO:oejw.WebInfConfiguration:Extract jar:file:/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare.war!/ to /tmp/jetty-0.0.0.0-8080-webapp-3.0-bare.war-_webapp-3.0-bare-any-/webapp
2015-01-15 10:51:58.038:INFO:oejdp.ScanningAppProvider:Deployment monitor /home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/contexts at interval 1
2015-01-15 10:51:58.052:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
2015-01-15 10:51:58.194:INFO:oejus.SslContextFactory:Enabled Protocols [SSLv2Hello, TLSv1, TLSv1.1, TLSv1.2] of [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2]
2015-01-15 10:51:58.197:INFO:oejs.AbstractConnector:Started SslSelectChannelConnector@0.0.0.0:8443
^C
2015-01-15 10:52:24.953:INFO:oejs.Server:Graceful shutdown SslSelectChannelConnector@0.0.0.0:8443
2015-01-15 10:52:24.953:INFO:oejs.Server:Graceful shutdown SelectChannelConnector@0.0.0.0:8080
2015-01-15 10:52:24.953:INFO:oejs.Server:Graceful shutdown o.e.j.w.WebAppContext{/webapp-3.0-bare,file:/tmp/jetty-0.0.0.0-8080-webapp-3.0-bare.war-_webapp-3.0-bare-any-/webapp/},/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare.war
2015-01-15 10:52:26.012:INFO:oejsl.ELContextCleaner:javax.el.BeanELResolver purged
2015-01-15 10:52:26.012:INFO:oejsh.ContextHandler:stopped o.e.j.w.WebAppContext{/webapp-3.0-bare,file:/tmp/jetty-0.0.0.0-8080-webapp-3.0-bare.war-_webapp-3.0-bare-any-/webapp/},/home/joakim/jetty-distros/jetty-distribution-8.1.16.v20140903/webapps/webapp-3.0-bare.war

Testing the specified @WebServlet ...

Thu Jan 15 10:52:19 MST 2015
$


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

On Wed, Jan 14, 2015 at 1:57 AM, Nir Barel <nirba@xxxxxxxxxxxxxx> wrote:

Hi,

 

I am trying to run Jetty 8 standalone ( not embedded ) and to use the servlet 3.0 code configuration capabilities using WebApplicationInitializer

When I deploy my war ( includes servlet 3.0 APIs ) the jetty choose to use the defaultweb.xml

that configured to use servlet 2.5 and therefore it doesn’t call my WebApplicationInitializer class.

 

Does it supported for not embedded jetty?

How can I tell jetty not to use web.xml or defaultweb.xml at all?

 

 

From the jetty debug log:

 

2015-01-14 10:54:24,722 DEBUG org.eclipse.jetty.webapp.WebInfConfiguration.unpack:508 [main] - webapp=file:/var/log/opt/tmp/jetty-127.0.0.1-8443-web.war-_web-any-/webapp/

2015-01-14 10:54:24,737 DEBUG org.eclipse.jetty.webapp.WebAppContext.preConfigure:456 [main] - preConfigure o.e.j.w.WebAppContext{/web,file:/var/log/opt/tmp/jetty-127.0.0.1-8443-web.war-_web-any-/webapp/},/opt

/webapps/web.war with org.eclipse.jetty.webapp.WebXmlConfiguration@6dc0d731

2015-01-14 10:54:24,766 DEBUG org.eclipse.jetty.webapp.WebDescriptor.processVersion:207 [main] - jar:file:/opt/jetty/lib/jetty-webapp-8.1.12.v20130726.jar!/org/eclipse/jetty/webapp/webdefault.xml: Calculated metadatacomplete =

True with version=2.5

2015-01-14 10:54:24,767 DEBUG org.eclipse.jetty.webapp.WebXmlConfiguration.findWebXml:114 [main] - No WEB-INF/web.xml in /opt/webapps/web.war. Serving files and default/dynamic servlets only

2015-01-14 10:54:24,767 DEBUG org.eclipse.jetty.webapp.WebAppContext.preConfigure:456 [main] - preConfigure o.e.j.w.WebAppContext{/web,file:/var/log/opt/tmp/jetty-127.0.0.1-8443-web.war-_web-any-/webapp/},/opt

/webapps/web.war with org.eclipse.jetty.webapp.MetaInfConfiguration@6357be97

 

 

 

 


_______________________________________________
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



Email secured by Check Point




Email secured by Check Point.



Back to the top