01: /* ForwardServlet.java
02:
03: {{IS_NOTE
04:
05: Purpose:
06: Description:
07: History:
08: 90/12/13 11:30:35, Create, Tom M. Yeh.
09: }}IS_NOTE
10:
11: Copyright (C) 2001 Potix Corporation. All Rights Reserved.
12:
13: {{IS_RIGHT
14: This program is distributed under GPL Version 2.0 in the hope that
15: it will be useful, but WITHOUT ANY WARRANTY.
16: }}IS_RIGHT
17: */
18: package org.zkoss.web.servlet;
19:
20: import java.io.IOException;
21:
22: import javax.servlet.GenericServlet;
23: import javax.servlet.ServletRequest;
24: import javax.servlet.ServletResponse;
25: import javax.servlet.ServletException;
26:
27: import org.zkoss.lang.D;
28: import org.zkoss.util.logging.Log;
29:
30: import org.zkoss.web.servlet.http.Https;
31:
32: /**
33: * The servlet used to forward a request to another URL.
34: * The forward target is specified as init-param, so you might need to
35: * create and name one servlet for each target.
36: *
37: * <p>init-param:
38: *
39: * <dl>
40: * <dt>target</dt>
41: * <dd>The target URL.</dd>
42: * </dl>
43: *
44: * @author tomyeh
45: */
46: public class ForwardServlet extends GenericServlet {
47: private static final Log log = Log.lookup(ForwardServlet.class);
48:
49: /** The target URL. */
50: private String _target;
51:
52: public ForwardServlet() {
53: }
54:
55: //-- super --//
56: public void init() throws ServletException {
57: _target = getInitParameter("target");
58: if (_target == null || _target.length() == 0)
59: throw new ServletException(
60: "ForwardServlet requires the init param, target");
61: }
62:
63: public void service(ServletRequest request, ServletResponse response)
64: throws ServletException, IOException {
65: try {
66: final String uri = Https.locate(getServletContext(),
67: request, _target, null);
68: Https.forward(getServletContext(), request, response, uri,
69: null, 0);
70: } catch (Error ex) {
71: if (D.ON && log.debugable())
72: log.realCause(ex);
73: throw ex;
74: } catch (RuntimeException ex) {
75: if (D.ON && log.debugable())
76: log.realCause(ex);
77: throw ex;
78: }
79: }
80: }
|