Author: markt
Date: Wed Oct 14 21:21:26 2015
New Revision: 1708694

URL: http://svn.apache.org/viewvc?rev=1708694&view=rev
Log:
Servlet 4.0
Add Javadoc to PushBuilder.push()
Add the header manipulation methods to the PushBuilder interface

Modified:
    tomcat/trunk/java/javax/servlet/http/PushBuilder.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties

Modified: tomcat/trunk/java/javax/servlet/http/PushBuilder.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/servlet/http/PushBuilder.java?rev=1708694&r1=1708693&r2=1708694&view=diff
==============================================================================
--- tomcat/trunk/java/javax/servlet/http/PushBuilder.java (original)
+++ tomcat/trunk/java/javax/servlet/http/PushBuilder.java Wed Oct 14 21:21:26 
2015
@@ -45,5 +45,48 @@ public interface PushBuilder {
      */
     PushBuilder setPath(String path);
 
+    /**
+     * Generates the push request. After calling this method the following
+     * fields are set to {@code null}:
+     * <ul>
+     * <li>{@code path}</li>
+     * <li>{@code etag}</li>
+     * <li>{@code lastModified}</li>
+     * </ul>
+     *
+     * @throws IllegalStateException If this method is called when {@code path}
+     *         is {@code null}
+     * @throws IllegalArgumentException If the request to push requires a body
+     */
     void push();
+
+    /**
+     * Adds a HTTP header to the request.
+     *
+     * @param name  The name of the header to add
+     * @param value The value of the header to add
+     *
+     * @return This builder instance
+     */
+    PushBuilder addHeader(String name, String value);
+
+    /**
+     * Sets a HTTP header on the request. Any existing headers of the same name
+     * are first remove.
+     *
+     * @param name  The name of the header to set
+     * @param value The value of the header to set
+     *
+     * @return This builder instance
+     */
+    PushBuilder setHeader(String name, String value);
+
+    /**
+     * Removes an HTTP header from the request.
+     *
+     * @param name  The name of the header to remove
+     *
+     * @return This builder instance
+     */
+    PushBuilder removeHeader(String name);
 }

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java?rev=1708694&r1=1708693&r2=1708694&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationPushBuilder.java Wed 
Oct 14 21:21:26 2015
@@ -16,6 +16,12 @@
  */
 package org.apache.catalina.core;
 
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletRequestWrapper;
 import javax.servlet.http.HttpServletRequest;
@@ -33,6 +39,7 @@ public class ApplicationPushBuilder impl
     private final org.apache.coyote.Request coyoteRequest;
 
     private String path;
+    private Map<String,List<String>> headers = new HashMap<>();
 
     public ApplicationPushBuilder(HttpServletRequest request) {
         baseRequest = request;
@@ -47,6 +54,20 @@ public class ApplicationPushBuilder impl
             throw new UnsupportedOperationException(sm.getString(
                     "applicationPushBuilder.noCoyoteRequest", 
current.getClass().getName()));
         }
+
+        // Populate the initial list of HTTP headers
+        // TODO Servlet 4.0
+        //      Filter headers as required by Servlet spec
+        Enumeration<String> headerNames = request.getHeaderNames();
+        while (headerNames.hasMoreElements()) {
+            String headerName = headerNames.nextElement();
+            List<String> values = new ArrayList<>();
+            headers.put(headerName, values);
+            Enumeration<String> headerValues = request.getHeaders(headerName);
+            while (headerValues.hasMoreElements()) {
+                values.add(headerValues.nextElement());
+            }
+        }
     }
 
 
@@ -68,7 +89,47 @@ public class ApplicationPushBuilder impl
 
 
     @Override
+    public PushBuilder addHeader(String name, String value) {
+        List<String> values = headers.get(name);
+        if (values == null) {
+            values = new ArrayList<>();
+            headers.put(name, values);
+        }
+        values.add(value);
+
+        return this;
+    }
+
+
+    @Override
+    public PushBuilder setHeader(String name, String value) {
+        List<String> values = headers.get(name);
+        if (values == null) {
+            values = new ArrayList<>();
+            headers.put(name, values);
+        } else {
+            values.clear();
+        }
+        values.add(value);
+
+        return this;
+    }
+
+
+    @Override
+    public PushBuilder removeHeader(String name) {
+        headers.remove(name);
+
+        return this;
+    }
+
+
+    @Override
     public void push() {
+        if (path == null) {
+            throw new 
IllegalStateException(sm.getString("pushBuilder.noPath"));
+        }
+
         org.apache.coyote.Request pushTarget = new org.apache.coyote.Request();
 
         pushTarget.method().setString("GET");
@@ -83,6 +144,9 @@ public class ApplicationPushBuilder impl
         // TODO Copy across / set other required attributes
 
         coyoteRequest.action(ActionCode.PUSH_REQUEST, pushTarget);
+
+        // Reset for next call to this method
         pushTarget = null;
+        path = null;
     }
 }

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1708694&r1=1708693&r2=1708694&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Wed Oct 
14 21:21:26 2015
@@ -105,6 +105,9 @@ naming.invalidEnvEntryType=Environment e
 naming.invalidEnvEntryValue=Environment entry {0} has an invalid value
 naming.namingContextCreationFailed=Creation of the naming context failed: {0}
 noPluggabilityServletContext.notAllowed=Section 4.4 of the Servlet 3.0 
specification does not permit this method to be called from a 
ServletContextListener that was not defined in web.xml, a web-fragment.xml file 
nor annotated with @WebListener
+
+pushBuilder.noPath=It is illegal to call push() before setting a path
+
 standardContext.invalidWrapperClass={0} is not a subclass of StandardWrapper
 standardContext.applicationListener=Error configuring application listener of 
class {0}
 standardContext.applicationSkipped=Skipped installing application listeners 
due to previous error(s)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to