KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > web > servlets > StandaloneENCAnnotationsServlet


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.web.servlets;
23
24 import java.io.IOException JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import java.util.Date JavaDoc;
27
28 import javax.annotation.Resource;
29 import javax.annotation.Resources;
30 import javax.ejb.EJB JavaDoc;
31 import javax.jms.Queue JavaDoc;
32 import javax.jms.QueueConnectionFactory JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServlet JavaDoc;
35 import javax.servlet.http.HttpServletRequest JavaDoc;
36 import javax.servlet.http.HttpServletResponse JavaDoc;
37 import javax.sql.DataSource JavaDoc;
38
39 import org.jboss.logging.Logger;
40 import org.jboss.test.web.mock.EntityHome;
41 import org.jboss.test.web.mock.StatelessSessionHome;
42 import org.jboss.test.web.mock.StatelessSessionLocalHome;
43
44 /** Tests of the server ENC naming context configured via annotations. This servlet has
45  * no dependencies on other ee component deployments as the env references are to mock
46  * objects. It does depend on a kernel beans deployment to setup the jndi bindings.
47  *
48  * @author Scott.Stark@jboss.org
49  * @version $Revision: 58438 $
50  */

51 @Resources({
52       @Resource(name="mail/DefaultMail", type=javax.mail.Session JavaDoc.class, mappedName="java:/Mail"),
53       @Resource(name="url/JBossHome", type=java.net.URL JavaDoc.class, mappedName="http://www.jboss.org"),
54       @Resource(name="mdr/ConsumesLink", type=javax.jms.Queue JavaDoc.class, mappedName="MockQueueA"),
55       @Resource(name="mdr/ProducesLink", type=javax.jms.Topic JavaDoc.class, mappedName="MockTopicA")
56 })
57 public class StandaloneENCAnnotationsServlet extends HttpServlet JavaDoc
58 {
59    private static final long serialVersionUID = 1;
60    private static final Logger log = Logger.getLogger(StandaloneENCAnnotationsServlet.class);
61
62    @Resource(name="jms/QueFactory", mappedName="java:/ConnectionFactory")
63    QueueConnectionFactory JavaDoc queueFactory;
64    @Resource(name="TestQueue", mappedName="MockQueueB")
65    Queue JavaDoc testQueue;
66    @Resource(name="mdr/ConsumesProducesJNDIName", mappedName="MockQueueA")
67    Queue JavaDoc refQueue;
68
69    @Resource(name="jdbc/DefaultDS", mappedName="java:/MockDS")
70    DataSource JavaDoc ds;
71    @EJB JavaDoc(name="ejb/bean3", beanInterface=StatelessSessionHome.class,
72          mappedName="jbosstest/ejbs/UnsecuredEJB")
73    StatelessSessionHome sshome;
74    @EJB JavaDoc(name="ejb/CtsBmp", beanInterface=EntityHome.class,
75          mappedName="jbosstest/ejbs/CtsBmp")
76    EntityHome entityHome;
77    @EJB JavaDoc(name="ejb/local/bean3", beanInterface=StatelessSessionLocalHome.class,
78          mappedName="jbosstest/ejbs/local/ENCBean1")
79    StatelessSessionLocalHome localHome;
80    @Resource(name="Ints/i0", mappedName="0")
81    int i0;
82    @Resource(name="Ints/i1", mappedName="1")
83    int i1;
84    @Resource(name="Floats/f0", mappedName="0.0")
85    float f0;
86    @Resource(name="Floats/f1", mappedName="1.1")
87    float f1;
88    @Resource(name="Strings/s0", mappedName="String0")
89    String JavaDoc s0;
90    @Resource(name="Strings/s1", mappedName="String1")
91    String JavaDoc s1;
92    @Resource(name="ejb/catalog/CatalogDAOClass", mappedName="com.sun.model.dao.CatalogDAOImpl")
93    String JavaDoc ejbName;
94
95    protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
96          throws ServletException JavaDoc, IOException JavaDoc
97    {
98       ENCTester tester = new ENCTester(log);
99       tester.testENC();
100
101       if( queueFactory == null )
102          throw new ServletException JavaDoc("queueFactory is not injected");
103       if( testQueue == null )
104          throw new ServletException JavaDoc("testQueue is not injected");
105       if( testQueue == null )
106          throw new ServletException JavaDoc("testQueue is not injected");
107
108       response.setContentType("text/html");
109       PrintWriter JavaDoc out = response.getWriter();
110       out.println("<html>");
111       out.println("<head><title>StandaloneENCAnnotationsServlet</title></head>");
112       out.println("<body>Tests passed<br>Time:" + new Date JavaDoc() + "</body>");
113       out.println("</html>");
114       out.close();
115    }
116
117    protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
118          throws ServletException JavaDoc, IOException JavaDoc
119    {
120       processRequest(request, response);
121    }
122
123    protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
124          throws ServletException JavaDoc, IOException JavaDoc
125    {
126       processRequest(request, response);
127    }
128
129 }
130
Popular Tags