BrightSide Workbench Full Report + Source Code
ContextServlet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.servlet.context;
19 
20 import java.io.IOException;
21 import javax.servlet.ServletException;
22 import javax.servlet.annotation.WebServlet;
23 import javax.servlet.http.HttpServlet;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.turro.action.Closeables;
27 import org.turro.action.IAgreements;
28 import org.turro.action.Initializers;
29 import org.turro.action.Interceptors;
30 import org.turro.elephant.context.ElephantApplication;
31 import org.turro.elephant.context.ElephantContext;
32 import org.turro.elephant.context.HeadlessApplication;
33 import org.turro.elephant.context.IConstructor;
34 import org.turro.elephant.direct.DirectContents;
35 import org.turro.sso.SSO;
36 
42 @WebServlet(name = "Context", urlPatterns = {"", "/"})
43 public class ContextServlet extends HttpServlet {
44 
45  @Override
46  protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
47  req.setAttribute("el_app", new ElephantApplication(req, resp));
48  super.service(req, resp);
49  }
50 
51  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
52  if(DirectContents.isDirectContent(request)) {
53  DirectContents.executeDirectContents(getServletContext(), request, response);
54  return; // moved
55  }
56  IConstructor constructor = ElephantContext.getConstructor(request, response);
57  HeadlessApplication.getInstance(constructor);
58  Initializers.initialize(constructor);
59  if(IAgreements.checkAgreements(request, response)) {
60  if(ElephantContext.getUseSSO() && SSO.hasSSO(request) && constructor.getUser() == null) {
61  SSO.getSSO().navigateAuthenticatedTo(constructor.getRequest(), constructor.getResponse());
62  } else {
63  if(!Interceptors.executeWeb(constructor)) {
64  constructor.startConstruction();
65  }
66  }
67  }
68  }
69 
70  @Override
71  public void destroy() {
72  super.destroy();
74  }
75 
76  // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
81  @Override
82  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
83  processRequest(request, response);
84  }
85 
90  @Override
91  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
92  processRequest(request, response);
93  }
94 
97  @Override
98  public String getServletInfo() {
99  return "Context servlet for Elephant";
100  }
101 
102  // </editor-fold>
103 
104 }
static void initialize(IConstructor constructor)
static boolean executeWeb(IConstructor constructor)
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static boolean isDirectContent(HttpServletRequest request)
static synchronized boolean executeDirectContents(ServletContext context, HttpServletRequest request, HttpServletResponse response)
void service(HttpServletRequest req, HttpServletResponse resp)
void doGet(HttpServletRequest request, HttpServletResponse response)
void processRequest(HttpServletRequest request, HttpServletResponse response)
void doPost(HttpServletRequest request, HttpServletResponse response)
static IElephantSSO getSSO()
Definition: SSO.java:49
static boolean hasSSO()
Definition: SSO.java:34
static boolean checkAgreements(HttpServletRequest request, HttpServletResponse response)
void navigateAuthenticatedTo(HttpServletRequest request, HttpServletResponse response)