01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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.ejb3.test.clusteredservice.servlets;
23:
24: import java.io.IOException;
25: import java.io.PrintWriter;
26:
27: import java.util.Properties;
28:
29: import javax.management.MBeanServer;
30: import javax.management.ObjectName;
31: import javax.naming.Context;
32: import javax.naming.InitialContext;
33: import javax.servlet.ServletException;
34: import javax.servlet.http.HttpServlet;
35: import javax.servlet.http.HttpServletRequest;
36: import javax.servlet.http.HttpServletResponse;
37:
38: import org.jboss.ejb3.test.clusteredservice.ServiceRemote;
39: import org.jboss.logging.Logger;
40:
41: /**
42: * @version <tt>$Revision: 60233 $</tt>
43: * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
44: */
45: public class EJBServlet extends HttpServlet {
46: private static final Logger log = Logger
47: .getLogger(EJBServlet.class);
48:
49: protected void processRequest(HttpServletRequest request,
50: HttpServletResponse response) throws ServletException,
51: IOException {
52: try {
53: ServiceRemote test = (ServiceRemote) getInitialContext()
54: .lookup("ServiceBean/remote");
55: test.remoteMethod();
56:
57: /* MBeanServer server = org.jboss.mx.util.MBeanServerLocator.locateJBoss();
58: ObjectName testerName = new ObjectName("default:service=service");
59: Object[] params = {};
60: String[] sig = {};
61: server.invoke(testerName, "", params, sig);*/
62: } catch (Exception e) {
63: e.printStackTrace();
64:
65: throw new ServletException(
66: "Failed to call ServiceBean through remote or local interfaces",
67: e);
68: }
69: response.setContentType("text/html");
70: PrintWriter out = response.getWriter();
71: out.println("<html>");
72: out.println("<head><title>EJBServlet</title></head>");
73: out.println("<body>Tests passed<br></body>");
74: out.println("</html>");
75: out.close();
76: }
77:
78: protected InitialContext getInitialContext() throws Exception {
79: Properties p = new Properties();
80: p.put(Context.INITIAL_CONTEXT_FACTORY,
81: "org.jnp.interfaces.NamingContextFactory");
82: p.put(Context.URL_PKG_PREFIXES,
83: "jboss.naming:org.jnp.interfaces");
84: p.put(Context.PROVIDER_URL, "localhost:1100");
85: return new InitialContext(p);
86: }
87:
88: protected void doGet(HttpServletRequest request,
89: HttpServletResponse response) throws ServletException,
90: IOException {
91: processRequest(request, response);
92: }
93:
94: protected void doPost(HttpServletRequest request,
95: HttpServletResponse response) throws ServletException,
96: IOException {
97: processRequest(request, response);
98: }
99: }
|