1 17 package org.apache.servicemix.components.http; 18 19 import javax.jbi.JBIException; 20 import javax.servlet.ServletConfig ; 21 import javax.servlet.ServletException ; 22 import javax.servlet.http.HttpServlet ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import java.io.IOException ; 27 28 33 public class BindingServlet extends HttpServlet { 34 35 private HttpBinding binding; 36 37 42 public HttpBinding getBinding() { 43 return binding; 44 } 45 46 public void setBinding(HttpBinding binding) { 47 this.binding = binding; 48 } 49 50 51 public void init(ServletConfig config) throws ServletException { 52 super.init(config); 53 if (binding == null) { 54 binding = (HttpBinding) getServletContext().getAttribute("binding"); 55 if (binding == null) { 56 binding = createHttpBinding(config); 57 } 58 if (binding == null) { 59 throw new ServletException ("No binding property available on the servlet context"); 60 } 61 } 62 } 63 64 65 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 66 try { 67 getBinding().process(request, response); 68 } 69 catch (JBIException e) { 70 throw new ServletException ("Failed to process JBI request: " + e, e); 71 } 72 } 73 74 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 75 try { 76 getBinding().process(request, response); 77 } 78 catch (JBIException e) { 79 throw new ServletException ("Failed to process JBI request: " + e, e); 80 } 81 } 82 83 protected HttpBinding createHttpBinding(ServletConfig config) throws ServletException { 84 return new HttpInOutBinding(); 86 } 87 88 } 89 | Popular Tags |