1 23 24 package com.sun.enterprise.tools.admingui; 25 26 import java.io.IOException ; 27 import javax.servlet.ServletConfig ; 28 import javax.servlet.ServletException ; 29 import javax.servlet.ServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpSession ; 33 34 import org.xml.sax.EntityResolver ; 35 36 import com.iplanet.jato.ModelTypeMap; 37 import com.iplanet.jato.CompleteRequestException; 38 import com.iplanet.jato.RequestContext; 39 import com.iplanet.jato.RequestContextImpl; 40 import com.iplanet.jato.RequestManager; 41 import com.iplanet.jato.view.View; 42 43 import com.sun.enterprise.tools.admingui.util.Util; 44 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 45 import com.sun.enterprise.tools.admingui.util.PreloadXML; 46 import com.sun.enterprise.tools.admingui.handlers.CommonHandlers; 47 import com.sun.enterprise.tools.jsfext.util.ClasspathEntityResolver; 48 import com.sun.enterprise.tools.guiframework.view.BaseServlet; 49 import com.sun.enterprise.tools.guiframework.view.descriptors.ViewDescriptor; 50 import com.sun.enterprise.tools.guiframework.view.event.ErrorEvent; 51 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 52 import com.sun.enterprise.tools.guiframework.view.ViewXMLEntityResolver; 53 import com.sun.enterprise.tools.guiframework.util.LogUtil; 54 55 import com.sun.web.ui.renderer.template.xml.XMLLayoutDefinitionManager; 56 57 import java.io.File ; 58 import java.io.UnsupportedEncodingException ; 59 import java.net.URL ; 60 import java.util.Enumeration ; 61 import java.util.logging.Handler ; 62 63 import com.sun.web.ui.common.CCPrivateConfiguration; 64 65 68 public class AdminGUIServlet extends BaseServlet { 69 70 private static final boolean debug = false; 71 72 public AdminGUIServlet() { 73 super(); 74 setDefaultHandlerName("TopFrameset"); 75 setEnforceStrictSessionTimeout(true); 76 setupConfig(); 77 78 CCPrivateConfiguration.setEntityResolver(new LockhartEntityResolver()); 80 ((XMLLayoutDefinitionManager) XMLLayoutDefinitionManager.getInstance()). 81 setEntityResolver(new ClasspathEntityResolver()); 82 } 83 84 96 protected void handleUncaughtException(ErrorEvent errorEvent) { 97 if (Util.isLoggableWARNING()) { 98 Util.logWARNING("Exception NOT handled!", errorEvent.getException()); 99 } 100 ViewDescriptor viewDesc = errorEvent.getCauseViewDescriptor(); 101 if (Util.isLoggableINFO()) { 102 if (viewDesc != null) { 103 Util.logINFO("Problem near ViewDescriptor: '"+viewDesc.getName()+"'"); 104 } 105 } 106 String cause = errorEvent.getCauseMessage(); 107 if (Util.isLoggableINFO()) { 108 if (cause != null) { 109 Util.logINFO(cause); 110 } 111 } 112 if (Util.isLoggableINFO()) { 113 Util.logINFO(errorEvent.getRegularTrace()); 114 } 115 if (viewDesc != null) { 116 while (viewDesc.getParent() != null) { 118 viewDesc = viewDesc.getParent(); 119 } 120 RequestContext ctx = RequestManager.getRequestContext(); 122 String redirName = null; 123 View view = null; 124 try { 125 view = viewDesc.getView(ctx); 126 while (view.getParent() != null) { 127 view = view.getParent(); 128 } 129 redirName = view.getName(); 130 } catch (Exception ex) { 131 if (Util.isLoggableWARNING()) { 132 Util.logWARNING(ex); 133 } 134 redirName = viewDesc.getName(); 135 } 136 137 try { 139 ServletRequest req = ctx.getRequest(); 140 if (req.getAttribute(UNCAUGHT_REDIR) != null) { 141 return; 143 } 144 ctx.getRequest().setAttribute(UNCAUGHT_REDIR, "true"); 145 ctx.getResponse().sendRedirect(redirName); 146 } catch (Throwable ex) { 147 if (Util.isLoggableWARNING()) { 148 Util.logWARNING(ex); 149 } 150 } 151 } 152 } 153 154 private void changeLogFileFormatter() { 157 Handler [] h = LogUtil._logger.getHandlers(); 158 for (int i = 0; i < h.length; i++) { 159 h[i].setFormatter(new PlainFormatter()); 160 } 161 } 162 163 167 protected URL getViewXMLURL() { 168 if (debug) 169 changeLogFileFormatter(); 170 171 String viewXMLFile = ConfigProperties.getInstance().getViewXMLFileName(); 173 URL viewXML = null; 174 175 viewXML = getClass().getClassLoader().getResource(viewXMLFile); 177 178 if (viewXML == null) { 180 if (Util.isLoggableFINEST()) { 181 Util.logFINEST("Unable to find XML FILE in the CLASSPATH: " + 182 viewXMLFile); 183 } 184 String sURL = "file:///" + 185 getServletConfig().getServletContext().getRealPath(viewXMLFile); 186 try { 187 viewXML = new URL (sURL); 188 } catch (Exception exc) { 189 throw new FrameworkException("Unable to create URL: '"+sURL+ 190 "' while attempting to locate '"+viewXMLFile+"'", exc); 191 } 192 } 193 return viewXML; 194 } 195 196 protected EntityResolver getViewXMLEntityResolver() { 197 if (entityResolver == null) { 198 entityResolver = new ViewXMLEntityResolver(); 199 } 200 return entityResolver; 201 } 202 203 208 protected String getJSPRoot() { 209 return AdminGUIConstants.DEFAULT_DISPLAY_URL_DIR; 210 } 211 212 213 216 protected String getPackageName() { 217 return PACKAGE_NAME; 218 } 219 220 221 public void init(ServletConfig config) throws ServletException { 222 if (!PreloadXML.isAlreadyLoaded()) { 228 new PreloadXML(config).run(); 230 } 231 232 super.init(config); 233 MODEL_TYPE_MAP = new ModelTypeMapImpl(); 234 } 235 236 269 270 272 protected void setupConfig() { 273 ConfigProperties config = ConfigProperties.getInstance(); 274 config.setViewXMLFileName("xml/viewDescriptor.xml"); 275 config.setTreeXMLFileName("xml/treeDescriptor.xml", "index"); 276 config.setDefaultDisplayURLDir("/jsp/"); 277 config.setTargetSupported(new Boolean (false)); 278 config.setInitialRightPage("homePageFrameset"); 279 config.setLoggerName("javax.enterprise.system.tools.admin"); 280 config.setDefaultTarget("server"); 281 config.setConsoleTitleKey("common.consoleTitlePE"); 282 } 283 284 protected void onBeforeRequest(RequestContext requestContext) 285 throws javax.servlet.ServletException { 286 HttpSession session = requestContext.getRequest().getSession(); 287 if (session != null) { 288 try { 289 String timeOutSet = (String )session.getAttribute("AdminGUItimeOut"); 290 if (timeOutSet == null) { 291 session.setAttribute("AdminGUItimeOut", "true"); 292 CommonHandlers.setTimeOut(requestContext); 293 } 297 } catch (CompleteRequestException cre) { 298 throw new CompleteRequestException(); 299 } catch (Exception ex) { 300 if (Util.isLoggableINFO()) { 302 Util.logINFO(ex); 303 } 304 } 305 } 306 } 307 308 protected void onNewSession(RequestContext requestContext) throws ServletException { 309 super.onNewSession(requestContext); 310 CommonHandlers.setTimeOut(requestContext); 311 } 312 313 protected void onSessionTimeout(RequestContext requestContext) throws javax.servlet.ServletException { 314 try { 315 String fileName = Util.getLocalizedHTML(requestContext, "/index.html"); 316 requestContext.getResponse().sendRedirect(".."+fileName); 317 } catch (IOException ex) { 318 if (Util.isLoggableWARNING()) { 319 Util.logWARNING(ex); 320 } 321 } catch (IllegalStateException ex) { 322 if (Util.isLoggableWARNING()) { 323 Util.logWARNING(ex); 324 } 325 } 326 throw new CompleteRequestException(); 327 } 328 329 330 334 338 protected void initializeRequestContext(RequestContext requestContext) { 339 super.initializeRequestContext(requestContext); 340 341 try { 342 HttpServletRequest request = requestContext.getRequest(); 344 if(request != null) { 345 request.setCharacterEncoding("UTF-8"); 346 347 if(request.isSecure()) { 348 CCPrivateConfiguration.setSecurePort(request.getServerPort()); 349 CCPrivateConfiguration.setSecureHelp(true); 350 } 351 } 352 } 353 catch(UnsupportedEncodingException ex) { 354 if(Util.isLoggableWARNING()) { 355 Util.logWARNING(ex); 356 } 357 } 358 359 com.sun.enterprise.tools.guiframework.model.ModelManager modelManager = 363 new com.sun.enterprise.tools.guiframework.model.ModelManager( 364 requestContext, MODEL_TYPE_MAP); 365 ((RequestContextImpl)requestContext).setModelManager(modelManager); 366 } 367 368 369 373 public String getModuleURL() { 374 String result=super.getModuleURL(); 380 if (result != null) { 381 return result; 382 } 383 return DEFAULT_MODULE_URL; 384 } 385 386 public static final String DEFAULT_MODULE_URL = "../admingui"; 387 public static String PACKAGE_NAME=getPackageName(AdminGUIServlet.class.getName()); 388 protected static final String UNCAUGHT_REDIR = "__uncaughtRedirFlag"; 389 390 protected EntityResolver entityResolver; 391 protected static ModelTypeMap MODEL_TYPE_MAP; 392 393 static { 397 if (debug) 398 com.sun.enterprise.tools.guiframework.util.LogUtil.setLevel( 399 com.sun.enterprise.tools.guiframework.util.LogUtil.FINER); 400 else 401 com.sun.enterprise.tools.guiframework.util.LogUtil.setLevel( 402 com.sun.enterprise.tools.guiframework.util.LogUtil.WARNING); 403 } 404 } 405 | Popular Tags |