From ef8ed00e24cef07a8139eccad584f6fff45f1b3c Mon Sep 17 00:00:00 2001 From: Ken Gilmer Date: Wed, 23 Nov 2011 16:59:21 +0900 Subject: [PATCH] touge.restclient: allow POST and PUTs without content. --- .../src/org/touge/restclient/ReSTClient.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/org.touge.restclient/src/org/touge/restclient/ReSTClient.java b/org.touge.restclient/src/org/touge/restclient/ReSTClient.java index 9c11b26..4b75f25 100644 --- a/org.touge.restclient/src/org/touge/restclient/ReSTClient.java +++ b/org.touge.restclient/src/org/touge/restclient/ReSTClient.java @@ -627,24 +627,28 @@ public Response call(final HttpMethod method, final String url, final Res connection.setDoOutput(false); break; case POST: - connection.setDoOutput(true); - baos = new ByteArrayOutputStream(); - copy(content, baos); - writeRequestBody(connection, baos.toByteArray()); - baos.close(); + if (content != null) { + connection.setDoOutput(true); + baos = new ByteArrayOutputStream(); + copy(content, baos); + writeRequestBody(connection, baos.toByteArray()); + baos.close(); - if (debugStream != null) - debugMid(debugBuffer, new String(baos.toByteArray())); + if (debugStream != null) + debugMid(debugBuffer, new String(baos.toByteArray())); + } break; case PUT: - connection.setDoOutput(true); - baos = new ByteArrayOutputStream(); - copy(content, baos); - writeRequestBody(connection, baos.toByteArray()); - baos.close(); - - if (debugStream != null) - debugMid(debugBuffer, new String(baos.toByteArray())); + if (content != null) { + connection.setDoOutput(true); + baos = new ByteArrayOutputStream(); + copy(content, baos); + writeRequestBody(connection, baos.toByteArray()); + baos.close(); + + if (debugStream != null) + debugMid(debugBuffer, new String(baos.toByteArray())); + } break; case DELETE: connection.setDoInput(true);