KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > http > SpringBindingServlet


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.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 JavaDoc;
24 import javax.servlet.ServletException JavaDoc;
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 JavaDoc config) throws ServletException JavaDoc {
36         ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
37         
38         String JavaDoc jbiName = config.getInitParameter("jbi");
39         if (jbiName == null) {
40             jbiName = "jbi";
41         }
42         String JavaDoc endpointName = config.getInitParameter("endpoint");
43         if (endpointName == null) {
44             throw new ServletException JavaDoc("You must configure a servlet config parameter of endpointRef");
45         }
46         
47         SpringJBIContainer jbi = (SpringJBIContainer) applicationContext.getBean(jbiName);
48         if (jbi == null) {
49             throw new ServletException JavaDoc("Could not find the JBIContainer in the Spring application context for name: " + jbiName);
50         }
51         
52         Object JavaDoc value = jbi.getBean(endpointName);
53         if (value == null) {
54             throw new ServletException JavaDoc("Could not find bean in the SpringJBIContainer for id: " + endpointName);
55         }
56         if (value instanceof HttpBinding) {
57             return (HttpBinding) value;
58         }
59         else {
60             throw new ServletException JavaDoc("The endpoint is not a HttpBinding: " + value);
61         }
62     }
63     
64
65 }
66
Popular Tags