Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed the callback for /pools/default/buckets/default

  • Loading branch information...
commit 4d2621124e04de72bb59ad0df25a6a374706caf9 1 parent 6efa34a
@trondn trondn authored
View
20 src/main/java/org/membase/jmembase/http/HttpRequestImpl.java
@@ -154,14 +154,18 @@ public void encodeResponse() {
output.add(buffer);
}
- if (chunkedResponse && out != null) {
- byte array[] = out.toByteArray();
- output.add(ByteBuffer.wrap(Integer.toHexString(array.length).getBytes()));
- output.add(ByteBuffer.wrap("\r\n".getBytes()));
- output.add(ByteBuffer.wrap(array));
- output.add(ByteBuffer.wrap("\r\n".getBytes()));
+ if (out != null) {
+ if (chunkedResponse) {
+ byte array[] = out.toByteArray();
+ output.add(ByteBuffer.wrap(Integer.toHexString(array.length).getBytes()));
+ output.add(ByteBuffer.wrap("\r\n".getBytes()));
+ output.add(ByteBuffer.wrap(array));
+ output.add(ByteBuffer.wrap("\r\n".getBytes()));
+ } else {
+ output.add(ByteBuffer.wrap(out.toByteArray()));
+ }
+ out = null;
}
- out = null;
}
private void purgeSendBuffers() {
@@ -182,7 +186,7 @@ private void purgeSendBuffers() {
public boolean shouldClose() {
purgeSendBuffers();
- return (output.isEmpty() && reasonCode != HttpReasonCode.OK);
+ return (output.isEmpty() && (reasonCode != HttpReasonCode.OK || !chunkedResponse));
}
public void startChunk() {
View
30 src/test/java/org/membase/jmembase/JMembaseTest.java
@@ -17,9 +17,11 @@
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
+import java.net.Socket;
import junit.framework.TestCase;
import org.membase.jmembase.http.HttpReasonCode;
import org.membase.jmembase.http.HttpRequestImpl;
@@ -36,15 +38,20 @@ public JMembaseTest(String testName) {
super(testName);
}
JMembase instance;
+ Thread thread;
+
@Override
protected void setUp() throws Exception {
super.setUp();
instance = new JMembase(8091, 100, 4096);
+ thread = new Thread(instance);
+ thread.start();
}
@Override
protected void tearDown() throws Exception {
+ thread.interrupt();
instance.close();
super.tearDown();
}
@@ -72,6 +79,29 @@ public void testHandleHttpRequest() throws IOException {
assert (request.getReasonCode() == HttpReasonCode.OK);
}
+ public void testHandleHttpRequestNetwork() throws IOException {
+ System.out.println("testHandleHttpRequest");
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+
+ pw.println("GET /pools/default/buckets/default HTTP/1.1");
+ pw.println("Authorization: Basic " + Base64.encode("Administrator:password"));
+ pw.println();
+ pw.flush();
+
+ BufferedReader r = new BufferedReader(new StringReader(sw.toString()));
+
+ Socket s = new Socket("localhost", 8091);
+ s.getOutputStream().write(sw.toString().getBytes());
+ s.getOutputStream().flush();
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
+ while (in.readLine() != null) {
+ /* Do nothing */
+ }
+ s.close();
+ }
+
public void testHandleHttpRequestMissingAuth() throws IOException {
System.out.println("testHandleHttpRequestMissingAuth");
StringWriter sw = new StringWriter();
Please sign in to comment.
Something went wrong with that request. Please try again.