01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.test.servlet;
18:
19: import java.io.IOException;
20: import java.io.PrintStream;
21: import java.lang.reflect.Method;
22: import javax.servlet.ServletException;
23: import javax.servlet.ServletOutputStream;
24: import javax.servlet.http.HttpServlet;
25: import javax.servlet.http.HttpServletRequest;
26: import javax.servlet.http.HttpServletResponse;
27: import javax.xml.ws.WebServiceRef;
28:
29: import junit.framework.Assert;
30:
31: public class WebserviceServlet extends HttpServlet {
32: @WebServiceRef
33: private HelloPojo helloPojo;
34:
35: @WebServiceRef
36: private HelloEjb helloEjb;
37:
38: protected void service(HttpServletRequest request,
39: HttpServletResponse response) throws ServletException,
40: IOException {
41: response.setContentType("text/plain");
42: ServletOutputStream out = response.getOutputStream();
43: PrintStream printStream = new PrintStream(out);
44:
45: String methodName = request.getParameter("method");
46: if (methodName == null) {
47: testAll(printStream);
48: } else {
49: try {
50: Method method = getClass().getMethod(methodName);
51: method.invoke(this );
52: } catch (Throwable e) {
53: // response.setStatus(580);
54: printStream.println("FAILED");
55: e.printStackTrace(printStream);
56: }
57: }
58: printStream.flush();
59: }
60:
61: public void testAll(PrintStream printStream) {
62: for (Method method : EjbServlet.class.getMethods()) {
63: if (!method.getName().startsWith("invoke"))
64: continue;
65:
66: try {
67: method.invoke(this );
68: printStream.println(method.getName() + " PASSED");
69: } catch (Throwable e) {
70: printStream.println(method.getName() + " FAILED");
71: e.printStackTrace(printStream);
72: printStream.flush();
73: }
74: printStream.println();
75: }
76: }
77:
78: public void invokePojoWebservice() {
79: Assert.assertEquals("Hello Bob from Pojo Webservice!",
80: helloPojo.hello("Bob"));
81: }
82:
83: public void invokeEjbWebservice() {
84: Assert.assertEquals("Hello Bob from EJB Webservice!", helloEjb
85: .hello("Bob"));
86: }
87: }
|