1 23 24 package barracudaDiscRack; 25 26 import com.lutris.appserver.server.*; 27 import com.lutris.appserver.server.httpPresentation.*; 28 import com.lutris.appserver.server.session.*; 29 import com.lutris.util.*; 30 import javax.servlet.*; 31 import javax.servlet.http.*; 32 import java.util.*; 33 import java.io.*; 34 35 40 public class BarracudaDiscRackEnhydra extends StandardApplication { 41 42 46 public void startup(Config appConfig) 47 throws ApplicationException { 48 super.startup(appConfig); 49 52 try { 54 ServletConfig servletConfig = 58 this.getHttpPresentationManager().getServlet().getServletConfig(); 59 Config gatewayConfig = appConfig.getConfig("InitGateway"); 60 if ( null != gatewayConfig ) { 61 servletConfig = 62 new ServletConfigWrapper( 63 this.getHttpPresentationManager().getServletContext(), 64 gatewayConfig, 65 servletConfig.getServletName() ); 66 } 67 68 this.myDiscRackGateway = new DiscRackGateway(); 69 this.myGatewayExtension = this.myDiscRackGateway.getEventExtension(); 70 this.myDiscRackGateway.init( servletConfig ); 71 } catch ( ServletException ex ) { 72 throw ( new ApplicationException( "Error initilising DiscRackGateway", ex ) ); 73 } catch ( KeywordValueException ex ) { 74 throw ( new ApplicationException( "Error initilising DiscRackGateway", ex ) ); 75 } 76 } 77 78 81 public void shutdown () { 82 super.shutdown(); 83 this.myDiscRackGateway.destroy(); 84 } 85 86 105 protected void ensureSession(HttpPresentationComms comms) 106 throws ApplicationException { 107 108 try { 109 boolean isOkForSession = presentationManager.isPresentationRequest(comms.request) || 110 comms.request.getRequestURI().indexOf(this.myGatewayExtension) > -1; 111 112 if ( isOkForSession ) { 113 comms.session = StandardAppUtil.getRequestSession(comms); 115 } 116 if ( comms.session != null && 117 sessionManager.sessionExists(comms.session.getSessionKey()) ) { 118 126 comms.sessionData = comms.session.getSessionData(); 127 } else { 128 129 if ( isOkForSession ) { 130 initializeNewSession(comms); 131 } 132 } 133 } catch ( HttpPresentationException except ) { 134 throw new ApplicationException(except); 135 } catch ( SessionException except ) { 136 throw new ApplicationException(except); 137 } 138 } 139 140 public boolean requestPreprocessor(HttpPresentationComms comms) 141 throws Exception { 142 boolean retVal = super.requestPreprocessor(comms); 143 if ( !retVal ) { 144 String target = comms.request.getRequestURI(); 145 if ( target.indexOf(this.myGatewayExtension) > -1 ) { 147 this.myDiscRackGateway.handleDefaultExt( 148 comms.request.getHttpServletRequest(), 149 comms.response.getHttpServletResponse(), 150 comms ); 151 retVal = true; 152 } 153 } 154 return retVal; 155 } 156 157 165 public String toHtml() { 166 return "This is <I>DiscRack</I>"; 167 } 168 169 private DiscRackGateway myDiscRackGateway; 170 private String myGatewayExtension; 171 } 172 173 174 class ServletConfigWrapper implements ServletConfig { 175 176 private ServletContext myContext; 177 private Config myConfig; 178 private String myName; 179 180 public ServletConfigWrapper( ServletContext context, Config config, String name ) { 181 this.myContext = context; 182 this.myConfig = config; 183 this.myName = name; 184 } 185 186 public ServletContext getServletContext() { 187 return this.myContext; 188 } 189 190 public String getInitParameter(String name) { 191 String retVal = null; 192 try { 193 retVal = this.myConfig.getString(name); 194 } catch ( KeywordValueException ex ) { 195 } 196 return retVal; 197 } 198 199 public Enumeration getInitParameterNames() { 200 return( Collections.enumeration(Arrays.asList(this.myConfig.keys())) ); 201 } 202 203 public String getServletName() { 204 return this.myName; 205 } 206 207 } 208
| Popular Tags
|