1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 45 import javax.servlet.ServletException ; 46 import javax.servlet.http.HttpServlet ; 47 import javax.servlet.http.HttpServletRequest ; 48 import javax.servlet.http.HttpServletResponse ; 49 50 import org.apache.log4j.Logger; 51 import org.dspace.app.webui.util.Authenticate; 52 import org.dspace.app.webui.util.JSPManager; 53 import org.dspace.app.webui.util.UIUtil; 54 import org.dspace.authorize.AuthorizeException; 55 import org.dspace.core.Context; 56 import org.dspace.core.LogManager; 57 58 82 public class DSpaceServlet extends HttpServlet 83 { 84 92 93 94 private static Logger log = Logger.getLogger(DSpaceServlet.class); 95 96 protected void doGet(HttpServletRequest request, 97 HttpServletResponse response) throws ServletException , IOException 98 { 99 processRequest(request, response); 100 } 101 102 protected void doPost(HttpServletRequest request, 103 HttpServletResponse response) throws ServletException , IOException 104 { 105 processRequest(request, response); 106 } 107 108 116 private void processRequest(HttpServletRequest request, 117 HttpServletResponse response) throws ServletException , IOException 118 { 119 Context context = null; 120 121 request.setCharacterEncoding("UTF-8"); 123 124 UIUtil.storeOriginalURL(request); 127 128 try 129 { 130 context = UIUtil.obtainContext(request); 133 134 request = Authenticate.getRealRequest(request); 137 138 if (log.isDebugEnabled()) 139 { 140 log.debug(LogManager.getHeader(context, "http_request", UIUtil 141 .getRequestLogInfo(request))); 142 } 143 144 if (request.getMethod().equals("POST")) 146 { 147 doDSPost(context, request, response); 148 } 149 else 150 { 151 doDSGet(context, request, response); 152 } 153 } 154 catch (SQLException se) 155 { 156 log.warn(LogManager.getHeader(context, "database_error", se 159 .toString()), se); 160 161 UIUtil.sendAlert(request, se); 163 164 JSPManager.showInternalError(request, response); 165 } 166 catch (AuthorizeException ae) 167 { 168 175 if (context.getCurrentUser() != null || 176 Authenticate.startAuthentication(context, request, response)) 177 { 178 log.info(LogManager.getHeader(context, "authorize_error", ae 181 .toString())); 182 183 JSPManager.showAuthorizeError(request, response, ae); 184 } 185 } 186 catch (RuntimeException e) 187 { 188 throw e; 190 } 191 catch (IOException ioe) 192 { 193 throw ioe; 195 } 196 catch (ServletException sve) 197 { 198 throw sve; 200 } 201 finally 202 { 203 if ((context != null) && context.isValid()) 205 { 206 context.abort(); 207 } 208 } 209 } 210 211 228 protected void doDSGet(Context context, HttpServletRequest request, 229 HttpServletResponse response) throws ServletException , IOException , 230 SQLException , AuthorizeException 231 { 232 super.doGet(request, response); 235 } 236 237 254 protected void doDSPost(Context context, HttpServletRequest request, 255 HttpServletResponse response) throws ServletException , IOException , 256 SQLException , AuthorizeException 257 { 258 super.doGet(request, response); 261 } 262 } 263 | Popular Tags |