cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r530488 - in /cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice: ServletConnection.java util/BlockCallHttpServletRequest.java
Date Thu, 19 Apr 2007 17:02:58 GMT
Author: gkossakowski
Date: Thu Apr 19 10:02:57 2007
New Revision: 530488

URL: http://svn.apache.org/viewvc?view=rev&rev=530488
Log:
COCOON-2050: Provide methods necessary for making POST servlet requests.

Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java?view=diff&rev=530488&r1=530487&r2=530488
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/ServletConnection.java
Thu Apr 19 10:02:57 2007
@@ -20,6 +20,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -65,6 +66,7 @@
     private boolean connected; 
     
     private InputStream responseBody;
+    private ByteArrayOutputStream requestBody;
 
     /**
      * Construct a new object
@@ -100,6 +102,8 @@
     	//if already connected, do nothing
     	if (connected) return;
     	
+    	request.setInputStream(new ByteArrayInputStream(requestBody.toByteArray()));
+    	
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         this.response.setOutputStream(os);
         RequestDispatcher dispatcher = null;
@@ -169,6 +173,18 @@
 				throw new IOException("Could not get response status code");
 			}
     	return response.getStatus();
+    }
+    
+    /**
+     * Returns an output stream that writes as POST to this connection.
+     * @return an output stream that writes as POST to this connection.
+     * @throws IllegalStateException - if already connected
+     */
+    public OutputStream getOutputStream() throws IllegalStateException {
+    	if (connected) throw new IllegalStateException("You cannot write to the connection already
connected.");
+    	if (requestBody == null) requestBody = new ByteArrayOutputStream();
+    	return requestBody;
+    	
     }
     
     // Parse the block protocol.

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java?view=diff&rev=530488&r1=530487&r2=530488
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java
(original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/util/BlockCallHttpServletRequest.java
Thu Apr 19 10:02:57 2007
@@ -18,6 +18,7 @@
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.security.Principal;
@@ -51,8 +52,11 @@
     private Hashtable attributes = new Hashtable();
     private RequestParameters parameters;
     private String encoding;
+    private String method;
     private Map headers = new HashMap();
     
+    private ServletInputStream requestBody;
+    
 	/**
 	 * format definied by RFC 822, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3

 	 */
@@ -170,8 +174,15 @@
      * @see javax.servlet.ServletRequest#getInputStream()
      */
     public ServletInputStream getInputStream() throws IOException {
-        // TODO Doesn't handle input streams yet
-        throw new UnsupportedOperationException();
+    	return requestBody;
+    }
+    
+    public void setInputStream(final InputStream inputStream) {
+    	requestBody = new ServletInputStream() {
+        	public int read() throws IOException {
+        		return inputStream.read();
+        	}
+        };
     }
 
     /* (non-Javadoc)
@@ -210,8 +221,11 @@
      * @see javax.servlet.http.HttpServletRequest#getMethod()
      */
     public String getMethod() {
-        // TODO Only implements GET yet
-        return "GET";
+        return method;
+    }
+    
+    public void setMethod(String method) {
+    	this.method = method;
     }
 
     /* (non-Javadoc)



Mime
View raw message