1 17 package org.apache.servicemix.components.http; 18 19 import org.apache.servicemix.components.util.ComponentSupport; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import javax.servlet.ServletException ; 24 import javax.jbi.JBIException; 25 import javax.jbi.messaging.NormalizedMessage; 26 import java.io.IOException ; 27 import java.io.PrintWriter ; 28 29 32 public abstract class HttpBindingSupport extends ComponentSupport implements HttpBinding { 33 protected static final int BAD_REQUEST_STATUS_CODE = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 34 private HttpMarshaler marshaler; 35 36 public HttpMarshaler getMarshaler() { 37 if (marshaler == null) { 38 marshaler = createMarshaler(); 39 } 40 return marshaler; 41 } 42 43 public void setMarshaler(HttpMarshaler marshaler) { 44 this.marshaler = marshaler; 45 } 46 47 public abstract void process(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException , 48 JBIException; 49 50 56 protected HttpMarshaler createMarshaler() { 57 return new HttpMarshaler(); 58 } 59 60 protected void outputException(HttpServletResponse response, Exception e) throws IOException { 61 response.setStatus(BAD_REQUEST_STATUS_CODE); 62 PrintWriter writer = response.getWriter(); 63 writer.println("Request failed with error: " + e); 64 e.printStackTrace(writer); 65 } 66 } 67 | Popular Tags |