Changeset 9ee106fab8ca310bad99ec4e49e9db8f3c608de7
- Timestamp:
- 09/22/07 15:17:59
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1190467079 +0200
- git-parent:
[740f4b34f443868b8822df7fcdc347bc1656fc14]
- git-author:
- Christopher Jung <bktheg@web.de> 1186924158 +0200
- Message:
Abhaengigkeiten vom DS-Servlet reduziert und einige wichtige Dinge in Listener ausgelagert
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rc99180b |
r9ee106f |
|
| 246 | 246 | return response; |
|---|
| 247 | 247 | } |
|---|
| | 248 | |
|---|
| | 249 | public void setResponse(Response response) { |
|---|
| | 250 | this.response = response; |
|---|
| | 251 | } |
|---|
| 248 | 252 | |
|---|
| 249 | 253 | /** |
|---|
| r5ba971b |
r9ee106f |
|
| 133 | 133 | |
|---|
| 134 | 134 | /** |
|---|
| | 135 | * Setzt das zum Aufruf gehoerende Response-Objekt |
|---|
| | 136 | * @param response Das Response-Objekt |
|---|
| | 137 | */ |
|---|
| | 138 | public abstract void setResponse(Response response); |
|---|
| | 139 | |
|---|
| | 140 | /** |
|---|
| 135 | 141 | * Liefert eine pro Kontext einmalige Instanz einer Klasse. |
|---|
| 136 | 142 | * Sollte keine Instanz dieser Klasse im Kontext vorhanden sein, |
|---|
| r740f4b3 |
r9ee106f |
|
| 34 | 34 | import javax.servlet.http.HttpServletResponse; |
|---|
| 35 | 35 | |
|---|
| 36 | | import net.driftingsouls.ds2.server.framework.db.HibernateFacade; |
|---|
| 37 | 36 | import net.driftingsouls.ds2.server.framework.pipeline.GeneratorPipeline; |
|---|
| 38 | | import net.driftingsouls.ds2.server.framework.pipeline.HttpRequest; |
|---|
| 39 | 37 | import net.driftingsouls.ds2.server.framework.pipeline.HttpResponse; |
|---|
| 40 | 38 | import net.driftingsouls.ds2.server.framework.pipeline.Pipeline; |
|---|
| 41 | 39 | import net.driftingsouls.ds2.server.framework.pipeline.ReaderPipeline; |
|---|
| 42 | | import net.driftingsouls.ds2.server.framework.pipeline.Request; |
|---|
| 43 | 40 | import net.driftingsouls.ds2.server.framework.pipeline.Response; |
|---|
| 44 | 41 | import net.driftingsouls.ds2.server.framework.pipeline.actions.Action; |
|---|
| … | … | |
| 47 | 44 | import net.driftingsouls.ds2.server.framework.xml.XMLUtils; |
|---|
| 48 | 45 | |
|---|
| 49 | | import org.apache.commons.logging.Log; |
|---|
| 50 | | import org.apache.commons.logging.impl.LogFactoryImpl; |
|---|
| 51 | 46 | import org.w3c.dom.Document; |
|---|
| 52 | 47 | import org.w3c.dom.Node; |
|---|
| … | … | |
| 58 | 53 | * |
|---|
| 59 | 54 | */ |
|---|
| 60 | | public class DriftingSoulsServlet extends HttpServlet { |
|---|
| | 55 | public class DriftingSoulsServlet extends HttpServlet implements Loggable { |
|---|
| 61 | 56 | private static final long serialVersionUID = -6026961401478799134L; |
|---|
| 62 | | |
|---|
| 63 | | private transient Log LOG = null; |
|---|
| | 57 | |
|---|
| 64 | 58 | private Map<String,ModuleSetting> modules = new HashMap<String,ModuleSetting>(); |
|---|
| 65 | 59 | private transient ModuleSetting defaultModule = null; |
|---|
| … | … | |
| 419 | 413 | public void init(ServletConfig config) throws ServletException { |
|---|
| 420 | 414 | super.init(config); |
|---|
| 421 | | if( config.getServletContext().getInitParameter("logger") == null ) { |
|---|
| 422 | | System.getProperties().setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); |
|---|
| 423 | | } |
|---|
| 424 | | else { |
|---|
| 425 | | System.getProperties().setProperty("org.apache.commons.logging.Log",config.getServletContext().getInitParameter("logger")); |
|---|
| 426 | | } |
|---|
| 427 | | |
|---|
| 428 | | LOG = new LogFactoryImpl().getInstance("DS2"); |
|---|
| 429 | | LOG.info("Booting DS..."); |
|---|
| 430 | | |
|---|
| 431 | | try { |
|---|
| 432 | | new DriftingSouls(LOG, config.getServletContext().getInitParameter("configdir"), true); |
|---|
| 433 | | } |
|---|
| 434 | | catch( Throwable e ) { |
|---|
| 435 | | LOG.fatal(e, e); |
|---|
| 436 | | throw new ServletException(e); |
|---|
| 437 | | } |
|---|
| 438 | 415 | |
|---|
| 439 | 416 | // Pipeline lesen |
|---|
| … | … | |
| 466 | 443 | throw new ServletException(e); |
|---|
| 467 | 444 | } |
|---|
| 468 | | |
|---|
| 469 | | LOG.info("DS is now ready for service"); |
|---|
| 470 | 445 | } |
|---|
| 471 | 446 | |
|---|
| … | … | |
| 473 | 448 | protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, |
|---|
| 474 | 449 | ServletException { |
|---|
| 475 | | BasicContext context = null; |
|---|
| | 450 | Context context = ContextMap.getContext(); |
|---|
| 476 | 451 | try { |
|---|
| 477 | 452 | Pipeline pipeline = null; |
|---|
| 478 | | Request request = new HttpRequest(httpRequest); |
|---|
| 479 | 453 | Response response = new HttpResponse(httpResponse); |
|---|
| 480 | | context = new BasicContext(request, response); |
|---|
| 481 | | try { |
|---|
| 482 | | context.putVariable(HttpServlet.class, "request", httpRequest); |
|---|
| 483 | | context.putVariable(HttpServlet.class, "response", httpResponse); |
|---|
| 484 | | context.putVariable(HttpServlet.class, "context", getServletContext()); |
|---|
| 485 | | context.putVariable(HttpServlet.class, "config", getServletConfig()); |
|---|
| 486 | | |
|---|
| 487 | | for( Rule rule : rules ) { |
|---|
| 488 | | if( (pipeline = rule.execute(context)) != null ) { |
|---|
| 489 | | break; |
|---|
| 490 | | } |
|---|
| 491 | | } |
|---|
| 492 | | |
|---|
| 493 | | if( pipeline != null ) { |
|---|
| 494 | | pipeline.execute(context); |
|---|
| 495 | | } |
|---|
| 496 | | else { |
|---|
| 497 | | throw new Exception("Unable to find a suitable rule for URL '"+request.getRequestURL()+(request.getQueryString() != null ? "?"+request.getQueryString() : "")+"'"); |
|---|
| 498 | | } |
|---|
| 499 | | |
|---|
| 500 | | response.send(); |
|---|
| 501 | | } |
|---|
| 502 | | catch( Throwable e ) { |
|---|
| 503 | | context.rollback(); |
|---|
| 504 | | |
|---|
| 505 | | throw e; |
|---|
| 506 | | } |
|---|
| 507 | | finally { |
|---|
| 508 | | context.free(); |
|---|
| 509 | | } |
|---|
| | 454 | context.setResponse(response); |
|---|
| | 455 | context.putVariable(HttpServlet.class, "response", httpResponse); |
|---|
| | 456 | context.putVariable(HttpServlet.class, "config", getServletConfig()); |
|---|
| | 457 | |
|---|
| | 458 | for( Rule rule : rules ) { |
|---|
| | 459 | if( (pipeline = rule.execute(context)) != null ) { |
|---|
| | 460 | break; |
|---|
| | 461 | } |
|---|
| | 462 | } |
|---|
| | 463 | |
|---|
| | 464 | if( pipeline != null ) { |
|---|
| | 465 | pipeline.execute(context); |
|---|
| | 466 | } |
|---|
| | 467 | else { |
|---|
| | 468 | throw new Exception("Unable to find a suitable rule for URL '"+context.getRequest().getRequestURL()+(context.getRequest().getQueryString() != null ? "?"+context.getRequest().getQueryString() : "")+"'"); |
|---|
| | 469 | } |
|---|
| | 470 | |
|---|
| | 471 | response.send(); |
|---|
| 510 | 472 | } |
|---|
| 511 | 473 | catch( Throwable e ) { |
|---|
| | 474 | context.rollback(); |
|---|
| | 475 | |
|---|
| 512 | 476 | StringBuilder msg = new StringBuilder(100); |
|---|
| 513 | 477 | msg.append("Time: "+new Date()+"\n"); |
|---|
| … | … | |
| 536 | 500 | } |
|---|
| 537 | 501 | } |
|---|
| 538 | | |
|---|
| 539 | | @Override |
|---|
| 540 | | public void destroy() { |
|---|
| 541 | | HibernateFacade.free(); |
|---|
| 542 | | |
|---|
| 543 | | super.destroy(); |
|---|
| 544 | | } |
|---|
| 545 | 502 | } |
|---|
| reb42e5a |
r9ee106f |
|
| 39 | 39 | </context-param> |
|---|
| 40 | 40 | |
|---|
| | 41 | <listener> |
|---|
| | 42 | <listener-class>net.driftingsouls.ds2.server.framework.pipeline.DefaultServletRequestListener</listener-class> |
|---|
| | 43 | </listener> |
|---|
| | 44 | |
|---|
| | 45 | <listener> |
|---|
| | 46 | <listener-class>net.driftingsouls.ds2.server.framework.pipeline.DefaultServletContextListener</listener-class> |
|---|
| | 47 | </listener> |
|---|
| | 48 | |
|---|
| 41 | 49 | <servlet> |
|---|
| 42 | 50 | <description>Main DS Servlet</description> |
|---|
| 43 | 51 | <servlet-name>ds</servlet-name> |
|---|
| | 52 | <description> |
|---|
| | 53 | Main DS Servlet |
|---|
| | 54 | </description> |
|---|
| 44 | 55 | <servlet-class>net.driftingsouls.ds2.server.framework.DriftingSoulsServlet</servlet-class> |
|---|
| 45 | 56 | <!-- Load this servlet at server startup time --> |
|---|