[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit MessageBody.java,1.2,1.3 MessageBodyWebRe
Brought to you by:
russgold
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv2105/src/com/meterware/httpunit
Modified Files:
MessageBody.java MessageBodyWebRequest.java
MimeEncodedMessageBody.java PostMethodWebRequest.java
PutMethodWebRequest.java
Log Message:
input stream requests now contain content type
Index: MessageBody.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MessageBody.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MessageBody.java 2001/06/04 20:45:33 1.2
+++ MessageBody.java 2001/06/06 13:25:33 1.3
@@ -38,10 +38,20 @@
/**
- * Updates the headers for this request as needed.
+ * Returns the content type of this message body. For text messages, this
+ * should include the character set.
**/
abstract
- void updateHeaders( URLConnection connection ) throws IOException;
+ String getContentType();
+
+
+ /**
+ * Updates the headers for this request as needed.
+ * @deprecated use getContentType
+ **/
+ final
+ void updateHeaders( URLConnection connection ) throws IOException {
+ }
/**
Index: MessageBodyWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MessageBodyWebRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MessageBodyWebRequest.java 2001/06/04 20:45:33 1.1
+++ MessageBodyWebRequest.java 2001/06/06 13:25:33 1.2
@@ -57,7 +57,7 @@
connection.setDoOutput( true );
MessageBody mb = newMessageBody();
- mb.updateHeaders( connection );
+ connection.setRequestProperty( "Content-type", mb.getContentType() );
OutputStream stream = connection.getOutputStream();
mb.writeTo( stream );
stream.flush();
@@ -102,19 +102,21 @@
static class InputStreamMessageBody extends MessageBody {
- InputStreamMessageBody( MessageBodyWebRequest request, InputStream source ) {
+ InputStreamMessageBody( MessageBodyWebRequest request, InputStream source, String contentType ) {
super( request );
_source = source;
+ _contentType = contentType;
}
/**
- * Updates the headers for this request as needed.
+ * Returns the content type of this message body.
**/
- void updateHeaders( URLConnection connection ) throws IOException {
+ String getContentType() {
+ return _contentType;
}
-
-
+
+
/**
* Transmits the body of this request as a sequence of bytes.
**/
@@ -131,5 +133,6 @@
private InputStream _source;
+ private String _contentType;
}
}
Index: MimeEncodedMessageBody.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/MimeEncodedMessageBody.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MimeEncodedMessageBody.java 2001/06/04 20:45:33 1.6
+++ MimeEncodedMessageBody.java 2001/06/06 13:25:33 1.7
@@ -41,10 +41,10 @@
/**
- * Updates the headers for this request as needed.
+ * Returns the content type of this message body.
**/
- void updateHeaders( URLConnection connection ) throws IOException {
- connection.setRequestProperty( "Content-type", "multipart/form-data; boundary=" + BOUNDARY );
+ String getContentType() {
+ return "multipart/form-data; boundary=" + BOUNDARY;
}
Index: PostMethodWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PostMethodWebRequest.java 2001/06/04 20:45:33 1.13
+++ PostMethodWebRequest.java 2001/06/06 13:25:33 1.14
@@ -50,10 +50,13 @@
/**
* Constructs a web request using a specific absolute url string and input stream.
+ * @param urlString the URL to which the request should be issued
+ * @param source an input stream which will provide the body of this request
+ * @param contentType the MIME content type of the body, including any character set
**/
- public PostMethodWebRequest( String urlString, InputStream source ) {
+ public PostMethodWebRequest( String urlString, InputStream source, String contentType ) {
super( urlString );
- _source = source;
+ _body = new InputStreamMessageBody( this, source, contentType );
}
@@ -97,8 +100,8 @@
protected MessageBody newMessageBody() {
- if (_source != null) {
- return new InputStreamMessageBody( this, _source );
+ if (_body != null) {
+ return _body;
} else if (isMimeEncoded()) {
return new MimeEncodedMessageBody( this );
} else {
@@ -131,6 +134,7 @@
private Hashtable _files = new Hashtable();
private InputStream _source;
+ private MessageBody _body;
}
@@ -151,9 +155,10 @@
/**
- * Updates the headers for this request as needed.
+ * Returns the content type of this message body.
**/
- void updateHeaders( URLConnection connection ) throws IOException {
+ String getContentType() {
+ return "application/x-www-form-urlencoded; charset=" + getRequest().getCharacterSet();
}
Index: PutMethodWebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PutMethodWebRequest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PutMethodWebRequest.java 2001/06/04 20:45:33 1.1
+++ PutMethodWebRequest.java 2001/06/06 13:25:33 1.2
@@ -37,20 +37,18 @@
public class PutMethodWebRequest extends MessageBodyWebRequest {
- public PutMethodWebRequest( String url, InputStream source ) {
- super( url );
- _source = source;
- }
-
/**
- * Returns a message body based on the input stream.
+ * Constructs a web request using a specific absolute url string and input stream.
+ * @param urlString the URL to which the request should be issued
+ * @param source an input stream which will provide the body of this request
+ * @param contentType the MIME content type of the body, including any character set
**/
- protected MessageBody newMessageBody() {
- return new InputStreamMessageBody( this, _source );
+ public PutMethodWebRequest( String url, InputStream source, String contentType ) {
+ super( url );
+ _body = new InputStreamMessageBody( this, source, contentType );
}
-
/**
* Returns 'PUT' to indicate the method.
**/
@@ -58,6 +56,14 @@
return "PUT";
}
+
+ /**
+ * Returns a message body based on the input stream.
+ **/
+ protected MessageBody newMessageBody() {
+ return _body;
+ }
+
- private InputStream _source;
+ private MessageBody _body;
}
|