abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r656935 - in /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server: RequestContext.java servlet/AbderaServlet.java servlet/ServletRequestContext.java
Date Fri, 16 May 2008 05:16:37 GMT
Author: jmsnell
Date: Thu May 15 22:16:37 2008
New Revision: 656935

URL: http://svn.apache.org/viewvc?rev=656935&view=rev
Log:
https://issues.apache.org/jira/browse/ABDERA-158 - Make ServletContext available in ServletRequestContext

I modified the patch so that the existing RequestContext.getAttribute and setAttribute methods
can be used. There is a new value for the Scope enum called CONTAINER that, when using the
ServletRequestContext, will use the ServletContext.

e.g. context.setAttribute(Scope.CONTAINER, "foo", "bar");

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java?rev=656935&r1=656934&r2=656935&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/RequestContext.java
Thu May 15 22:16:37 2008
@@ -45,9 +45,10 @@
    * RequestContext attributes can either have Session or Request scope.
    * Request scope attributes are only valid within the context of the current 
    * request.  Session scope attributes, however, will remain valid as long 
-   * as the Session is active
+   * as the Session is active. Container scope attributes are set on the 
+   * Web container (e.g. the ServletContext)
    */
-  public enum Scope { REQUEST, SESSION };
+  public enum Scope { REQUEST, SESSION, CONTAINER };
   
   /**
    * Special properties provided by the server

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java?rev=656935&r1=656934&r2=656935&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/AbderaServlet.java
Thu May 15 22:16:37 2008
@@ -84,7 +84,7 @@
     HttpServletResponse response) 
       throws ServletException, IOException {
     RequestContext reqcontext = 
-      new ServletRequestContext(provider, request);
+      new ServletRequestContext(provider, request, getServletContext());
     FilterChain chain = new FilterChain(provider,reqcontext);
     try {
       output(
@@ -159,7 +159,7 @@
     Map<String,String> properties = new HashMap<String,String>();
     Enumeration<String> e = config.getInitParameterNames();
     while(e.hasMoreElements()) {
-      String key = (String) e.nextElement();
+      String key = e.nextElement();
       String val = config.getInitParameter(key);
       properties.put(key, val);
     }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java?rev=656935&r1=656934&r2=656935&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/servlet/ServletRequestContext.java
Thu May 15 22:16:37 2008
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Locale;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
@@ -41,17 +42,20 @@
   implements RequestContext {
 
   private final HttpServletRequest request;
+  private final ServletContext servletContext;
   private HttpSession session;
   
   public ServletRequestContext(
     Provider provider,
-    HttpServletRequest request) {
+    HttpServletRequest request,
+    ServletContext servletContext) {
       super(
         provider, 
         request.getMethod(), 
         initRequestUri(request),
         initBaseUri(provider,request));
       this.request = request;
+      this.servletContext = servletContext;
       this.session = request.getSession(false);
       this.principal = request.getUserPrincipal();
       this.subject = provider.resolveSubject(this);
@@ -97,6 +101,10 @@
   public HttpServletRequest getRequest() {
     return request;
   }
+
+  public ServletContext getServletContext() {
+    return servletContext;
+  }
   
   public synchronized HttpSession getSession() {
     return getSession(false);
@@ -111,6 +119,11 @@
     switch(scope) {
       case REQUEST: request.setAttribute(name, value); break;
       case SESSION: getSession(true).setAttribute(name, value); break;
+      case CONTAINER: {
+        ServletContext scontext = getServletContext();
+        if (scontext != null) 
+          scontext.setAttribute(name, value);
+      }
     }
     return this;
   }
@@ -119,6 +132,10 @@
     switch(scope) {
       case REQUEST: return request.getAttribute(name);
       case SESSION: return (session != null) ? session.getAttribute(name) : null;
+      case CONTAINER: {
+        ServletContext scontext = getServletContext();
+        return scontext != null ? scontext.getAttribute(name) : null;
+      }
     }
     return null;
   }
@@ -128,6 +145,10 @@
     switch(scope) {
       case REQUEST: return enum2array(request.getAttributeNames());
       case SESSION: return (session != null) ? enum2array(session.getAttributeNames()) :
null;
+      case CONTAINER: {
+        ServletContext scontext = getServletContext();
+        return scontext != null ? enum2array(scontext.getAttributeNames()) : null;
+      }
     }
     return null;
   }
@@ -216,13 +237,13 @@
   }
   
   private static IRI initRequestUri(HttpServletRequest request) {
-    IRI uri = null;
+    IRI uri;
     StringBuilder buf = 
       new StringBuilder(
         request.getRequestURI());
     String qs = request.getQueryString();
     if (qs != null && qs.length() != 0)
-      buf.append("?" + request.getQueryString());
+        buf.append("?").append(request.getQueryString());
     uri = new IRI(buf.toString());
     return uri;
   }



Mime
View raw message