You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2003/02/01 00:23:20 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient SimpleHttpConnection.java TestMethodsNoHost.java TestMethodsRedirectNoHost.java TestWebappBasicAuth.java TestWebappCookie.java TestWebappMethods.java TestWebappParameters.java TestWebappRedirect.java
olegk 2003/01/31 15:23:18
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpConnection.java HttpMethodBase.java
httpclient/src/java/org/apache/commons/httpclient/methods
PostMethod.java PutMethod.java
httpclient/src/test/org/apache/commons/httpclient
SimpleHttpConnection.java TestMethodsNoHost.java
TestMethodsRedirectNoHost.java
TestWebappBasicAuth.java TestWebappCookie.java
TestWebappMethods.java TestWebappParameters.java
TestWebappRedirect.java
Log:
Bug fixes:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11095
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11653
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14731
Changelog:
- Abstract EntityEnclosingMethod class has been introduced to encapsulate common behaviour of all entity enclosing methods
- "Expect: 100-continue" header support
- HttpClient does not hang indefinitely if the server of origin does not return status code 100 when expected. HttpClient resumes sending request body after 3 seconds if no response is sent
- Support for chunk encoded requests in all entity enclosing methods
- Entity enclosing methods do not allow automatic redirection
- More robust (or so I'd like to hope) request content buffering logic
- PostMethod inherited from EntityEnclosingMethod class
- PutMethod inherited from EntityEnclosingMethod class
- Older methods of PostMethod dealing with url-encoded parameters deprecated in favour of new setRequestBody(NameValuePair[]) method
Submitted by Oleg Kalnichevski
Revision Changes Path
1.40 +32 -4 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
Index: HttpConnection.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- HttpConnection.java 31 Jan 2003 00:33:36 -0000 1.39
+++ HttpConnection.java 31 Jan 2003 23:23:13 -0000 1.40
@@ -103,6 +103,7 @@
* @author Ortwin Gl�ck
* @author Jeff Dever
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
*
* @version $Revision$ $Date$
*/
@@ -674,6 +675,33 @@
LOG.trace("enter HttpConnection.getResponseInputStream()");
assertOpen();
return inputStream;
+ }
+
+ /**
+ * Waits for the specified number of milliseconds for input data to become available
+ *
+ * @param timeout_ms Number of milliseconds to wait for input data.
+ *
+ * @return boolean <tt>true</tt> if input data is availble, <tt>false</tt> otherwise.
+ *
+ * @throws IOException If an IO problem occurs
+ * @throws IllegalStateException If the connection isn't open.
+ */
+ public boolean waitForResponse(long timeout_ms)
+ throws IOException, IllegalStateException {
+ LOG.trace("enter HttpConnection.waitForResponse(int)");
+ assertOpen();
+ if (timeout_ms < 0) {
+ throw new IllegalArgumentException("Timeout value may not be negative");
+ }
+ long overtime = System.currentTimeMillis() + timeout_ms;
+ while (System.currentTimeMillis() < overtime) {
+ if (inputStream.available() > 0) {
+ return true;
+ }
+ }
+ LOG.debug("Waiting for response timeout");
+ return false;
}
/**
1.105 +56 -18 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- HttpMethodBase.java 30 Jan 2003 05:01:53 -0000 1.104
+++ HttpMethodBase.java 31 Jan 2003 23:23:14 -0000 1.105
@@ -258,6 +258,9 @@
/** true if we are finished with the connection */
private boolean doneWithConnection = false;
+ /** Number of milliseconds to wait for 100-contunue response */
+ private static long RESPONSE_WAIT_TIME_MS = 3000;
+
// ----------------------------------------------------------- Constructors
/**
@@ -2372,17 +2375,39 @@
}
} while (retryCount <= maxRetries);
- //try to do the read
- try {
- readResponse(state, connection);
- } catch (HttpRecoverableException httpre) {
- LOG.warn("Recoverable exception caught when reading response");
- if (LOG.isDebugEnabled()) {
- LOG.debug("Closing the connection.");
+
+ // Should we expect a response at this point?
+ boolean responseExpected = true;
+ if (!this.bodySent) {
+ if (connection.waitForResponse(RESPONSE_WAIT_TIME_MS)) {
+ responseExpected = true;
+ LOG.debug("Response available");
+ }
+ else {
+ responseExpected = false;
+ // Something is wrong.
+ if (getRequestHeader("Expect") != null) {
+ // Most probably Expect header is not recongnized
+ // Remove the header to signal the method
+ // that it's okay to go ahead with sending data
+ removeRequestHeader("Expect");
+ }
+ LOG.debug("Response not available. Send the request body");
+ }
+ }
+ if (responseExpected) {
+ //try to do the read
+ try {
+ readResponse(state, connection);
+ } catch (HttpRecoverableException httpre) {
+ LOG.warn("Recoverable exception caught when reading response");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Closing the connection.");
+ }
+
+ connection.close();
+ throw httpre;
}
-
- connection.close();
- throw httpre;
}
//everything should be OK at this point
}
@@ -2404,13 +2429,26 @@
throws HttpException, IOException {
LOG.trace("enter writeRemainingRequestBody(HttpState, HttpConnection)");
- if (HttpStatus.SC_CONTINUE == statusLine.getStatusCode()) {
+ boolean writeRemaining = false;
+ boolean continueReceived = false;
+ if (statusLine == null) {
+ writeRemaining = true;
+ }
+ else {
+ if (statusLine.getStatusCode() == HttpStatus.SC_CONTINUE) {
+ writeRemaining = true;
+ continueReceived = true;
+ }
+ }
+
+ if (writeRemaining) {
if (!bodySent) {
bodySent = writeRequestBody(state, connection);
} else {
- LOG.warn("Received status CONTINUE but the body has already "
- + "been sent");
- // According to RFC 2616 this respose should be ignored
+ if (continueReceived) {
+ LOG.warn("Received status CONTINUE but the body has already been sent");
+ // According to RFC 2616 this respose should be ignored
+ }
}
readResponse(state, connection);
}
1.35 +161 -475 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java
Index: PostMethod.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- PostMethod.java 28 Jan 2003 22:25:26 -0000 1.34
+++ PostMethod.java 31 Jan 2003 23:23:16 -0000 1.35
@@ -2,7 +2,6 @@
* $Header$
* $Revision$
* $Date$
- *
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -60,27 +59,20 @@
* [Additional notices, if required by prior licensing conditions]
*
*/
-
package org.apache.commons.httpclient.methods;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
+import java.util.Vector;
import java.util.Iterator;
import java.util.List;
-import java.util.Vector;
-import org.apache.commons.httpclient.HttpConstants;
-import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.ChunkedOutputStream;
-import org.apache.commons.httpclient.ContentLengthInputStream;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -118,52 +110,32 @@
* @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
* @author Ortwin Gl�ck
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
* @since 1.0
*/
-public class PostMethod extends GetMethod {
- //~ Static variables/initializers ������������������������������������������
-
- /**
- * The content length will be calculated automatically. This implies
- * buffering of the content.
- */
- public static final int CONTENT_LENGTH_AUTO = -2;
-
- /**
- * The request will use chunked transfer encoding. Content length is not
- * calculated and the content is not buffered.<br>
- */
- public static final int CONTENT_LENGTH_CHUNKED = -1;
-
+public class PostMethod extends EntityEnclosingMethod {
// -------------------------------------------------------------- Constants
/** Log object for this class. */
- private static final Log LOG = LogFactory.getLog(PostMethod.class);
+ private static final Log log = LogFactory.getLog(PostMethod.class);
+
+ /** Custom content encoding. */
+ private static final int CUSTOM_CONTENT = 0;
+
+ /** URL encoded content. */
+ private static final int URL_ENCODED_CONTENT = 1;
+
+ /** My content encoding. */
+ private int contentEnconding = CUSTOM_CONTENT;
/** The Content-Type header for www-form-urlcoded. */
- private static final Header CONTENT_TYPE = new Header("Content-Type",
+ static final Header URL_ENCODED_CONTENT_TYPE = new Header("Content-Type",
"application/x-www-form-urlencoded");
- /** The buffered request body. */
- protected ByteArrayOutputStream buffer = null;
-
- /** The unbuffered request body. */
- protected InputStream requestBody = null;
-
/** The buffered request body consisting of <code>NameValuePair</code>s */
- protected Vector parameters = new Vector();
-
- /** Counts how often the request was sent to the server. */
- protected int repeatCount = 0;
-
- /**
- * The content length of the <code>requestBody</code> or one of
- * <code>{@link #CONTENT_LENGTH_AUTO}</code> and
- * <code>{@link #CONTENT_LENGTH_CHUNKED}</code>.
- */
- protected int requestContentLength = CONTENT_LENGTH_AUTO;
+ protected Vector deprecated_parameters = new Vector();
- //~ Constructors �����������������������������������������������������������
+ // ----------------------------------------------------------- Constructors
/**
* No-arg constructor.
@@ -172,7 +144,6 @@
*/
public PostMethod() {
super();
- setFollowRedirects(false);
}
/**
@@ -184,7 +155,6 @@
*/
public PostMethod(String uri) {
super(uri);
- setFollowRedirects(false);
}
/**
@@ -195,9 +165,8 @@
*
* @since 1.0
*/
- public PostMethod(String uri, String tempDir) {
- super(uri, tempDir);
- setFollowRedirects(false);
+ public PostMethod(String uti, String tempDir) {
+ super(uti, tempDir);
}
/**
@@ -211,28 +180,6 @@
*/
public PostMethod(String uri, String tempDir, String tempFile) {
super(uri, tempDir, tempFile);
- setFollowRedirects(false);
- }
-
- // ----------------------------------------------------------- Constructors
-
- //~ Methods ����������������������������������������������������������������
-
- /**
- * A POST request can only be redirected if input is buffered. Overrides
- * method of {@link org.apache.commons.httpclient.HttpMethodBase}.
- *
- * @return true if request is buffered and <code>setFollowRedirects</code>
- * was set to <code>true</code>.
- *
- * @since 2.0
- */
- public boolean getFollowRedirects() {
- if (!super.getFollowRedirects()) {
- return false;
- }
-
- return (buffer != null);
}
// ----------------------------------------------------- Instance Methods
@@ -252,23 +199,15 @@
* Set the value of parameter with parameterName to parameterValue. Does
* not preserve the initial insertion order.
*
- * @param parameterName DOCUMENT ME!
- * @param parameterValue DOCUMENT ME!
- *
- * @throws IllegalStateException if my request body has already been
- * generated.
+ * @param parameterName name of the parameter
+ * @param parameterValue value of the parameter
*
* @since 2.0
- * @deprecated use {@link #removeParameter(String,String)} followed by
- * {@link #addParameter(String,String)}.
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public void setParameter(String parameterName, String parameterValue)
- throws IllegalStateException {
- LOG.trace("enter PostMethod.setParameter(String, String)");
-
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
- }
+ public void setParameter(String parameterName, String parameterValue) {
+ log.trace("enter PostMethod.setParameter(String, String)");
removeParameter(parameterName, parameterValue);
addParameter(parameterName, parameterValue);
@@ -278,21 +217,24 @@
* Gets the parameter of the specified name. If there exists more than one
* parameter with the name paramName, then only the first one is returned.
*
- * @param paramName DOCUMENT ME!
+ * @param paramName name of the parameter
*
* @return If a parameter exists with the name argument, the coresponding
* NameValuePair is returned. Otherwise null.
*
* @since 2.0
+ *
+ * @deprecated use {@link #getRequestBody()} or
+ * {@link #getRequestBodyAsString()}.
*/
public NameValuePair getParameter(String paramName) {
- LOG.trace("enter PostMethod.getParameter(String)");
+ log.trace("enter PostMethod.getParameter(String)");
if (paramName == null) {
return null;
}
- Iterator iter = parameters.iterator();
+ Iterator iter = deprecated_parameters.iterator();
while (iter.hasNext()) {
NameValuePair parameter = (NameValuePair) iter.next();
@@ -301,7 +243,6 @@
return parameter;
}
}
-
return null;
}
@@ -314,13 +255,15 @@
* @return An array of the current parameters
*
* @since 2.0
- * @see #getParameter(java.lang.String)
+ *
+ * @deprecated use {@link #getRequestBody()} or
+ * {@link #getRequestBodyAsString()}.
*/
public NameValuePair[] getParameters() {
- LOG.trace("enter PostMethod.getParameters()");
+ log.trace("enter PostMethod.getParameters()");
- int numPairs = parameters.size();
- Object[] objectArr = parameters.toArray();
+ int numPairs = deprecated_parameters.size();
+ Object[] objectArr = deprecated_parameters.toArray();
NameValuePair[] nvPairArr = new NameValuePair[numPairs];
for (int i = 0; i < numPairs; i++) {
@@ -331,168 +274,27 @@
}
/**
- * Sets the request body to be the specified string.
- *
- * <p>
- * Once this method has been invoked, the request parameters cannot be
- * altered until I am {@link #recycle recycled}.
- * </p>
- *
- * @param body Request content as a string
- *
- * @throws IllegalStateException if request params have been added
- *
- * @since 2.0
- */
- public void setRequestBody(String body) throws IllegalStateException {
- LOG.trace("enter PostMethod.setRequestBody(String)");
-
- if (!parameters.isEmpty()) {
- throw new IllegalStateException(
- "Request parameters have already been added.");
- }
-
- if (body == null) {
- this.requestBody = null;
- return;
- }
-
- this.requestBody = new ByteArrayInputStream(
- HttpConstants.getContentBytes(body, getRequestCharSet()));
- }
-
- /**
- * Sets the request body to be the specified inputstream.
- *
- * <p>
- * Once this method has been invoked, the request parameters cannot be
- * altered until I am {@link #recycle recycled}.
- * </p>
- *
- * @param body DOCUMENT ME!
- *
- * @throws IllegalStateException if request params have been added
- *
- * @since 2.0
- */
- public void setRequestBody(InputStream body) throws IllegalStateException {
- LOG.trace("enter PostMethod.getRequestBody(InputStream)");
-
- if (!parameters.isEmpty()) {
- throw new IllegalStateException(
- "Request parameters have already been added.");
- }
-
- this.requestBody = body;
- }
-
- /**
- * Gets the requestBody as it would be if it was executed.
- *
- * @return The request body if it has been set. The generated request
- * body from the paramters if they exist. Null otherwise.
- *
- * @since 2.0
- */
- public InputStream getRequestBody() {
- LOG.trace("enter PostMethod.getRequestBody()");
-
- if (requestBody != null) {
- return requestBody;
- } else if (!parameters.isEmpty()) {
- return generateRequestBody(parameters);
- } else {
- return null;
- }
- }
-
- /**
- * Return the request body as a string.
- *
- * @return the request body as a string
- * @throws IOException If an IO problem occurs.
- *
- * @since 2.0
- */
- public String getRequestBodyAsString() throws IOException {
- LOG.trace("enter PostMethod.getRequestBodyAsString()");
-
- StringBuffer buffer = new StringBuffer();
- InputStream requestBody = getRequestBody();
- int data = requestBody.read();
-
- while (data != -1) {
- buffer.append((char) data);
- data = requestBody.read();
- }
-
- return buffer.toString();
- }
-
- /**
- * Sets length information about the request body.
- *
- * <p>
- * Note: If you specify a content length the request is unbuffered. This
- * prevents redirection and automatic retry if a request fails the first
- * time. This means that the HttpClient can not perform authorization
- * automatically but will throw an Exception. You will have to set the
- * necessary 'Authorization' or 'Proxy-Authorization' headers manually.
- * </p>
- *
- * @param length size in bytes or any of CONTENT_LENGTH_AUTO,
- * CONTENT_LENGTH_CHUNKED. If number of bytes or CONTENT_LENGTH_CHUNKED
- * is specified the content will not be buffered internally and the
- * Content-Length header of the request will be used. In this case
- * the user is responsible to supply the correct content length.
- * If CONTENT_LENGTH_AUTO is specified the request will be buffered
- * before it is sent over the network.
- * @throws RuntimeException if chunked transfer encoding is requested for
- * a HTTP 1.0 request
- *
- * @since 2.0
- */
- public void setRequestContentLength(int length)
- throws RuntimeException {
- //TODO: We should be throwing a more specific exception than this.
-
- LOG.trace("enter PostMethod.setRequestContentLength(int)");
-
- if ((length == CONTENT_LENGTH_CHUNKED) && !isHttp11()) {
- throw new RuntimeException(
- "Chunked transfer encoding not allowed for HTTP/1.0");
- }
-
- requestContentLength = length;
- }
-
- /**
* Add a new parameter to be used in the POST request body.
*
* @param paramName The parameter name to add.
* @param paramValue The parameter value to add.
*
- * @throws IllegalStateException if my request body has already been
- * generated.
* @throws IllegalArgumentException if either argument is null
*
* @since 1.0
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public void addParameter(String paramName, String paramValue)
- throws IllegalStateException, IllegalArgumentException {
-
- LOG.trace("enter PostMethod.addParameter(String, String)");
-
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
- }
+ public void addParameter(String paramName, String paramValue) {
+ log.trace("enter PostMethod.addParameter(String, String)");
if ((paramName == null) || (paramValue == null)) {
throw new IllegalArgumentException(
"Arguments to addParameter(String, String) cannot be null");
} else {
- parameters.add(new NameValuePair(paramName, paramValue));
+ deprecated_parameters.add(new NameValuePair(paramName, paramValue));
}
+ setRequestBody(getParameters());
}
/**
@@ -500,26 +302,18 @@
*
* @param param The parameter to add.
*
- * @throws IllegalStateException if my request body has already been
- * generated.
* @throws IllegalArgumentException if the argument is null or contains
* null values
*
* @since 2.0
- * @see #addParameter(String,String)
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public void addParameter(NameValuePair param)
- throws IllegalStateException, IllegalArgumentException {
-
- LOG.trace("enter PostMethod.addParameter(NameValuePair)");
+ public void addParameter(NameValuePair param) {
+ log.trace("enter PostMethod.addParameter(NameValuePair)");
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
- }
-
- if (null == param) {
- throw new IllegalArgumentException(
- "Argument to addParameter(NameValuePair) cannot be null");
+ if (param == null) {
+ throw new IllegalArgumentException("NameValuePair may not be null");
} else {
addParameter(param.getName(), param.getValue());
}
@@ -531,23 +325,15 @@
*
* @param parameters The array of parameters to add.
*
- * @throws IllegalStateException if my request body has already been
- * generated.
- *
* @since 2.0
- * @see #addParameter(org.apache.commons.httpclient.NameValuePair)
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public void addParameters(NameValuePair[] parameters)
- throws IllegalStateException {
-
- LOG.trace("enter PostMethod.addParameters(NameValuePair[])");
+ public void addParameters(NameValuePair[] parameters) {
+ log.trace("enter PostMethod.addParameters(NameValuePair[])");
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
- }
-
- if (null == parameters) {
- LOG.warn("Attempt to addParameters(null) ignored");
+ if (parameters == null) {
+ log.warn("Attempt to addParameters(null) ignored");
} else {
for (int i = 0; i < parameters.length; i++) {
addParameter(parameters[i]);
@@ -556,22 +342,6 @@
}
/**
- * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
- * to clear my request body.
- *
- * @since 1.0
- */
- public void recycle() {
- LOG.trace("enter PostMethod.recycle()");
- super.recycle();
- requestBody = null;
- requestContentLength = CONTENT_LENGTH_AUTO;
- buffer = null;
- repeatCount = 0;
- parameters.clear();
- }
-
- /**
* Removes all parameters with the given paramName. If there is more than
* one parameter with the given paramName, all of them are removed. If
* there is just one, it is removed. If there are none, then the request
@@ -581,28 +351,21 @@
*
* @return true if at least one parameter was removed
*
- * @throws IllegalStateException if my request body has already been
- * generated.
* @throws IllegalArgumentException When the parameter name passed is null
*
* @since 2.0
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public boolean removeParameter(String paramName)
- throws IllegalArgumentException, IllegalStateException {
-
- LOG.trace("enter PostMethod.removeParameter(String)");
-
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
- }
+ public boolean removeParameter(String paramName) {
+ log.trace("enter PostMethod.removeParameter(String)");
if (paramName == null) {
throw new IllegalArgumentException(
"Argument passed to removeParameter(String) cannot be null");
}
-
boolean removed = true;
- Iterator iter = parameters.iterator();
+ Iterator iter = deprecated_parameters.iterator();
while (iter.hasNext()) {
NameValuePair pair = (NameValuePair) iter.next();
@@ -612,7 +375,7 @@
removed = true;
}
}
-
+ setRequestBody(getParameters());
return removed;
}
@@ -626,28 +389,23 @@
*
* @return true if a parameter was removed.
*
- * @throws IllegalStateException if my request body has already been
- * generated.
* @throws IllegalArgumentException when param name or value are null
*
* @since 2.0
+ *
+ * @deprecated use {@link #setRequestBody(NameValuePair[])}.
*/
- public boolean removeParameter(String paramName, String paramValue)
- throws IllegalArgumentException, IllegalStateException {
-
- LOG.trace("enter PostMethod.removeParameter(String, String)");
+ public boolean removeParameter(String paramName, String paramValue) {
+ log.trace("enter PostMethod.removeParameter(String, String)");
- if (null != requestBody) {
- throw new IllegalStateException("Request body already generated.");
+ if (paramName == null) {
+ throw new IllegalArgumentException("Parameter name may not be null");
}
-
- if ((paramName == null) || (paramValue == null)) {
- throw new IllegalArgumentException(
- "Argument passed to removeParameter(String,String) cannot be "
- + "null");
+ if (paramValue == null) {
+ throw new IllegalArgumentException("Parameter value may not be null");
}
- Iterator iter = parameters.iterator();
+ Iterator iter = deprecated_parameters.iterator();
while (iter.hasNext()) {
NameValuePair pair = (NameValuePair) iter.next();
@@ -655,149 +413,33 @@
if (paramName.equals(pair.getName())
&& paramValue.equals(pair.getValue())) {
iter.remove();
-
return true;
}
}
-
+ setRequestBody(getParameters());
return false;
}
/**
- * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
- * to return the length of the request body.
- *
- * @return number of bytes in the request body
- *
- * @since 2.0
- */
- protected int getRequestContentLength() {
- LOG.trace("enter PostMethod.getRequestContentLength()");
-
- if (null == requestBody) {
- requestBody = generateRequestBody(parameters);
- bufferContent();
- }
-
- if (requestContentLength != CONTENT_LENGTH_AUTO) {
- return requestContentLength;
- }
-
- bufferContent();
-
- return requestContentLength;
- }
-
- /**
- * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
- * to also add <tt>Content-Type</tt> header when appropriate.
- *
- * @param state DOCUMENT ME!
- * @param conn DOCUMENT ME!
- * @throws IOException DOCUMENT ME!
- * @throws HttpException DOCUMENT ME!
+ * Set an Array of parameters to be used in the POST request body
*
- * @since 2.0
- */
- protected void addRequestHeaders(HttpState state, HttpConnection conn)
- throws IOException, HttpException {
- super.addRequestHeaders(state, conn);
-
- if (!parameters.isEmpty()) {
- //there are some parameters, so set the contentType header
- setRequestHeader(CONTENT_TYPE);
- }
- }
-
- /**
- * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
- * to write request parameters as the request body. The input stream will
- * be truncated after the specified content length.
- *
- * @param state DOCUMENT ME!
- * @param conn DOCUMENT ME!
- *
- * @return always returns true
- *
- * @throws IOException if the stream ends before the specified content
- * length. <p>
- * @throws HttpException DOCUMENT ME!
+ * @param parameters The array of parameters to add.
*
- * @since 2.0
+ * @throws IllegalArgumentException when param parameters are null
+ *
+ * @since 2.0beta1
*/
- protected boolean writeRequestBody(HttpState state, HttpConnection conn)
- throws IOException, HttpException {
- LOG.trace(
- "enter PostMethod.writeRequestBody(HttpState, HttpConnection)");
- if (null == requestBody) {
- requestBody = generateRequestBody(parameters);
- }
+ public void setRequestBody(NameValuePair[] parameters) {
+ log.trace("enter PostMethod.setRequestBody(NameValuePair[])");
- if ((repeatCount > 0) && (buffer == null)) {
- throw new HttpException(
- "Sorry, unbuffered POST request can not be repeated.");
+ if (parameters == null) {
+ throw new IllegalArgumentException("Array of parameters may not be null");
}
-
- repeatCount++;
-
- InputStream instream = this.requestBody;
- OutputStream outstream = conn.getRequestOutputStream();
-
- if (this.requestContentLength == CONTENT_LENGTH_CHUNKED) {
- outstream = new ChunkedOutputStream(outstream);
- }
- if (this.requestContentLength >= 0) {
- // don't need a watcher here - we're reading from something local,
- // not server-side.
- instream = new ContentLengthInputStream(instream, this.requestContentLength);
- }
-
- byte[] tmp = new byte[4096];
- int total = 0;
- int i = 0;
- while ((i = instream.read(tmp)) >= 0) {
- outstream.write(tmp, 0, i);
- total += i;
- }
- if (outstream instanceof ChunkedOutputStream) {
- ((ChunkedOutputStream) outstream).writeClosingChunk();
- }
- if ((this.requestContentLength > 0) && (total < this.requestContentLength)) {
- throw new IOException("Unexpected end of input stream after "
- + total + " bytes (expected "
- + this.requestContentLength + " bytes)");
- }
-
- if (buffer != null) {
- //restore buffered content for repeated requests
- requestBody = new ByteArrayInputStream(buffer.toByteArray());
- }
-
- return true;
+ super.setRequestBody(generateRequestBody(parameters));
+ this.contentEnconding = URL_ENCODED_CONTENT;
}
-
- /**
- * Encode the list of parameters into a query stream.
- *
- * @param params the list of query name and value
- *
- * @return the query stream
- *
- * @since 1.0
- */
- protected InputStream generateRequestBody(List params) {
- LOG.trace("enter PostMethod.generateRequestBody(List)");
- String body = generateRequestBodyAsString(params);
-
- return new ByteArrayInputStream(
- HttpConstants.getContentBytes(body, getRequestCharSet()));
- }
-
-
- // ------------------------------------------------------------Class Methods
-
/**
* Encode the list of parameters into a query string.
*
@@ -807,69 +449,113 @@
*
* @since 2.0
*/
- protected static String generateRequestBodyAsString(List params) {
- LOG.trace("enter PostMethod.generateRequestBodyAsString(List)");
+ protected static String generateRequestBody(NameValuePair[] parameters) {
+ log.trace("enter PostMethod.generateRequestBodyAsString(NameValuePair[])");
- Iterator it = params.iterator();
+ if (parameters == null) {
+ throw new IllegalArgumentException("Array of parameters may not be null");
+ }
StringBuffer buff = new StringBuffer();
- while (it.hasNext()) {
- NameValuePair parameter = (NameValuePair) it.next();
+ for(int i = 0; i < parameters.length; i++) {
+ if (i > 0) {
+ buff.append("&");
+ }
+
+ NameValuePair parameter = parameters[i];
String queryName = null;
try {
queryName = URIUtil.encodeWithinQuery(parameter.getName());
} catch (URIException urie) {
- LOG.error("encoding error within query name", urie);
+ log.error("encoding error within query name", urie);
queryName = parameter.getName();
}
buff.append(queryName).append("=");
String queryValue = null;
try {
queryValue = URIUtil.encodeWithinQuery(parameter.getValue());
- } catch (URIException urie) {
- LOG.error("encoding error within query value", urie);
+ } catch (URIException e) {
+ log.error("Encoding error within query value", e);
queryValue = parameter.getValue();
}
buff.append(queryValue);
- if (it.hasNext()) {
- buff.append("&");
- }
}
return buff.toString();
}
/**
- * Buffers the request body and calculates the content length. If the
- * method was called earlier it returns immediately.
+ * Sets the request body to be the specified string.
*
- * @since 1.0
+ * <p>
+ * Once this method has been invoked, the request parameters cannot be
+ * altered until I am {@link #recycle recycled}.
+ * </p>
+ *
+ * @param body Request body content as a string
+ *
+ * @since 2.0
*/
- private void bufferContent() {
- LOG.trace("enter PostMethod.bufferContent()");
+ public void setRequestBody(String body) {
+ log.trace("enter PostMethod.setRequestBody(String)");
- if (buffer != null) {
- return;
- }
+ super.setRequestBody(body);
+ this.contentEnconding = CUSTOM_CONTENT;
+ }
- try {
- buffer = new ByteArrayOutputStream();
+ /**
+ * Sets the request body to be the specified inputstream.
+ *
+ * <p>
+ * Once this method has been invoked, the request parameters cannot be
+ * altered until I am {@link #recycle recycled}.
+ * </p>
+ *
+ * @param body Request body content as {@link java.io.InputStream}
+ *
+ * @since 2.0
+ */
+ public void setRequestBody(InputStream body) {
+ log.trace("enter PostMethod.getRequestBody(InputStream)");
- byte[] data = new byte[10000];
- int l = requestBody.read(data);
- int total = 0;
+ super.setRequestBody(body);
+ this.contentEnconding = CUSTOM_CONTENT;
+ }
- while (l > 0) {
- buffer.write(data, 0, l);
- total += l;
- l = requestBody.read(data);
- }
+ /**
+ * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
+ * to also add <tt>Content-Type</tt> header when appropriate.
+ *
+ * @param state the client state
+ * @param conn the {@link HttpConnection} the headers will eventually be
+ * written to
+ * @throws IOException when an error occurs writing the request
+ * @throws HttpException when a HTTP protocol error occurs
+ *
+ * @since 2.0
+ */
+
+ protected void addRequestHeaders(HttpState state, HttpConnection conn)
+ throws IOException, HttpException {
+ super.addRequestHeaders(state, conn);
- requestBody = new ByteArrayInputStream(buffer.toByteArray());
- requestContentLength = total;
- } catch (IOException e) {
- requestBody = null;
- requestContentLength = 0;
+ if (this.contentEnconding == URL_ENCODED_CONTENT) {
+ //there are some parameters, so set the contentType header
+ setRequestHeader(URL_ENCODED_CONTENT_TYPE);
}
}
+
+ /**
+ * Override method of {@link org.apache.commons.httpclient.HttpMethodBase}
+ * to clear my request body.
+ *
+ * @since 1.0
+ */
+ public void recycle() {
+ log.trace("enter PostMethod.recycle()");
+ super.recycle();
+ this.contentEnconding = CUSTOM_CONTENT;
+ this.deprecated_parameters.clear();
+ }
+
}
1.21 +3 -228 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PutMethod.java 28 Jan 2003 22:25:28 -0000 1.20
+++ PutMethod.java 31 Jan 2003 23:23:16 -0000 1.21
@@ -2,7 +2,6 @@
* $Header$
* $Revision$
* $Date$
- *
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -63,34 +62,16 @@
package org.apache.commons.httpclient.methods;
-import org.apache.commons.httpclient.HttpConstants;
-import org.apache.commons.httpclient.HttpConnection;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethodBase;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-
-
/**
* PUT Method.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
*
* @since 1.0
*/
-public class PutMethod extends HttpMethodBase {
+public class PutMethod extends EntityEnclosingMethod {
// ----------------------------------------------------------- Constructors
@@ -102,7 +83,7 @@
* @since 1.0
*/
public PutMethod() {
- setFollowRedirects(false);
+ super();
}
@@ -115,31 +96,8 @@
*/
public PutMethod(String uri) {
super(uri);
- setFollowRedirects(false);
}
-
- // ------------------------------------------------------- Instance Methods
-
-
- /**
- * Request body content to be sent.
- */
- private byte[] data = null;
-
-
- /**
- * Request body content to be sent.
- */
- private File file = null;
-
-
- /**
- * Request body content to be sent.
- */
- private URL url = null;
-
-
// --------------------------------------------------------- Public Methods
/**
@@ -151,187 +109,4 @@
public String getName() {
return "PUT";
}
-
- /**
- * Set my request body content to the contents of a file.
- *
- * @param file The file
- * @throws IOException if an IO problem occurs
- * @since 2.0
- */
- public void setRequestBody(File file) throws IOException {
- checkNotUsed();
- this.file = file;
- }
-
- /**
- * Set my request body content to the resource at the specified URL.
- *
- * @param url The URL
- * @throws IOException If an IO problem occurs.
- * @since 2.0
- */
- public void setRequestBody(URL url) throws IOException {
- checkNotUsed();
- this.url = url;
- }
-
- /**
- * Set my request body content to the contents of a byte array.
- *
- * @param bodydata The new content.
- * @since 2.0
- */
- public void setRequestBody(byte[] bodydata) {
- checkNotUsed();
- this.data = bodydata;
- }
-
- /**
- * Set my request body content to the contents of a string.
- *
- * @param bodydata The new content
- * @since 2.0
- */
- public void setRequestBody(String bodydata) {
- checkNotUsed();
- setRequestBody(HttpConstants.getContentBytes(bodydata, getRequestCharSet()));
- }
-
- /**
- * Set my request body content to the contents of an input stream. The
- * contents will be buffered into memory. To upload large entities, it is
- * recommended to first buffer the data into a temporary file, and then send
- * that file.
- *
- * @param is The input stream.
- * @throws IOException If an IO problem occurs
- * @since 2.0
- */
- public void setRequestBody(InputStream is) throws IOException {
- LOG.trace("enter PutMethod.setRequestBody(InputStream)");
-
- checkNotUsed();
- byte[] buffer = new byte[4096];
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- int nb = 0;
- while (true) {
- nb = is.read(buffer);
- if (nb == -1) {
- break;
- }
- os.write(buffer, 0, nb);
- }
- data = os.toByteArray();
- }
-
-
- // ------------------------------------------------- HttpMethodBase Methods
-
- /**
- * Override the method of {@link HttpMethodBase} to set the <tt>Expect</tt>
- * header if it has not already been set, in addition to the "standard" set
- * of headers.
- *
- * @param state The state.
- * @param conn The connection.
- * @throws IOException If an IO problem occurs
- * @throws HttpException Never.
- * @since 2.0
- */
- protected void addRequestHeaders(HttpState state, HttpConnection conn)
- throws IOException, HttpException {
- // TODO: Determine why this method is declared to throw HttpException
- // since it never actually does throw it.
- LOG.trace("enter PutMethod.addRequestHeaders(HttpState, HttpConnection)");
-
- super.addRequestHeaders(state, conn);
- // Send expectation header
- if (isHttp11() && null == getRequestHeader("expect")) {
- setRequestHeader("Expect", "100-continue");
- }
- }
-
- /**
- * Override the method of {@link HttpMethodBase} to not send any data until
- * the <tt>100 Continue</tt> status has not be read.
- *
- * @param state The state
- * @param conn The connection
- * @return true if the data was written.
- * @throws IOException If an IO problem occurs
- * @throws HttpException This doesn't ever seem to be thrown.
- * @since 2.0
- */
- protected boolean writeRequestBody(HttpState state, HttpConnection conn)
- throws IOException, HttpException {
- LOG.trace("enter PutMethod.writeRequestBody(HttpState, HttpConnection)");
- if (getStatusLine() == null) {
- return false;
- }
- if (null != getRequestHeader("expect")
- && getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) {
- return false;
- }
- OutputStream out = conn.getRequestOutputStream((isHttp11()
- && (null == getRequestHeader("Content-Length"))));
-
- InputStream inputStream = null;
- if (file != null && file.exists()) {
- inputStream = new FileInputStream(file);
- } else if (url != null) {
- inputStream = url.openConnection().getInputStream();
- } else if (data != null) {
- inputStream = new ByteArrayInputStream(data);
- } else {
- return true;
- }
-
- byte[] buffer = new byte[4096];
- int nb = 0;
- while (true) {
- nb = inputStream.read(buffer);
- if (nb == -1) {
- break;
- }
- out.write(buffer, 0, nb);
- }
- out.flush();
- return true;
- }
-
- /**
- * Override the method of {@link HttpMethodBase}
- * to return the appropriate content length.
- *
- * @return the content length
- * @since 2.0
- */
- protected int getRequestContentLength() {
- LOG.trace("enter PutMethod.getRequestContentLength()");
-
- if (null != data) {
- return data.length;
- } else if (null != file && file.exists()) {
- return (int) (file.length());
- } else if (url != null) {
- return -1;
- } else {
- return 0;
- }
- }
-
- /**
- *
- * @since 1.0
- */
- public void recycle() {
- super.recycle();
- data = null;
- url = null;
- file = null;
- }
-
- /** Log object for this class. */
- private static final Log LOG = LogFactory.getLog(PutMethod.class);
}
1.8 +8 -3 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java
Index: SimpleHttpConnection.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SimpleHttpConnection.java 25 Jan 2003 12:52:07 -0000 1.7
+++ SimpleHttpConnection.java 31 Jan 2003 23:23:17 -0000 1.8
@@ -180,6 +180,11 @@
return str;
}
+ public boolean waitForResponse(long timeout_ms)
+ throws IOException, IllegalStateException {
+ return true;
+ }
+
public InputStream getResponseInputStream() {
return bodyInputStream;
1.14 +7 -104 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
Index: TestMethodsNoHost.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TestMethodsNoHost.java 23 Jan 2003 22:48:27 -0000 1.13
+++ TestMethodsNoHost.java 31 Jan 2003 23:23:17 -0000 1.14
@@ -106,102 +106,16 @@
// ----------------------------------------------------------------- Tests
- public void testPostCantAddParamAfterBodySet() throws Exception {
- PostMethod post = new PostMethod("/foo");
- post.setRequestBody("this+is+the+body");
- try {
- post.addParameter("name","value");
- fail("Expected IllegalStateException");
- } catch(IllegalStateException e) {
- // expected
- }
- }
-
- /** Ensure setRequestBody fails after addParameter is called. */
- public void testPostCantSetBodyAfterAddParam() throws Exception {
- PostMethod post = new PostMethod("/foo");
- post.addParameter("name","value");
- try {
- post.setRequestBody("this+is+the+body");
- fail("Expected IllegalStateException");
- } catch(IllegalStateException e) {
- // expected
- }
- }
-
-
- /** Ensure that parameters can be added and getted. */
- public void testPostAddGetParameter() {
- PostMethod post = new PostMethod();
-
- //no parameters
- assertNull(post.getParameter("non-existant"));
- assertEquals(0, post.getParameters().length);
-
- //add one parameter
- post.addParameter(NAME,VALUE);
- assertEquals(PAIR, post.getParameter(NAME));
- assertEquals(1, post.getParameters().length);
-
- //add another parameter
- post.addParameter(PAIR0);
- assertEquals(PAIR0, post.getParameter(PAIR0.getName()));
- assertEquals(2, post.getParameters().length);
-
- //add two more parameters
- post.addParameters(new NameValuePair[]{ PAIR1, PAIR2 });
- assertEquals(4, post.getParameters().length);
- NameValuePair[] parameters = post.getParameters();
- for (int i=0; i<parameters.length; i++){
- NameValuePair pair = parameters[i];
- assertEquals(pair, post.getParameter(pair.getName()));
- }
- }
-
- /** Exercise some unusual and error conditions. */
- public void testPostAddParameterErrorCases() {
- PostMethod post = new PostMethod();
-
- //add null paramters
- try{
- post.addParameter(null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) { }
-
- try{
- post.addParameter(null, "value");
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) { }
-
- try{
- post.addParameter("name", null);
- fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) { }
- }
-
- /** Adding the same parameter twice should be OK. */
- public void testPostAddSameParameter() {
- PostMethod post = new PostMethod();
-
- //add same parameter twice
- post.addParameter(PAIR0);
- post.addParameter(PAIR0);
-
- assertEquals(2, post.getParameters().length);
- NameValuePair[] pairs = post.getParameters();
- assertEquals(pairs[0], pairs[1]);
- }
-
public void testPostParametersEncoding() throws IOException {
PostMethod post = new PostMethod();
- post.addParameter(PAIR);
+ post.setRequestBody(new NameValuePair[] { PAIR });
assertEquals("name=value", post.getRequestBodyAsString());
- post.addParameters(new NameValuePair[]{ PAIR1, PAIR2 });
+ post.setRequestBody(new NameValuePair[]{ PAIR, PAIR1, PAIR2 });
assertEquals("name=value&name1=value1&name2=value2",
post.getRequestBodyAsString());
- post.addParameter("hasSpace", "a b c d");
+ post.setRequestBody(new NameValuePair[]{ PAIR, PAIR1, PAIR2, new NameValuePair("hasSpace", "a b c d") });
assertEquals("name=value&name1=value1&name2=value2&hasSpace=a%20b%20c%20d",
post.getRequestBodyAsString());
@@ -214,17 +128,6 @@
assertEquals(body, post.getRequestBodyAsString());
}
-
- public void testPostSetRequestBodyThrowsIllegalState() throws Exception {
- PostMethod post = new PostMethod("/foo");
- post.addParameter(NAME0, VALUE0);
- try {
- post.setRequestBody("this+is+the+body");
- fail("Expected IllegalStateException");
- } catch(IllegalStateException e) {
- // expected
- }
- }
public void testHttpMethodBasePaths() throws Exception {
HttpMethod simple = new SimpleHttpMethod();
1.5 +7 -9 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java
Index: TestMethodsRedirectNoHost.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestMethodsRedirectNoHost.java 25 Jan 2003 12:52:07 -0000 1.4
+++ TestMethodsRedirectNoHost.java 31 Jan 2003 23:23:17 -0000 1.5
@@ -147,13 +147,11 @@
conn.open();
PostMethod method = new PostMethod("/oldfile");
- method.setFollowRedirects(true);
- method.addParameter("name", "value");
+ method.setRequestBody(new NameValuePair[] { new NameValuePair("name", "value") } );
method.execute(new HttpState(), conn);
Header locationHeader = method.getResponseHeader("Location");
- assertEquals(200, method.getStatusCode());
- assertEquals(1, method.getParameters().length);
- assertEquals("/newfile", method.getPath());
+ assertEquals(302, method.getStatusCode());
+ assertEquals("/oldfile", method.getPath());
}
1.8 +6 -6 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappBasicAuth.java
Index: TestWebappBasicAuth.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappBasicAuth.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestWebappBasicAuth.java 23 Jan 2003 22:48:27 -0000 1.7
+++ TestWebappBasicAuth.java 31 Jan 2003 23:23:17 -0000 1.8
@@ -140,7 +140,7 @@
client.getState().setCredentials("BasicAuthServlet",new UsernamePasswordCredentials("jakarta","commons"));
client.getHostConfiguration().setHost(host, port, "http");
PostMethod method = new PostMethod("/" + context + "/auth/basic");
- method.addParameter("testing","one");
+ method.setRequestBody(new NameValuePair[] { new NameValuePair("testing","one") } );
method.setUseDisk(false);
try {
client.executeMethod(method);
@@ -154,7 +154,7 @@
method.recycle();
method.setPath("/" + context + "/auth/basic");
- method.addParameter("testing","one");
+ method.setRequestBody(new NameValuePair[] { new NameValuePair("testing","one") } );
try {
client.executeMethod(method);
} catch (Throwable t) {
1.8 +5 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java
Index: TestWebappCookie.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestWebappCookie.java 23 Jan 2003 22:48:28 -0000 1.7
+++ TestWebappCookie.java 31 Jan 2003 23:23:17 -0000 1.8
@@ -131,7 +131,7 @@
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(host, port, "http");
PostMethod method = new PostMethod("/" + context + "/cookie/write");
- method.addParameter("simple","set");
+ method.setRequestBody(new NameValuePair[] { new NameValuePair("simple","set") } );
method.setUseDisk(false);
try {
client.executeMethod(method);
1.12 +6 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java
Index: TestWebappMethods.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TestWebappMethods.java 23 Jan 2003 22:48:28 -0000 1.11
+++ TestWebappMethods.java 31 Jan 2003 23:23:17 -0000 1.12
@@ -298,7 +298,8 @@
client.getHostConfiguration().setHost(host, port, "http");
PostMethod method = new PostMethod("/" + context + "/body");
method.setUseDisk(false);
- method.addParameter("quote","It was the best of times, it was the worst of times.");
+ method.setRequestBody(new NameValuePair[] {
+ new NameValuePair("quote","It was the best of times, it was the worst of times.") } );
try {
client.executeMethod(method);
} catch (Throwable t) {
1.8 +7 -6 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappParameters.java
Index: TestWebappParameters.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappParameters.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestWebappParameters.java 23 Jan 2003 22:48:28 -0000 1.7
+++ TestWebappParameters.java 31 Jan 2003 23:23:18 -0000 1.8
@@ -271,8 +271,9 @@
client.getHostConfiguration().setHost(host, port, "http");
PostMethod method = new PostMethod("/" + context + "/params");
method.setQueryString("query=string");
- method.addParameter("param","eter");
- method.addParameter("para","meter");
+ method.setRequestBody(new NameValuePair[] {
+ new NameValuePair("param","eter"),
+ new NameValuePair("para","meter") } );
method.setUseDisk(false);
try {
client.executeMethod(method);
1.14 +5 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java
Index: TestWebappRedirect.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TestWebappRedirect.java 23 Jan 2003 22:48:28 -0000 1.13
+++ TestWebappRedirect.java 31 Jan 2003 23:23:18 -0000 1.14
@@ -242,7 +242,7 @@
fail("Unable to execute method : " + t.toString());
}
//buffered request is okay to redirect
- assertEquals(HttpStatus.SC_OK,method.getStatusCode());
+ assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode());
}
public void testPutRedirect() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org