1 23 24 package com.sun.enterprise.appclient.jws; 25 26 import javax.servlet.http.HttpServlet ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 import javax.servlet.RequestDispatcher ; 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletContext ; 32 import javax.servlet.ServletException ; 33 34 35 48 public class JWSAdHocServlet extends HttpServlet { 49 50 51 public static final String CONTEXT_ROOT_PARAMETER_NAME = "context-root"; 52 53 54 public static final String CATEGORY_PARAMETER_NAME = "category"; 55 56 57 private ServletContext jwsAppContext = null; 58 59 60 private RequestDispatcher systemWebAppDispatcher = null; 61 62 63 private String targetContextRoot = null; 64 65 66 private String category = null; 67 68 69 public JWSAdHocServlet() { 70 } 71 72 78 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { 79 83 JWSAdHocServletRequestWrapper wrappedRequest = new JWSAdHocServletRequestWrapper(request, targetContextRoot, category); 84 try { 85 getJWSRequestDispatcher().forward(wrappedRequest, response); 86 } catch (Throwable thr) { 87 throw new ServletException ("Error dispatching request to Java Web Start app client application", thr); 88 } 89 } 90 91 94 public void init() { 95 ServletConfig config = getServletConfig(); 96 97 targetContextRoot = config.getInitParameter(CONTEXT_ROOT_PARAMETER_NAME); 98 category = config.getInitParameter(CATEGORY_PARAMETER_NAME); 99 } 100 101 105 private ServletContext getJWSAppContext() { 106 if (jwsAppContext == null) { 107 String uri = NamingConventions.webAppURI(); 108 jwsAppContext = getServletContext().getContext(uri); 109 } 110 return jwsAppContext; 111 } 112 113 117 private RequestDispatcher getJWSRequestDispatcher() { 118 if (systemWebAppDispatcher == null) { 119 String uri = NamingConventions.webAppURI(); 120 WebPath webPath = new WebPath(uri); 121 122 ServletContext sc = getServletContext().getContext(webPath.contextRoot()); 123 String servletContextName = sc.getServletContextName(); 124 systemWebAppDispatcher = sc.getRequestDispatcher(webPath.path() + "/" + category + targetContextRoot); 125 } 126 return systemWebAppDispatcher; 127 } 128 } 129 | Popular Tags |