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.components.http;
18:
19: import org.apache.servicemix.jbi.container.SpringJBIContainer;
20: import org.springframework.context.ApplicationContext;
21: import org.springframework.web.context.support.WebApplicationContextUtils;
22:
23: import javax.servlet.ServletConfig;
24: import javax.servlet.ServletException;
25:
26: /**
27: * A Spring based HTTP Binding Servlet for ServiceMix which will
28: * lookup the JBI container and the HttpBinding to use from the Spring
29: * {@link ApplicationContext}
30: *
31: * @version $Revision: 426415 $
32: */
33: public class SpringBindingServlet extends BindingServlet {
34:
35: protected HttpBinding createHttpBinding(ServletConfig config)
36: throws ServletException {
37: ApplicationContext applicationContext = WebApplicationContextUtils
38: .getRequiredWebApplicationContext(getServletContext());
39:
40: String jbiName = config.getInitParameter("jbi");
41: if (jbiName == null) {
42: jbiName = "jbi";
43: }
44: String endpointName = config.getInitParameter("endpoint");
45: if (endpointName == null) {
46: throw new ServletException(
47: "You must configure a servlet config parameter of endpointRef");
48: }
49:
50: SpringJBIContainer jbi = (SpringJBIContainer) applicationContext
51: .getBean(jbiName);
52: if (jbi == null) {
53: throw new ServletException(
54: "Could not find the JBIContainer in the Spring application context for name: "
55: + jbiName);
56: }
57:
58: Object value = jbi.getBean(endpointName);
59: if (value == null) {
60: throw new ServletException(
61: "Could not find bean in the SpringJBIContainer for id: "
62: + endpointName);
63: }
64: if (value instanceof HttpBinding) {
65: return (HttpBinding) value;
66: } else {
67: throw new ServletException(
68: "The endpoint is not a HttpBinding: " + value);
69: }
70: }
71:
72: }
|