Advertisement
Guest User

Untitled

a guest
Jun 20th, 2011
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. public void doFilter(ServletRequest request, ServletResponse response,
  2. FilterChain chain)
  3. throws IOException, ServletException {
  4.  
  5. if (debug) {
  6. log("NPNSessionFilter:doFilter()");
  7. }
  8.  
  9. // Create wrappers for the request and response objects.
  10. // Using these, you can extend the capabilities of the
  11. // request and response, for example, allow setting parameters
  12. // on the request before sending the request to the rest of the filter chain,
  13. // or keep track of the cookies that are set on the response.
  14. //
  15. // Caveat: some servers do not handle wrappers very well for forward or
  16. // include requests.
  17. RequestWrapper wrappedRequest = new RequestWrapper((HttpServletRequest) request);
  18. ResponseWrapper wrappedResponse = new ResponseWrapper((HttpServletResponse) response);
  19.  
  20. doBeforeProcessing(wrappedRequest, wrappedResponse);
  21.  
  22. Throwable problem = null;
  23. AbstractSiteAccess access = null;
  24. Connection dbconn = null;
  25. try {
  26. //NPN - Check access to protected content
  27. dbconn =
  28. DBConn.getConnection(ServiceLocator.getInstance().
  29. getDataSource(DBConn.USANPN_DS_NAME));
  30. access =
  31. new SiteAccessDrupal();
  32. access.verifyAccess(wrappedRequest, wrappedResponse, dbconn);
  33.  
  34.  
  35.  
  36. chain.doFilter(wrappedRequest, wrappedResponse);
  37.  
  38.  
  39.  
  40.  
  41. } catch (Throwable t) {
  42. // If an exception is thrown somewhere down the filter chain,
  43. // we still want to execute our after processing, and then
  44. // rethrow the problem after that.
  45. problem = t;
  46. Logger.getLogger(NPNSessionFilter.class.getName()).log(
  47. Level.INFO,
  48. t.getLocalizedMessage());
  49.  
  50. for(StackTraceElement e : t.getStackTrace()){
  51. StringBuffer sb = new StringBuffer();
  52. sb.append(e.getClassName());
  53. sb.append(":");
  54. sb.append(e.getFileName());
  55. sb.append(":");
  56. sb.append(e.getMethodName());
  57. sb.append(":");
  58. sb.append(e.getLineNumber());
  59. System.out.println(sb.toString());
  60. }
  61.  
  62.  
  63. }finally{
  64. DBConn.closeConnection(dbconn);
  65. }
  66.  
  67. doAfterProcessing(wrappedRequest, wrappedResponse);
  68.  
  69. // If there was a problem, we want to rethrow it if it is
  70. // a known type, otherwise log it.
  71. if (problem != null) {
  72. if (problem instanceof ServletException) {
  73. throw (ServletException) problem;
  74. }
  75. if (problem instanceof IOException) {
  76. throw (IOException) problem;
  77. }
  78. //NPN - Handle the problem
  79. if (problem instanceof AccessControlException) {
  80. try {
  81. access.handleAccessProblem(wrappedRequest, wrappedResponse, problem);
  82. } catch (Exception ex) {
  83. Logger.getLogger(NPNSessionFilter.class.getName()).log(Level.SEVERE, null, ex);
  84. }
  85. return;
  86.  
  87. }
  88. sendProcessingError(problem, response);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement