01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package com.noelios.restlet.ext.servlet;
20:
21: import java.util.List;
22:
23: import org.restlet.Client;
24: import org.restlet.Context;
25: import org.restlet.data.Protocol;
26: import org.restlet.data.Request;
27: import org.restlet.data.Response;
28: import org.restlet.util.Helper;
29:
30: /**
31: * Connector acting as a WAR client for a Servlet Application. It internally
32: * uses one of the available connectors registered with the current Restlet
33: * implementation.<br/> <br/>
34: *
35: * Here is an example of WAR URI that can be resolved by this client:
36: * "war:///WEB-INF/web.xml"
37: *
38: * @author Jerome Louvel (contact@noelios.com)
39: */
40: public class ServletWarClient extends Client {
41: /** The helper provided by the implementation. */
42: private Helper helper;
43:
44: /**
45: * Constructor.
46: *
47: * @param context
48: * The context.
49: */
50: public ServletWarClient(Context context,
51: javax.servlet.ServletContext servletContext) {
52: super (context, (List<Protocol>) null);
53: getProtocols().add(Protocol.WAR);
54: this .helper = new ServletWarClientHelper(this , servletContext);
55: }
56:
57: /**
58: * Returns the helper provided by the implementation.
59: *
60: * @return The helper provided by the implementation.
61: */
62: private Helper getHelper() {
63: return this .helper;
64: }
65:
66: /**
67: * Handles a call.
68: *
69: * @param request
70: * The request to handle.
71: * @param response
72: * The response to update.
73: */
74: public void handle(Request request, Response response) {
75: init(request, response);
76: getHelper().handle(request, response);
77: }
78:
79: /** Start callback. */
80: public void start() throws Exception {
81: super .start();
82: getHelper().start();
83: }
84:
85: /** Stop callback. */
86: public void stop() throws Exception {
87: getHelper().stop();
88: super.stop();
89: }
90:
91: }
|