提交 e2500b07 编写于 作者: K kohsuke

throwing away much of the early experiment

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17576 71c3de6d-444a-0410-be80-ed276b4c234a
上级 a540ed22
......@@ -14,7 +14,7 @@ import java.lang.reflect.Method;
public class CLI {
public static void main(final String[] args) throws Exception {
URL target = new URL("http://localhost:8080/duplexChannel");
ChunkedHttpStreamPair con = new ChunkedHttpStreamPair(target);
FullDuplexHttpStream con = new FullDuplexHttpStream(target);
ExecutorService pool = Executors.newCachedThreadPool();
Channel channel = new Channel("Chunked connection to "+target,
pool,con.getInputStream(),con.getOutputStream());
......
......@@ -16,7 +16,7 @@ import java.util.UUID;
*
* @author Kohsuke Kawaguchi
*/
public class ChunkedHttpStreamPair {
public class FullDuplexHttpStream {
private final URL target;
/**
* Uniquely identifies this connection, so that the server can bundle separate HTTP requests together.
......@@ -34,32 +34,19 @@ public class ChunkedHttpStreamPair {
return output;
}
public ChunkedHttpStreamPair(URL target) throws IOException {
public FullDuplexHttpStream(URL target) throws IOException {
this.target = target;
// server->client side is very simple
// server->client
HttpURLConnection con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST
con.setDoOutput(true); // request POST to avoid caching
con.setRequestMethod("POST");
con.addRequestProperty("Session",uuid.toString());
con.addRequestProperty("Side","download");
con.getOutputStream().close();
input = con.getInputStream();
// client->server needs to be chopped up into blocks since URLConnection
// doesn't allow POST without Content-Length
// output = new SequenceOutputStream(new HttpBlock(makeConnection())) {
// protected Block next(Block current) throws IOException {
// // wait for the server to finish the response
// // before initiating the next connection. This guarantees
// // that the uploaded data is handled in-order by the server
// ((HttpBlock)current).close();
//
// return new HttpBlock(makeConnection());
// }
// };
// chunked encoding
// client->server uses chunked encoded POST for unlimited capacity.
con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST
con.setRequestMethod("POST");
......@@ -69,35 +56,5 @@ public class ChunkedHttpStreamPair {
output = con.getOutputStream();
}
private class HttpBlock extends Block {
private final HttpURLConnection con;
private HttpBlock(HttpURLConnection con) throws IOException {
super(new FilterOutputStream(con.getOutputStream()) {
public void write(byte[] b, int off, int len) throws IOException {
out.write(b, off, len);
}
}, BLOCK_SIZE);
this.con = con;
}
void close() throws IOException {
con.getInputStream().read();
}
}
private HttpURLConnection makeConnection() throws IOException {
HttpURLConnection con = (HttpURLConnection) target.openConnection();
con.setDoOutput(true); // request POST
con.setRequestMethod("POST");
con.addRequestProperty("User-Agent","Hudson");
con.addRequestProperty("Session",uuid.toString());
con.addRequestProperty("Side","upload");
con.setFixedLengthStreamingMode(BLOCK_SIZE);
con.connect();
return con;
}
static final int BLOCK_SIZE = 1024;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册