001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.aop.earwithwebinf.servlet;
023:
024: import java.io.IOException;
025: import java.io.PrintWriter;
026:
027: import javax.servlet.ServletException;
028: import javax.servlet.http.HttpServlet;
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031:
032: import org.jboss.test.aop.earwithwebinf.interceptor.EJBInterceptor;
033: import org.jboss.test.aop.earwithwebinf.interceptor.WebInterceptor;
034: import org.jboss.test.aop.earwithwebinf.webinf.classes.ClassesClass;
035: import org.jboss.test.aop.earwithwebinf.webinf.lib.LibClass;
036:
037: /**
038: *
039: * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
040: * @version $Revision: 1.1 $
041: */
042: public class EarExampleServlet extends HttpServlet {
043: public void service(HttpServletRequest request,
044: HttpServletResponse response) throws ServletException,
045: IOException {
046: try {
047: EJBInterceptor.invoked = false;
048: WebInterceptor.invoked = false;
049: ClassesClass classesClass = new ClassesClass();
050: if (EJBInterceptor.invoked)
051: throw new RuntimeException(
052: "Should not have invoked EJBInterceptor");
053: if (!WebInterceptor.invoked)
054: throw new RuntimeException(
055: "Should have invoked WebInterceptor");
056:
057: EJBInterceptor.invoked = false;
058: WebInterceptor.invoked = false;
059: String ret = classesClass.invokeEjb("Test");
060: if (!EJBInterceptor.invoked)
061: throw new RuntimeException(
062: "Should have invoked EJBInterceptor");
063: if (!WebInterceptor.invoked)
064: throw new RuntimeException(
065: "Should have invoked WebInterceptor");
066: if (!ret.equals("#Test#"))
067: throw new RuntimeException("Did not reach EJBLayer");
068:
069: EJBInterceptor.invoked = false;
070: WebInterceptor.invoked = false;
071: LibClass libClass = new LibClass();
072: if (EJBInterceptor.invoked)
073: throw new RuntimeException(
074: "Should not have invoked EJBInterceptor");
075: if (!WebInterceptor.invoked)
076: throw new RuntimeException(
077: "Should have invoked WebInterceptor");
078:
079: EJBInterceptor.invoked = false;
080: WebInterceptor.invoked = false;
081: ret = libClass.invokeEjb("Test");
082: if (!EJBInterceptor.invoked)
083: throw new RuntimeException(
084: "Should have invoked EJBInterceptor");
085: if (!WebInterceptor.invoked)
086: throw new RuntimeException(
087: "Should have invoked WebInterceptor");
088: if (!ret.equals("#Test#"))
089: throw new RuntimeException("Did not reach EJBLayer");
090:
091: //It worked
092: response.setContentType("text/html");
093: PrintWriter out = response.getWriter();
094: out.println("<html>");
095: out
096: .println("<head><title>EarExampleServlet</title></head>");
097: out.println("<body>Tests passed<br></body>");
098: out.println("</html>");
099: out.close();
100: } catch (Exception e) {
101: e.printStackTrace();
102:
103: StringBuffer err = new StringBuffer(e.getClass().getName()
104: + "\n");
105: err.append(e.getMessage() + "\n");
106:
107: StackTraceElement[] elements = e.getStackTrace();
108: for (int i = 0; i < elements.length; i++) {
109: err.append(elements[i].toString() + "\n");
110: }
111:
112: response.sendError(500, err.toString());
113: }
114: }
115:
116: }
|