001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.test;
017:
018: import java.io.IOException;
019: import java.io.PrintWriter;
020: import java.sql.Connection;
021:
022: import javax.jms.Queue;
023: import javax.jms.QueueConnection;
024: import javax.jms.QueueConnectionFactory;
025: import javax.naming.Context;
026: import javax.naming.InitialContext;
027: import javax.servlet.ServletException;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import javax.sql.DataSource;
031:
032: import org.apache.geronimo.test.local.TestLocal;
033: import org.apache.geronimo.test.local.TestLocalHome;
034: import org.apache.geronimo.test.remote.Test;
035: import org.apache.geronimo.test.remote.TestHome;
036: import org.apache.geronimo.test.ws.HelloWorld;
037: import org.apache.geronimo.test.ws.HelloWorldService;
038:
039: /**
040: * Servlet implementation class for Servlet: TomcatTestServlet
041: *
042: */
043: public class TomcatTestServlet extends javax.servlet.http.HttpServlet
044: implements javax.servlet.Servlet {
045: /* (non-Java-doc)
046: * @see javax.servlet.http.HttpServlet#HttpServlet()
047: */
048: public TomcatTestServlet() {
049: super ();
050: }
051:
052: /* (non-Java-doc)
053: * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
054: */
055: protected void doGet(HttpServletRequest request,
056: HttpServletResponse response) throws ServletException,
057: IOException {
058:
059: PrintWriter out = response.getWriter();
060: out
061: .println("<html><head><title>Sample application to check references</title></head></html>");
062: out.println("<body>");
063:
064: try {
065: Context ctx = new InitialContext();
066: TestHome result = (TestHome) ctx
067: .lookup("java:comp/env/ejb/TestBean");
068: //TestHome testHome = (TestHome) PortableRemoteObject.narrow(result, TestHome.class);
069: Test test = result.create();
070: String echo = test.echo("Test");
071: out
072: .println("<font align=Center face=\"Garamond\"> Check EJB Reference : Call to bean method returned ->"
073: + echo + " </font><br>");
074:
075: DataSource ds = (DataSource) ctx
076: .lookup("java:comp/env/jdbc/MyDataSource");
077: Connection con = ds.getConnection();
078: out
079: .println("<font align=Center face=\"Garamond\"> Check Resource Reference : Got Connection ->"
080: + con + " </font><br>");
081:
082: QueueConnectionFactory qcf = (QueueConnectionFactory) ctx
083: .lookup("java:comp/env/jms/DefaultActiveMQConnectionFactory");
084: QueueConnection qCon = qcf.createQueueConnection();
085: out
086: .println("<font align=Center face=\"Garamond\"> Check JMS Resource Reference : Got Queue Connection ->"
087: + qCon + " </font><br>");
088:
089: Queue q = (Queue) ctx
090: .lookup("java:comp/env/jms/SendReceiveQueue");
091: out
092: .println("<font align=Center face=\"Garamond\"> Check JMS Resource Env Reference : Got Queue ->"
093: + q.getQueueName() + " </font><br>");
094:
095: HelloWorldService hello = (HelloWorldService) ctx
096: .lookup("java:comp/env/service/HelloWorldService");
097: HelloWorld port = hello.getHelloWorld();
098: out
099: .println("<font align=Center face=\"Garamond\"> Check Service Reference : Called Web Service ->"
100: + port.getHelloWorld("Test")
101: + " </font><br>");
102:
103: TestLocalHome resultLocal = (TestLocalHome) ctx
104: .lookup("java:comp/env/ejb/TestLocalBean");
105: TestLocal testLocal = resultLocal.create();
106: String echoLocal = testLocal.echoLocal("Test");
107: out
108: .println("<font align=Center face=\"Garamond\"> Check EJB Local Reference : Call to bean method returned ->"
109: + echoLocal + " </font><br>");
110:
111: } catch (Exception e) {
112: e.printStackTrace();
113: }
114:
115: out.println("</body></html>");
116:
117: }
118:
119: /* (non-Java-doc)
120: * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
121: */
122: protected void doPost(HttpServletRequest request,
123: HttpServletResponse response) throws ServletException,
124: IOException {
125:
126: }
127: }
|