Update of /cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-web/src/test/java/org/xdoclet/testapp/web In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9417/src/test/java/org/xdoclet/testapp/web Added Files: AbstractBaseTag.java AbstractFilter.java DummyServletRequestListener.java FakeFilter.java FakeListener.java FakeServlet.java SecondFilter.java SimpleListener.java SimpleTag.java SimpleVelocityServlet.java SuperFilter.java TaglessFilter.java TaglessListener.java TestServletContextListener.java TestSessionListener.java ThirdFilter.java TimerFilter.java Log Message: fix for XDP-184 ( Thanks Ulrich ) test coverage for this improvement m, as well reworking of test classes to get rid of dependency to testapp-web --- NEW FILE: AbstractBaseTag.java --- package org.xdoclet.testapp.web; import javax.servlet.jsp.tagext.TagSupport; public class AbstractBaseTag extends TagSupport { String blam; /** * @jsp.attribute * @return */ public String getBlam() { return blam; } public void setBlam(String blam) { this.blam = blam; } } --- NEW FILE: ThirdFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import java.io.IOException; /** * A third filter class, to test order of the filters. * This one has no name nor order attribute, it will be sorted last. * * @web.filter * name="ThirdFilter" * display-name="Third Filter" * description="My 3rd filter is really cool" * * @web.filter-mapping * servlet-name="/third" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class ThirdFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { } public void init(FilterConfig filterConfig) throws ServletException { } } --- NEW FILE: SimpleVelocityServlet.java --- package org.xdoclet.testapp.web; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import java.io.IOException; /** * Simple Velocity Servlet. This servlet illustrates that your servlet can be any * subclass of HttpServlet, as long as all the classes * in the hierarchy (and any classes they depend on) are on the classpath. * * @web.servlet * display-name="Simple Velocity Servlet" * load-on-startup="1" * run-as="TestRole" * name="SimpleVelocityServlet" * description="This is a description for the simple Velocity servlet" * * @web.servlet-init-param * name="param1" * value="value1" * description="This is a description for the 1st init-param of the simple Velocity servlet" * * @web.servlet-init-param * name="param2" * value="value2" * * @web.servlet-mapping * url-pattern="/simple/*" * * @web.resource-ref * name="jdbc/EmployeeAppDB" * auth="Container" * description="Test resource reference" * type="javax.sql.DataSource" * scope="Shareable" * jndi-name="test jndi??" * * @web.resource-env-ref * name="jms/StockQueue" * type="javax.jms.Queue" * description="Test resource env ref" * * @web.env-entry * name="TestEnvName" * type="java.lang.String" * value="testString" * description="a test string for env entry!?" * * @web.security-role * role-name="TestRole" * description="A description for the test role" * * @web.security-role * role-name="AnotherRole" * * @web.security-role-ref * role-name="LinkedTestRole" * role-link="TestRole" * description="A description for the test link role" * * @web.security-role-ref * role-name="YetAnotherRole" * role-link="AnotherRole" * * @web.ejb-ref * name="Account" * description="A test reference to the Account EJB" * home="test.interfaces.AccountHome" * link="Account" * remote="test.interfaces.Account" * type="Entity" * * @web.ejb-local-ref * name="Dummy" * description="A test ref to the local Dummy Session Bean" * home="test.interfaces.DummyLocalHome" * link="Dummy" * local="test.interfaces.DummyLocal" * type="Session" * * @jboss.resource-ref * jndi-name="queue/A" * res-ref-name="Queue" * * @jboss.ejb-ref-jndi * jndi-name="ejb/bank/Account" * ref-name="Account" * */ public class SimpleVelocityServlet extends HttpServlet { /** * Called by the server (via the service method) to allow a servlet to handle a POST request. * The HTTP POST method allows the client to send data of unlimited length to the Web server * a single time and is useful when posting information such as credit card numbers. */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // just print Hi! response.getWriter().println("Hi!"); } } --- NEW FILE: SimpleTag.java --- package org.xdoclet.testapp.web; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; import java.io.IOException; import java.util.Date; /** * Simple JSP tag. * * @jsp.tag name="simple" * display-name="SimpleTag" * body-content="empty" * description="Simple JSP tag." * @jsp.variable name-given="date" * class="java.util.Date" * declare="true" * scope="AT_BEGIN" * @jsp.variable name-given="var" */ public class SimpleTag extends AbstractBaseTag { private String action = null; private Integer thingy = new Integer(-1); /** * Sets the action attribute. This is included in the tld file. * * TODO : check if the @jsp could be on get method or how it was handled in xdoclet1 * * @jsp.attribute * description="The action attribute defines the dummy action to take with this dummy tag." * required="true" * rtexprvalue="true" */ public void setAction(String action) { this.action = action; } /** * Just another dummy example that will use default values * @jsp.attribute * type=java.lang.Integer */ public void setThingy(Integer thingy) { this.thingy = thingy; } /** * Process the start tag for this instance. */ public int doStartTag() throws JspTagException { try { JspWriter out = pageContext.getOut(); out.print("Simple tag started with action: " + action); pageContext.setAttribute("date", new Date()); pageContext.setAttribute("var", "<" + thingy + ">"); } catch (IOException ex) { throw new JspTagException("Could not write tag content: " + ex.getMessage()); } return EVAL_BODY_INCLUDE; } /** * Process the end tag. This method will be called on all Tag objects. */ public int doEndTag() throws JspTagException { try { JspWriter out = pageContext.getOut(); out.print("Simple tag ended."); } catch (IOException ex) { throw new JspTagException("Could not write at end tag: " + ex.getMessage()); } return EVAL_PAGE; } } --- NEW FILE: AbstractFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; import javax.servlet.FilterConfig; import javax.servlet.ServletException; /** * Just like the SuperFilter, we don't want an abstract filter to be in the * generated web.xml * (This one doesn't implemented the doFilter method. * * @web.filter * display-name="Abstract Filter" * name="AbstractFilter" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public abstract class AbstractFilter implements Filter { public void destroy() { // do some stuff } public void init(FilterConfig filterConfig) throws ServletException { // do some other stuff } } --- NEW FILE: SecondFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import java.io.IOException; /** * A second filter class, to test order of the filters. * This one has no order parameter, it will be sorted with it's name attribute. * * @web.filter * display-name="Second Filter" * name="SecondFilter" * order="2" * icon="icon2.gif" * * @web.filter-mapping * url-pattern="/second" * * @web.filter-mapping * url-pattern="/other/mapping" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class SecondFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { } public void init(FilterConfig filterConfig) throws ServletException { } } --- NEW FILE: SuperFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; /** * An interface extending the Filter interface. * This is probably most useless, but anyway, just in case someone puts web.filter * tags in an interface, we wouldn't we it to appear in the generated web.xml * * @web.filter * display-name="Super Filter" * name="SuperFilter" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public interface SuperFilter extends Filter { } --- NEW FILE: FakeServlet.java --- package org.xdoclet.testapp.web; /** * This fake servlet serves as testcase to make sure the WebPlugin doesn't generate anything * if a class containing @web tags is not an implementation of Servlet * * @web.servlet * name="FakeServlet" * display-name="Fake Servlet" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class FakeServlet { } --- NEW FILE: TestServletContextListener.java --- package org.xdoclet.testapp.web; import javax.servlet.ServletContextAttributeEvent; import javax.servlet.ServletContextAttributeListener; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; /** * Implements all the 2.3 listeners not related to sessions. * * TODO: implement ServletRequestAttributeListener & ServletRequestListener when we get servlet-2.4.jar * * @web.listener * order="2" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class TestServletContextListener implements ServletContextAttributeListener, ServletContextListener { public void attributeAdded(ServletContextAttributeEvent event) { } public void attributeRemoved(ServletContextAttributeEvent event) { } public void attributeReplaced(ServletContextAttributeEvent event) { } public void contextDestroyed(ServletContextEvent event) { } public void contextInitialized(ServletContextEvent event) { } } --- NEW FILE: TaglessFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import java.io.IOException; /** * Let's make sure nothing is generated for filters that are not tagged. * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class TaglessFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { } public void init(FilterConfig filterConfig) throws ServletException { } } --- NEW FILE: DummyServletRequestListener.java --- package org.xdoclet.testapp.web; import javax.servlet.ServletRequestEvent; import javax.servlet.ServletRequestListener; /** * @web.listener * * @author greg * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class DummyServletRequestListener implements ServletRequestListener { public void requestInitialized(ServletRequestEvent servletRequestEvent) { System.out.println("requestInitialized"); } public void requestDestroyed(ServletRequestEvent servletRequestEvent) { System.out.println("requestDestroyed"); } } --- NEW FILE: FakeFilter.java --- package org.xdoclet.testapp.web; /** * * Let's make sure nothing is generated for classes that have filter tags but * are not implementations of javax.servlet.filter * * @web.filter * display-name="Fake Filter" * name="FakeFilter" * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class FakeFilter { public void someDummyMethod() { System.out.println("oh no!"); } } --- NEW FILE: FakeListener.java --- package org.xdoclet.testapp.web; /** * A fake class that has a web.listener tag but is not actually implementing * the Filter interface * * @web.listener * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class FakeListener { } --- NEW FILE: SimpleListener.java --- package org.xdoclet.testapp.web; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; /** * Simple context listener, prints changes to the console. * * <p>A ServletContextListener recieves notifications about changes to the servlet context of the web * application they are part of. NOTE: this is a Servlet 2.3 only feature.</p> * * <p>A HttpSessionListener receives notifications about changes to the list of active sessions in * a web application. NOTE: this is a Servlet 2.3 only feature.</p> * * @web.listener * * @author <a href="mailto:you...@yo...">you...@yo...</a> */ public final class SimpleListener implements ServletContextListener, HttpSessionListener { /** Constructs a new SimpleListener. */ public SimpleListener() { } /** Notification that the web application is ready to process requests. */ public void contextInitialized(ServletContextEvent sce) { sce.getServletContext().log("The servlet context has been initialized, the web application is ready to process requests."); } /** Notification that the servlet context is about to be shut down. */ public void contextDestroyed(ServletContextEvent sce) { sce.getServletContext().log("The servlet context is about to be shut down."); } /** Notification that a session was created. */ public void sessionCreated(HttpSessionEvent hse) { HttpSession session = hse.getSession(); // session.getServletContext().log("A session was created, id: " + session.getId()); } /** Notification that a session was invalidated. */ public void sessionDestroyed(HttpSessionEvent hse) { HttpSession session = hse.getSession(); // session.getServletContext().log("A session was invalidated, id: " + session.getId()); } } --- NEW FILE: TimerFilter.java --- package org.xdoclet.testapp.web; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import java.io.IOException; /** * Timer filter that logs the request processing time in milliseconds to the console. * * <p>A filter is an object that performs filtering tasks on either the request to a resource * (a servlet or static content), or on the response from a resource, or both.</p> * * <p>For more information on filters, check the <a href="http://java.sun.com/products/servlet/2.3/javadoc/">javadoc</a> * or read the <a href="http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters_p.html">Filter code with Servlet 2.3 model</a> * article at <a href="http://www.javaworld.com">JavaWorld</a>.</p> * * @web.filter * display-name="Timer Filter" * name="TimerFilter" * order="1" * icon="iconOne.gif" * description="The description of the TimerFilter" * * @web.filter-init-param * name="param1" * value="value1" * * @web.filter-init-param * name="param2" * value="value2" * description="the second parameter to the Timer Filter" * * @web.filter-mapping * url-pattern="*.xml" * * @author <a href="mailto:you...@yo...">you...@yo...</a> */ public class TimerFilter implements Filter { /** * A filter configuration object used by a servlet container used to pass information to * a filter during initialization. This is set in the <code>init(FilterConfig config)</code> method. */ private FilterConfig config = null; /** Called by the web container to indicate to a filter that it is being placed into service. */ public void init(FilterConfig config) throws ServletException { this.config = config; } /** Called by the web container to indicate to a filter that it is being taken out of service. */ public void destroy() { config = null; } /** * Logs the time it took in milliseconds to process the request. * * <p>The <code>doFilter</code> method of the Filter is called by the container each time a * request/response pair is passed through the chain due to a client request for a * resource at the end of the chain. */ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { long before = System.currentTimeMillis(); // pass the request and response to the filter chain chain.doFilter(req, res); long after = System.currentTimeMillis(); String name = ""; if (req instanceof HttpServletRequest) name = ((HttpServletRequest) req).getRequestURI(); // log the difference in time, check the console for output config.getServletContext().log(name + ": " + (after - before) + "ms"); } } --- NEW FILE: TestSessionListener.java --- package org.xdoclet.testapp.web; import javax.servlet.http.HttpSessionActivationListener; import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; /** * Implements all the servlet 2.3 listeners related to sessions. * * @web.listener * order=1 * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class TestSessionListener implements HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionListener { public void sessionDidActivate(HttpSessionEvent event) { } public void sessionWillPassivate(HttpSessionEvent event) { } public void attributeAdded(HttpSessionBindingEvent event) { } public void attributeRemoved(HttpSessionBindingEvent event) { } public void attributeReplaced(HttpSessionBindingEvent event) { } public void valueBound(HttpSessionBindingEvent event) { } public void valueUnbound(HttpSessionBindingEvent event) { } public void sessionCreated(HttpSessionEvent event) { } public void sessionDestroyed(HttpSessionEvent event) { } } --- NEW FILE: TaglessListener.java --- package org.xdoclet.testapp.web; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; /** * A listener that actually implements ServletContextListener * but has no web.listener tag. Should appear in the generated web.xml * * @author <a href="mailto:gre...@fr...">Grégory Joseph</a> * @author $Author: ko5tik $ (last edit) * @version $Revision: 1.1 $ */ public class TaglessListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent event) { } public void contextInitialized(ServletContextEvent event) { } } |