KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > HttpBridgeServlet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.http;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.ServletConfig JavaDoc;
22 import javax.servlet.ServletException JavaDoc;
23 import javax.servlet.http.HttpServlet JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 public class HttpBridgeServlet extends HttpServlet JavaDoc {
28
29     /**
30      * Generated serial version UID
31      */

32     private static final long serialVersionUID = -7995806514300732777L;
33     
34     private HttpProcessor processor;
35
36     public HttpProcessor getProcessor() {
37         return processor;
38     }
39
40     public void setProcessor(HttpProcessor processor) {
41         this.processor = processor;
42     }
43
44     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc {
45         super.init(config);
46         if (processor == null) {
47             processor = (HttpProcessor) getServletContext().getAttribute("processor");
48             if (processor == null) {
49                 throw new ServletException JavaDoc("No binding property available on the servlet context");
50             }
51         }
52     }
53
54     
55     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
56         try {
57             getProcessor().process(request, response);
58         } catch (IOException JavaDoc e) {
59             throw e;
60         } catch (ServletException JavaDoc e) {
61             throw e;
62         } catch (RuntimeException JavaDoc e) {
63             throw e;
64         } catch (Exception JavaDoc e) {
65             throw new ServletException JavaDoc("Failed to process request: " + e, e);
66         }
67     }
68
69     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
70         try {
71             getProcessor().process(request, response);
72         } catch (IOException JavaDoc e) {
73             throw e;
74         } catch (ServletException JavaDoc e) {
75             throw e;
76         } catch (RuntimeException JavaDoc e) {
77             throw e;
78         } catch (Exception JavaDoc e) {
79             throw new ServletException JavaDoc("Failed to process request: " + e, e);
80         }
81     }
82
83 }
84
Popular Tags