1 18 package org.apache.beehive.netui.pageflow.xmlhttprequest; 19 20 import org.apache.beehive.netui.core.urls.URLRewriterService; 21 import org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptorContext; 22 import org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptor; 23 import org.apache.beehive.netui.pageflow.interceptor.Interceptors; 24 import org.apache.beehive.netui.pageflow.interceptor.InterceptorException; 25 import org.apache.beehive.netui.pageflow.interceptor.InterceptorChain; 26 import org.apache.beehive.netui.pageflow.internal.DefaultURLRewriter; 27 import org.apache.beehive.netui.util.logging.Logger; 28 29 import javax.servlet.http.HttpServlet ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.ServletContext ; 34 import java.io.IOException ; 35 import java.util.List ; 36 37 40 public class XmlHttpRequestServlet extends HttpServlet 41 { 42 private static final Logger logger = Logger.getInstance(XmlHttpRequestServlet.class); 43 44 public void init() throws ServletException 45 { 46 ServletContext ctxt = getServletContext(); 47 RequestInterceptorContext.init(ctxt); 48 RequestInterceptorContext.addInterceptor(ctxt, new ErrorCRI()); 50 } 51 52 public void doGet(HttpServletRequest request, 53 HttpServletResponse response) 54 throws IOException , ServletException 55 { 56 58 response.setContentType("text/xml"); 60 response.setHeader("Pragma", "No-cache"); 61 response.setHeader("Cache-Control", "no-cache"); 62 63 ServletContext ctxt = getServletContext(); 64 RequestInterceptorContext context = new RequestInterceptorContext(request, response, ctxt); 65 List interceptors = context.getRequestInterceptors(); 66 67 URLRewriterService.registerURLRewriter(0, request, new DefaultURLRewriter()); 69 70 try 71 { 72 Interceptors.doPreIntercept(context, interceptors); 73 } 74 catch (InterceptorException e) 75 { 76 throw new ServletException (e); 77 } 78 79 } 82 83 public void doPost(HttpServletRequest request, 84 HttpServletResponse response) 85 throws IOException , ServletException 86 { 87 doGet(request, response); 88 } 89 90 class ErrorCRI extends RequestInterceptor 91 { 92 public void preRequest(RequestInterceptorContext ctxt, InterceptorChain chain) throws InterceptorException 93 { 94 HttpServletRequest request = ctxt.getRequest(); 96 String cmd = request.getRequestURI(); 97 String ctxtPath = request.getContextPath(); 98 99 try { 101 cmd = cmd.substring(ctxtPath.length() + 1); 102 int idx = cmd.lastIndexOf('.'); 103 if (idx != -1) { 104 cmd = cmd.substring(0, idx); 105 } 106 107 if ("netuiError".equals(cmd)) { 108 String error = request.getParameter("error"); 109 logger.error("NetUI JavaScript Error:" + error); 110 System.err.println("NetUI JavaScript Error:" + error); 111 } 112 } 113 catch (RuntimeException e) { 114 logger.error("Runtime Error creating XmlRequestServlet Command:" + e.getClass().getName(),e); 115 } 116 117 chain.continueChain(); 118 } 119 120 public void postRequest(RequestInterceptorContext context, InterceptorChain chain) throws InterceptorException 121 { 122 chain.continueChain(); 123 } 124 } 125 } 126 | Popular Tags |