1 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 33 public class SpringBindingServlet extends BindingServlet { 34 35 protected HttpBinding createHttpBinding(ServletConfig config) throws ServletException { 36 ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); 37 38 String jbiName = config.getInitParameter("jbi"); 39 if (jbiName == null) { 40 jbiName = "jbi"; 41 } 42 String endpointName = config.getInitParameter("endpoint"); 43 if (endpointName == null) { 44 throw new ServletException ("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 ("Could not find the JBIContainer in the Spring application context for name: " + jbiName); 50 } 51 52 Object value = jbi.getBean(endpointName); 53 if (value == null) { 54 throw new ServletException ("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 ("The endpoint is not a HttpBinding: " + value); 61 } 62 } 63 64 65 } 66 | Popular Tags |