01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
20:
21: import javax.servlet.ServletConfig;
22: import javax.servlet.ServletException;
23: import javax.servlet.http.HttpServlet;
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: public class HttpBridgeServlet extends HttpServlet {
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 config) throws ServletException {
45: super .init(config);
46: if (processor == null) {
47: processor = (HttpProcessor) getServletContext()
48: .getAttribute("processor");
49: if (processor == null) {
50: throw new ServletException(
51: "No binding property available on the servlet context");
52: }
53: }
54: }
55:
56: protected void doGet(HttpServletRequest request,
57: HttpServletResponse response) throws ServletException,
58: IOException {
59: try {
60: getProcessor().process(request, response);
61: } catch (IOException e) {
62: throw e;
63: } catch (ServletException e) {
64: throw e;
65: } catch (RuntimeException e) {
66: throw e;
67: } catch (Exception e) {
68: throw new ServletException("Failed to process request: "
69: + e, e);
70: }
71: }
72:
73: protected void doPost(HttpServletRequest request,
74: HttpServletResponse response) throws ServletException,
75: IOException {
76: try {
77: getProcessor().process(request, response);
78: } catch (IOException e) {
79: throw e;
80: } catch (ServletException e) {
81: throw e;
82: } catch (RuntimeException e) {
83: throw e;
84: } catch (Exception e) {
85: throw new ServletException("Failed to process request: "
86: + e, e);
87: }
88: }
89:
90: }
|