libexml-java-0.0.20080703.orig/ 0000755 0001750 0001750 00000000000 11111351376 015522 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/ 0000755 0001750 0001750 00000000000 11111351353 016474 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/ 0000755 0001750 0001750 00000000000 11111351351 017261 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/ 0000755 0001750 0001750 00000000000 11111351351 020240 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/java/ 0000755 0001750 0001750 00000000000 11111351351 021161 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/java/net/ 0000755 0001750 0001750 00000000000 11111351351 021747 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/ 0000755 0001750 0001750 00000000000 11111351351 024126 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/ 0000755 0001750 0001750 00000000000 11111351351 025105 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/GeneralDataPosterTest.java 0000644 0001750 0001750 00000012350 10762067376 032203 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/**
* This class is for unit testing {@link DataPoster} classes.
*
* @author Elias Ross
* @version 1.0
*/
public class GeneralDataPosterTest
extends junit.framework.TestCase
{
public GeneralDataPosterTest(String name) {
super(name);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(GeneralDataPosterTest.class);
}
/*
public static junit.framework.TestSuite suite() {
return new org.hansel.CoverageDecorator(GeneralDataPosterTest.class,
new Class[] { GeneralDataPoster.class });
}
*/
/**
* Doesn't allow marking.
*/
class ByteArrayInputStream2 extends ByteArrayInputStream {
boolean tested = false;
ByteArrayInputStream2(byte[] buf) {
super(buf);
}
public boolean markSupported() {
tested = true;
return false;
}
public String toString() { return super.toString() + " tested=" + tested; }
}
public void testChunkLots()
throws Exception
{
int len = 1024 * 64;
byte b[] = new byte[len];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
DataPoster poster2 = new GeneralDataPoster(bais, -1);
poster2.sendData(baos);
InputStream is = new ChunkedInputStream(new ByteArrayInputStream(baos.toByteArray()));
int total = 0;
while (true) {
int got = is.read(b);
if (got == -1)
break;
total += got;
}
assertEquals("got back lots of bytes", len, total);
}
public void testChunk()
throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1, 2, 3 });
DataPoster poster2 = new GeneralDataPoster(bais, -1);
poster2.sendData(baos);
byte b[] = new byte[3];
InputStream is = new ChunkedInputStream(new ByteArrayInputStream(baos.toByteArray()));
int got = is.read(b);
assertEquals("got back 3 bytes", 3, got);
assertEquals("got back 1 2 3", 1, b[0]);
assertEquals("got back 1 2 3", 2, b[1]);
assertEquals("got back 1 2 3", 3, b[2]);
}
public void testRepost()
throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] { 1, 2, 3 });
DataPoster poster2 = new GeneralDataPoster(bais, 2);
poster2.sendData(baos);
assertEquals("wrote 2 bytes", 2, baos.size());
poster2.sendData(baos);
assertEquals("wrote 4 bytes", 4, baos.size());
poster2.sendData(baos);
assertEquals("wrote 6 bytes", 6, baos.size());
}
public void testCoverage()
throws Exception
{
GeneralDataPoster gdp = new GeneralDataPoster();
gdp.toString();
gdp.init(null, 0);
gdp.init(null, 0);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
gdp.sendData(bos);
assertEquals(0, bos.size());
}
public void testRepostChunked()
throws Exception
{
GeneralDataPoster gdp = new GeneralDataPoster();
// use chunked
gdp.init(new ByteArrayInputStream(new byte[]{ 'a', 'b' }), -1);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
gdp.sendData(bos);
gdp.sendData(bos);
byte[] a = bos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(a);
ChunkedInputStream cis;
cis = new ChunkedInputStream(bais);
assertEquals('a', cis.read());
assertEquals('b', cis.read());
assertEquals(-1, cis.read());
cis.close();
cis = new ChunkedInputStream(bais);
assertEquals('a', cis.read());
assertEquals('b', cis.read());
}
public void testExceptions()
throws Exception
{
try {
new GeneralDataPoster(null, 10);
fail("null InputStream with non-zero length");
} catch (IllegalArgumentException e) { }
DataPoster poster = new GeneralDataPoster(null, 0);
try {
poster.sendData(null);
fail("null os");
} catch (IllegalArgumentException e) { }
ByteArrayOutputStream baos;
InputStream bais;
DataPoster poster2;
baos = new ByteArrayOutputStream();
bais = new ByteArrayInputStream2(new byte[] { 1, 2, 3 });
poster2 = new GeneralDataPoster(bais, 2);
poster2.sendData(baos);
try {
poster2.sendData(baos);
fail("cannot reset input stream");
} catch (HttpException e) { }
assertEquals("only wrote 2 bytes", 2, baos.size());
baos = new ByteArrayOutputStream();
bais = new ByteArrayInputStream(new byte[] { 1, 2, 3 });
poster2 = new GeneralDataPoster(bais, 4);
try {
poster2.sendData(baos);
fail("not enough data");
} catch (HttpException e) { }
assertEquals("only wrote 3 bytes", 3, baos.size());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/EasyHttpClientTest.java 0000644 0001750 0001750 00000031162 10762067376 031541 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* This class is for unit testing {@link EasyHttpClient}.
*
* @author Elias Ross
* @version 1.0
*/
public class EasyHttpClientTest extends junit.framework.TestCase {
public EasyHttpClientTest(String name) {
super(name);
}
public static class MyHttpServer extends ThreadedHttpServer {
boolean doRead = true;
boolean doPost = true;
boolean doClose = false;
boolean fail = false;
boolean failAlways = false;
int sleep = 1;
volatile int requestCount = 0;
StatusLine statusLine = StatusLine.HTTP11_200_OK;
ServerRequest request;
public MyHttpServer() throws IOException {
super();
}
public void handleRequest(Request req) throws IOException {
HttpServer s = req.getServer();
// System.out.println("handleRequest " + s);
requestCount++;
request = s.readRequest();
// System.out.println("handleRequest " + request);
InputStream is = request.getInputStream();
is = HttpUtil.wrapInputStream(is, request.getHeaders());
String result = "got ";
if (doRead) {
BufferedReader in = new BufferedReader(
new InputStreamReader(is));
String line = in.readLine();
result += line;
}
if (fail) {
fail = failAlways;
throw new IOException("Told to fail");
}
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
System.out.println("Interrupted");
throw new IOException("Wakeup");
}
if (doPost) {
MessageHeader mh;
mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, ""
+ result.length());
s.writeResponse(new ServerResponse(statusLine,
new MessageHeader[] { mh }));
PrintWriter out = new PrintWriter(new OutputStreamWriter(s
.getOutputStream()));
out.println(result);
out.flush();
} else {
if (doClose) {
MessageHeader mh;
mh = new MessageHeader(MessageHeader.FN_CONNECTION, "close");
s.writeResponse(new ServerResponse(statusLine,
new MessageHeader[] { mh }));
s.getOutputStream().close();
} else {
MessageHeader mh;
mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "0");
s.writeResponse(new ServerResponse(statusLine,
new MessageHeader[] { mh }));
}
}
}
}
private class EasyHttpClientFactory2 {
HttpClient c;
EasyHttpClientFactory2(Socket s) throws IOException {
c = new BasicHttpClient(s.getOutputStream(), s.getInputStream());
}
public EasyHttpClient makeGetClient(URL url) {
return new EasyHttpClient(c, url, Method.GET);
}
public EasyHttpClient makePostClient(URL url) {
return new EasyHttpClient(c, url, Method.POST);
}
public EasyHttpClient makeClient(URL url, Method method) {
return new EasyHttpClient(c, url, method);
}
}
public void testEasyGet() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
Socket s = new Socket("127.0.0.1", server.getPort());
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
URL url = new URL("http://localhost");
EasyHttpClient ec;
ec = factory.makeGetClient(url);
assertEquals(null, ec.getLastResponse());
ec = factory.makeGetClient(url);
BufferedReader br;
br = ec.doGet();
String got = HttpUtil.read(br).trim();
assertEquals("got", got);
assertEquals("/", server.request.getRequestLine().getRequestURI());
// try again
ec.setFile("/otherfile");
HttpUtil.discard(ec.doGet());
assertEquals("/otherfile", server.request.getRequestLine()
.getRequestURI());
// try 404
ec.setFile("/otherfile2");
server.statusLine = StatusLine.HTTP11_404;
try {
HttpUtil.read(ec.doGet());
fail("Bad HTTP status" + ec.getLastResponse());
} catch (HttpException e) {
}
assertEquals(404, ec.getLastResponse().getStatusLine().getStatusCode());
// ignore 404
ec.setCheckStatus(false);
br = ec.doGet();
assertEquals(404, ec.getLastResponse().getStatusLine().getStatusCode());
got = HttpUtil.read(br).trim();
assertEquals("got", got);
}
public void testEasyPostRetry() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.fail = true;
server.failAlways = false;
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClient ec = new EasyHttpClient(url, Method.POST);
String body = "abc=def";
BufferedReader br = ec.doPostUrlEncoded(body.getBytes());
String got = HttpUtil.read(br).trim();
assertEquals("got " + body, got);
assertTrue("we tossed", server.requestCount >= 2);
}
public void testEasyPostRetry2() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.fail = true;
server.failAlways = true;
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClient ec = new EasyHttpClient(url, Method.POST);
try {
ec.doPostUrlEncoded("who cares\n".getBytes());
fail("should have failed");
} catch (IOException e) {
}
assertTrue("failed four times", server.requestCount >= 3);
}
/**
* Doesn't allow marking.
*/
class ByteArrayInputStream2 extends ByteArrayInputStream {
boolean tested = false;
ByteArrayInputStream2(byte[] buf) {
super(buf);
}
public boolean markSupported() {
tested = true;
return false;
}
public String toString() {
return super.toString() + " tested=" + tested;
}
}
public void testEasyPostRetry3() throws IOException {
MyHttpServer server = new MyHttpServer();
server.start();
server.fail = true;
server.failAlways = true;
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClient ec = new EasyHttpClient(url, Method.POST);
String body = "something\n";
ByteArrayInputStream2 is = new ByteArrayInputStream2(body.getBytes());
try {
ec.doOperation(is, -1, "text/plain");
fail("cannot re-post " + is.tested + " " + ec.getLastResponse());
} catch (HttpException e) {
}
}
public void testEasyPost() throws Exception {
ThreadedHttpServer server = new MyHttpServer();
server.start();
Socket s = new Socket("127.0.0.1", server.getPort());
URL url = new URL("http://localhost/");
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
EasyHttpClient ec = factory.makePostClient(url);
Map map = new HashMap();
map.put("a", "b");
byte[] body = HttpUtil.urlEncode(map);
BufferedReader br = ec.doPostUrlEncoded(body);
String got = HttpUtil.read(br).trim();
assertEquals("got " + new String(body), got);
ec.close();
try {
ec.doPostUrlEncoded(body);
fail("already closed");
} catch (IllegalStateException e) {
}
}
public void testEasyException() throws Exception {
HttpClient c = new BasicHttpClient(new ByteArrayOutputStream(),
new ByteArrayInputStream(new byte[0]));
MessageHeaders mh = new MessageHeaders();
RequestLine rl = new RequestLine(Method.DELETE, "/", HttpVersion.HTTP11);
try {
new EasyHttpClient(null, rl, mh);
} catch (IllegalArgumentException e) {
}
try {
new EasyHttpClient(c, null, mh);
} catch (IllegalArgumentException e) {
}
try {
new EasyHttpClient(c, rl, null);
} catch (IllegalArgumentException e) {
}
}
public void testEasyOperation() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
Socket s = new Socket("127.0.0.1", server.getPort());
URL url = new URL("http://localhost/");
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
EasyHttpClient ec = factory.makePostClient(url);
String str = "yo!\n";
ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
InputStream is = ec.doOperation(bais, str.length(), "text/plain");
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String got = HttpUtil.read(in);
String fct = server.request.getHeaders().getFieldContent(
MessageHeader.FN_CONTENT_TYPE);
String fcl = server.request.getHeaders().getFieldContent(
MessageHeader.FN_CONTENT_LENGTH);
assertEquals("text/plain", fct);
assertEquals("4", fcl);
assertEquals(("got " + str).trim(), got.trim());
// no length set
try {
ec.doOperation(null, 10, null);
fail("need input stream with length");
} catch (IllegalArgumentException e) {
}
}
public void testGrabBag() throws Exception {
MyHttpServer server = new MyHttpServer();
server.doRead = false;
server.doPost = false;
server.fail = true;
server.failAlways = true;
Socket s = new Socket("127.0.0.1", server.getPort());
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
URL url = new URL("http://localhost");
EasyHttpClient ec = factory.makeGetClient(url);
try {
ec.doPostUrlEncoded(null);
fail("null urlEncodedData");
} catch (IllegalArgumentException e) {
}
ec.toString();
try {
ec.doPostUrlEncoded(null);
fail("null urlEncodedData");
} catch (IllegalArgumentException e) {
}
}
/*
* public void testMain() throws Exception { EasyHttpClient.main(new
* String[] { }); EasyHttpClient.main(new String[] {
* "http://www.example.net" }); EasyHttpClient.main(new String[] {
* "http://www.example.net", "a=b" }); }
*/
public void testGetNoResponse() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
server.doPost = false;
server.statusLine = StatusLine.HTTP11_404;
Socket s = new Socket("127.0.0.1", server.getPort());
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
URL url = new URL("http://localhost");
EasyHttpClient ec = factory.makeGetClient(url);
ec.setCheckStatus(false);
BufferedReader br = ec.doGet();
assertTrue("got some sort of reply", br != null);
}
public void testEasyOperation2() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
server.doPost = false;
Socket s = new Socket("127.0.0.1", server.getPort());
URL url = new URL("http://localhost/");
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2(s);
EasyHttpClient ec = factory.makeClient(url, Method.DELETE);
ec.doOperation();
assertEquals(Method.DELETE, server.request.getRequestLine().getMethod());
// try again, use keep-alive
server.doPost = true;
ec.doOperation();
ec.close();
server.doPost = false;
// try again, this time the server returns empty document
s = new Socket("127.0.0.1", server.getPort());
factory = new EasyHttpClientFactory2(s);
ec = factory.makeClient(url, Method.DELETE);
ec.doOperation();
// server closes connection
server.doClose = true;
ec.doOperation();
}
public void testRetryClientTimeoutBug() throws Exception {
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
server.doPost = true;
server.sleep = 240 * 1000 * 3; // should cause timeout
URL url = new URL("http://localhost:" + server.getPort());
RetryHttpClient client = new RetryHttpClient(url, 3) {
protected void setSocketOptions(Socket socket) throws IOException {
socket.setSoTimeout(1 * 1000);
}
protected void retrySendRequest(IOException e, int failures) {
super.retrySendRequest(e, failures);
System.out.println("Retry " + e + " " + failures);
}
};
EasyHttpClient ec = new EasyHttpClient(client, url, Method.POST);
try {
ec.doOperation();
fail("need to time out!");
} catch (SocketTimeoutException e) {
}
server.interrupt();
System.out.println("should not timeout");
server.sleep = 1; // should not cause timeout
ec.doOperation();
server.close();
}
public void testMain() throws Exception {
EasyHttpClient.main(new String[0]);
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
EasyHttpClient.main(new String[] { "http://localhost:" + server.getPort() });
server.close();
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/MessageHeadersTest.java 0000644 0001750 0001750 00000005141 10762067376 031517 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.net.URL;
import junit.framework.TestCase;
public class MessageHeadersTest extends TestCase {
public void testAppend()
{
MessageHeaders hl = new MessageHeaders();
MessageHeaders hl2 = new MessageHeaders();
hl.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
hl2.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
assertEquals(1, hl2.count());
hl = new MessageHeaders();
hl2.set(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
assertEquals("" + hl2, 1, hl2.count());
try {
hl.add(null);
fail("not valid");
} catch (IllegalArgumentException e) { }
}
public void testAdd()
{
MessageHeaders hl = new MessageHeaders();
hl.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
hl.add("trANSFER-enCODING", "boo");
assertEquals(2, hl.asList().size());
assertEquals(true, hl.remove("Transfer-Encoding"));
assertEquals(0, hl.asList().size());
assertEquals(false, hl.remove("Transfer-Encoding"));
}
public void testContains()
{
MessageHeaders hl = new MessageHeaders();
hl.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
hl.add(MessageHeader.FN_CONTENT_TYPE, "text/xml");
hl.set(MessageHeader.FN_CONTENT_TYPE, "text/xml2");
boolean chunked = hl.contains(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
assertEquals("got chunked", true, chunked);
String val = hl.getFieldContent(MessageHeader.FN_CONTENT_TYPE);
assertEquals("got type", "text/xml2", val);
String val2 = hl.getFieldContent(MessageHeader.FN_CONTENT_LENGTH);
assertEquals("not here", null, val2);
}
public void testMakeHostHeader()
throws Exception
{
MessageHeader mh;
mh = MessageHeader.makeHostHeader(new URL("http://example.com"));
assertEquals("example.com", mh.getFieldContent());
mh = MessageHeader.makeHostHeader(new URL("http://example.com:123"));
assertEquals("example.com:123", mh.getFieldContent());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/ChunkStreamTest.java 0000644 0001750 0001750 00000017764 10762067376 031101 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
/**
* This class is for unit testing ChunkedOutputStream and ChunkedInputStream.
*
* @author Elias Ross
* @version 1.0
*/
public class ChunkStreamTest
extends junit.framework.TestCase
{
public ChunkStreamTest(String name) {
super(name);
}
static final byte stuff[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
public void testWriteRead()
throws IOException
{
//System.out.println("testWriteRead");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ChunkedOutputStream cos = new ChunkedOutputStream(bos);
for (int i = 1; i < stuff.length; i++)
cos.write(stuff, 0, i);
cos.doneOutput();
cos.doneOutput(); // shouldn't matter
// read in
byte stuffin[] = bos.toByteArray();
InputStream is = new ByteArrayInputStream(stuffin);
ChunkedInputStream cis = new ChunkedInputStream(is);
for (int i = 1; i < stuff.length; i++) {
int len = cis.read(stuffin, 0, i);
assertEquals("len", i, len);
for (int j = 0; j < len; j++)
assertEquals("position", stuff[j], stuffin[j]);
}
// EOF
assertEquals(-1, cis.read());
}
public void testWriteRead2()
throws IOException
{
//System.out.println("testWriteRead2");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ChunkedOutputStream cos = new ChunkedOutputStream(bos);
for (int i = 0; i < stuff.length; i++)
cos.write(stuff[i]);
cos.close();
// read in
InputStream is = new ByteArrayInputStream(bos.toByteArray());
ChunkedInputStream cis = new ChunkedInputStream(is);
for (int i = 0; i < stuff.length; i++) {
int what = cis.read();
assertEquals("what " + i, (char)stuff[i], (char)what);
}
// EOF
assertEquals(-1, cis.read());
assertEquals(-1, cis.read(new byte[1], 0, 1));
}
public void testReadBi()
throws IOException
{
//System.out.println("testReadBi");
int ints[] = { 0x0Fe, 1, 45, 7, 55, 1, 0x1ceface1, 0x1234, 0x00001, 0xABCD, 0xEF, 0x12};
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ChunkedOutputStream cos = new ChunkedOutputStream(bos);
for (int i = 0; i < ints.length; i++)
cos.writeChunkLen(ints[i]);
byte buf[] = bos.toByteArray();
cos.close();
// read
InputStream is = new ByteArrayInputStream(buf);
ChunkedInputStream cis = new ChunkedInputStream(is);
for (int i = 0; i < ints.length; i++) {
int len = cis.readLengthFromStream();
assertEquals("Read Hex Len", ints[i], len);
}
// at eof
try {
cis.readLengthFromStream();
fail("bad length");
} catch (IOException e) {
}
}
public void testReadHex()
throws IOException
{
String hexs[] = { "00Fe", "1234", "000001", "ABCD", "EF" };
int ints[] = { 0x0Fe, 0x1234, 0x00001, 0xABCD, 0xEF };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos);
for (int i = 0; i < hexs.length; i++) {
osw.write(hexs[i]);
osw.write("\r\n");
}
osw.write("\r\n");
osw.write("GHJH\r\n");
osw.close();
byte buf[] = bos.toByteArray();
// read in chunks
InputStream is = new ByteArrayInputStream(buf);
ChunkedInputStream cis = new ChunkedInputStream(is);
for (int i = 0; i < hexs.length; i++) {
int len = cis.readLengthFromStream();
assertEquals("Read Hex Len", ints[i], len);
}
cis.readChunkEnd();
try {
//System.out.println("testReadHex readLengthFromStream");
cis.readLengthFromStream();
fail("bad length");
} catch (IOException e) {
}
cis.close();
}
public void testCoverage()
throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ChunkedOutputStream cos = new ChunkedOutputStream(bos);
cos.toString();
cos.write(new byte[] { 1, 2 } );
byte stuffin[] = bos.toByteArray();
InputStream is = new ByteArrayInputStream(stuffin);
ChunkedInputStream cis = new ChunkedInputStream(is);
cis.toString();
assertEquals(1, cis.read());
assertEquals(2, cis.read());
}
public void testChunkExtension()
throws IOException
{
String s =
"01;an extension\r\nx\r\n" +
"00\r\nheader: value\r\n\r\n";
InputStream is = new ByteArrayInputStream(s.getBytes());
ChunkedInputStream cis = new ChunkedInputStream(is);
assertEquals('x', cis.read());
assertEquals(null, cis.getEntityHeaders());
assertEquals(false, cis.isEndChunk());
assertEquals(-1, cis.read());
assertEquals(true, cis.isEndChunk());
assertEquals("value", cis.getEntityHeaders().getFieldContent("header"));
s = "00\r\nheader: val\r\n \r\n";
is = new ByteArrayInputStream(s.getBytes());
cis = new ChunkedInputStream(is);
try {
cis.read();
fail("no CRLF");
} catch (IOException e) {}
s =
"01\r\nx\r\n" +
"00\r\nan entity-header\r \n\r\n";
is = new ByteArrayInputStream(s.getBytes());
cis = new ChunkedInputStream(is);
cis.read();
try {
cis.read();
fail("no CRLF");
} catch (IOException e) {}
}
public void testBadEnd()
throws IOException
{
InputStream is = new ByteArrayInputStream(new byte[] { '1', '\n', '\n'} );
ChunkedInputStream cis = new ChunkedInputStream(is);
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream(new byte[] { 'F', '\r', '\n' } );
cis = new ChunkedInputStream(is);
assertEquals(-1, cis.read(new byte[100], 0, 100));
is = new ByteArrayInputStream(new byte[] { 'G', '\r', '\n'} );
cis = new ChunkedInputStream(is);
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream(new byte[] { 'g', '\r', '\n'} );
cis = new ChunkedInputStream(is);
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream("a\r\n01234567890\n\r".getBytes());
cis = new ChunkedInputStream(is);
assertEquals('0', cis.read());
is = new ByteArrayInputStream(new byte[] { '1', '\r', '\r'} );
cis = new ChunkedInputStream(is);
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream("01\r\nA\n\r".getBytes());
cis = new ChunkedInputStream(is);
cis.read();
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream(new byte[] { '1', '\r', '\n', 'a', '\r', '?' } );
cis = new ChunkedInputStream(is);
cis.read();
try {
cis.read();
fail("bad seq");
} catch (IOException e) { }
is = new ByteArrayInputStream(new byte[] { '1', ' ', '\r', '\n', 'a'} );
cis = new ChunkedInputStream(is);
assertEquals("Space in length, not in spec, but apache 1.3.29 does it", 'a', cis.read());
}
public void testParam()
throws IOException
{
try {
new ChunkedInputStream(null);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
new ChunkedOutputStream(null);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
ChunkedOutputStream os = new ChunkedOutputStream(new ByteArrayOutputStream());
os.doneOutput();
os.write('a');
fail("already wrote last chunk");
} catch (IllegalStateException e) {
}
try {
ChunkedOutputStream os = new ChunkedOutputStream(new ByteArrayOutputStream());
os.doneOutput();
os.write(stuff, 0, stuff.length);
fail("already wrote last chunk");
} catch (IllegalStateException e) {
}
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/ 0000755 0001750 0001750 00000000000 11111351351 026571 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011567 L ustar root root libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpServletRequestImplTest.java libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpServletRequestImpl0000644 0001750 0001750 00000007354 10770533053 033217 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.Locale;
import javax.servlet.http.HttpSession;
import junit.framework.TestCase;
import net.noderunner.http.ContentType;
import net.noderunner.http.ServerRequest;
public class HttpServletRequestImplTest extends TestCase {
HttpServletRequestImpl req;
String euro = "\u20AC";
Socket socket;
String uri = "/?a=b&c=d";
public void setUp() throws Exception {
String s=
"GET " + uri + " HTTP/1.1" + "\r\n" +
"Content-Length: 3" + "\r\n" +
"Content-Type: text/xml; encoding=UTF-8" + "\r\n" +
"x-Date: " + new HttpDateFormat().format(new Date()) + "\r\n" +
"\r\n" +
euro + "\r\n";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes("UTF-8"));
ServerRequest sreq = new ServerRequest(is);
req = new HttpServletRequestImpl(sreq);
ServerSocket ss = new ServerSocket(0);
req.serverSocket(ss);
socket = new Socket("localhost", ss.getLocalPort());
req.remoteAddress((InetSocketAddress)socket.getLocalSocketAddress());
ss.close();
}
public void tearDown() throws Exception {
socket.close();
}
public void testSimple2() throws Exception {
assertEquals(null, req.getAuthType());
assertEquals(uri, req.getRequestURI());
assertEquals(uri, req.getRequestURL().toString());
assertEquals(0, req.getCookies().length);
assertEquals(3, req.getContentLength());
assertEquals("UTF-8", req.getCharacterEncoding());
assertEquals(euro, req.getReader().readLine());
assertEquals("text", ContentType.parse(req.getContentType()).getType());
req.getLocalAddr();
req.getLocalName();
assertEquals(2, req.getParameterMap().size());
assertEquals("b", req.getParameter("a"));
assertEquals(null, req.getParameter("notHere"));
req.getParameterNames();
assertEquals("b", req.getParameterValues("a")[0]);
req.setAttribute("key", "val");
assertEquals("val", req.getAttribute("key"));
assertEquals(true, req.getAttributeNames().hasMoreElements());
req.removeAttribute("key");
assertEquals(null, req.getAttribute("key"));
req.setCharacterEncoding("ASCII");
assertEquals(socket.getPort(), req.getServerPort());
assertEquals(Locale.getDefault(), req.getLocale());
assertEquals(Locale.getDefault(), req.getLocales().nextElement());
assertEquals(false, req.isSecure());
assertTrue(req.getDateHeader("x-Date") <= System.currentTimeMillis());
assertEquals("3", req.getHeader("Content-length"));
assertEquals(3, req.getIntHeader("Content-length"));
assertEquals(true, req.getHeaderNames().hasMoreElements());
assertEquals(false, req.isUserInRole("user"));
assertEquals(null, req.getUserPrincipal());
assertEquals(null, req.getSession(false));
HttpSession session = req.getSession();
assertSame(session, req.getSession(false));
assertSame(session, req.getSession(true));
assertEquals(-1, req.getInputStream().read());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HelloWorldServer.java 0000644 0001750 0001750 00000002500 10762067376 032721 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.net.ServerSocket;
import net.noderunner.http.servlet.ServletServer;
/**
* Example server.
*
* @author Elias Ross
*/
public class HelloWorldServer {
public HelloWorldServer(int port) throws Exception {
ServerSocket sock = new ServerSocket(port);
ServletServer ss = new ServletServer(new HelloServlet(), sock);
ss.start();
synchronized (this) {
this.wait();
}
ss.close();
}
public static void main(String s[]) throws Exception {
new HelloWorldServer(9090);
}
}
././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/BasicHttpSessionTest.java libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/BasicHttpSessionTest.j0000644 0001750 0001750 00000003334 10762067376 033062 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import junit.framework.TestCase;
/**
* @author Elias Ross
*/
public class BasicHttpSessionTest extends TestCase {
BasicHttpSession s = new BasicHttpSession();
/**
* Test this class.
*/
public void testThis() {
assertEquals(null, s.getAttribute("foo"));
assertEquals(false, s.getAttributeNames().hasMoreElements());
assertEquals(true, s.getCreationTime() != 0);
assertNotNull(s.getId());
assertEquals(null, s.getServletContext());
assertEquals(null, s.getSessionContext());
assertEquals(null, s.getValue("foo"));
assertEquals(0, s.getValueNames().length);
s.invalidate();
assertEquals(true, s.isNew());
s.putValue("foo", "bar");
s.removeAttribute("foo");
assertEquals("bar", s.getValue("foo"));
assertEquals("foo", s.getValueNames()[0]);
s.removeValue("foo");
s.setAttribute("foo", "bar");
assertEquals("bar", s.getAttribute("foo"));
s.setMaxInactiveInterval(1000);
assertEquals(1000, s.getMaxInactiveInterval());
}
}
././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpServletResponseImplTest.java libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpServletResponseImp0000644 0001750 0001750 00000005253 10762067376 033220 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Locale;
import net.noderunner.http.ServerResponse;
import junit.framework.TestCase;
public class HttpServletResponseImplTest extends TestCase {
HttpServletResponseImpl res = new HttpServletResponseImpl();
public void testSimple() throws Exception {
ServerResponse response = res.createServerResponse();
assertEquals("HTTP/1.1 200 OK", response.getStatusLine().toString());
}
public void testSimple2() throws Exception {
assertSame(res.getOutputStream(), res.getOutputStream());
assertSame(res.getWriter(), res.getWriter());
res.getOutputStream().write((byte)'!');
res.getWriter().write("Hi");
ServerResponse response = res.createServerResponse();
assertEquals("HTTP/1.1 200 OK", response.getStatusLine().toString());
ByteArrayOutputStream os = new ByteArrayOutputStream();
response.getDataPoster().sendData(os);
assertEquals("!Hi", os.toString());
}
public void testEnc() throws IOException {
res.setContentType("text/xml; encoding=UTF-8");
res.getWriter().append('\u2668');
assertEquals("UTF-8", res.getCharacterEncoding());
}
public void testCoverage() throws IOException {
res.setLocale(Locale.CANADA);
assertEquals(Locale.CANADA, res.getLocale());
assertEquals("ISO-8859-1", res.getCharacterEncoding());
res.setCharacterEncoding("UTF-8");
assertEquals("UTF-8", res.getCharacterEncoding());
res.setBufferSize(100);
res.getOutputStream().write(5);
res.resetBuffer();
res.getOutputStream().write(5);
res.reset();
res.addDateHeader("foo", new Date().getTime());
res.setDateHeader("foo", new Date().getTime());
res.addIntHeader("bar", 5);
res.setIntHeader("bar", 5);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ServerResponse response = res.createServerResponse();
response.getDataPoster().sendData(os);
assertEquals("", os.toString());
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpDateFormatTest.java libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HttpDateFormatTest.jav0000644 0001750 0001750 00000002713 10762067376 033052 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.text.ParseException;
import java.util.Date;
import junit.framework.TestCase;
public class HttpDateFormatTest extends TestCase {
HttpDateFormat hdf = new HttpDateFormat();
public void testBasic() throws ParseException {
Date parse = hdf.parse("Sun, 06 Nov 1994 08:49:37 GMT");
Date parse2 = hdf.parse("Sunday, 06-Nov-94 08:49:37 GMT");
Date parse3 = hdf.parse("Sun Nov 6 08:49:37 1994");
Date parse4 = hdf.parse("Sun Nov 16 08:49:37 1994");
long at = 784111777000L;
assertEquals(at, parse.getTime());
assertEquals(at, parse2.getTime());
assertEquals(at, parse3.getTime());
long day = 1000 * 60 * 60 * 24;
assertEquals(at + day * 10, parse4.getTime());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/HelloServlet.java 0000644 0001750 0001750 00000003572 10762067376 032101 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial") class HelloServlet extends HttpServlet {
boolean fail;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Get! " + req);
resp.setContentType("text/plain");
PrintWriter writer = resp.getWriter();
if (writer != resp.getWriter())
throw new IllegalStateException("not same");
writer.println("Hello, World!");
// not required
// writer.flush();
if (fail)
throw new ServletException("expected");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("Post! " + req);
resp.setContentType("text/plain");
PrintWriter writer = resp.getWriter();
writer.println("Hello, " + req.getParameter("name") + "!");
writer.flush();
}
} ././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/ServletServerTest.java libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/servlet/ServletServerTest.java0000644 0001750 0001750 00000004517 10762067376 033144 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.io.BufferedReader;
import java.net.ServerSocket;
import java.net.URL;
import junit.framework.TestCase;
import net.noderunner.http.EasyHttpClient;
import net.noderunner.http.HttpException;
import net.noderunner.http.HttpUtil;
import net.noderunner.http.MessageHeader;
import net.noderunner.http.MessageHeaders;
public class ServletServerTest extends TestCase {
HelloServlet servlet = new HelloServlet();
public void testSimple() throws Exception {
ServletServer ss = new ServletServer(servlet);
ss.start();
URL url = new URL("http://localhost:" + ss.getPort());
EasyHttpClient ehc = new EasyHttpClient(url);
BufferedReader reader = ehc.doGet();
MessageHeaders headers = ehc.getLastResponse().getHeaders();
String string = HttpUtil.read(reader);
assertEquals("Hello, World!", string.trim());
String content = headers.getFieldContent(MessageHeader.FN_SERVER);
assertTrue(content, content.startsWith("ServletServer"));
byte[] bs = HttpUtil.urlEncode(new String[] { "name", "Bob" });
reader = ehc.doPostUrlEncoded(bs);
string = HttpUtil.read(reader);
assertEquals("Hello, Bob!", string.trim());
servlet.fail = true;
try {
reader = ehc.doGet();
fail("expect fail");
} catch (HttpException e) {}
ehc.close();
ss.close();
}
public void testSocketConstructor() throws Exception {
ServletServer ss = new ServletServer(servlet, new ServerSocket(0));
ss.start();
ss.close();
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/ByteArrayDataPosterTest.java 0000644 0001750 0001750 00000004023 10762067376 032526 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.ByteArrayOutputStream;
/**
* This class is for unit testing {@link DataPoster} classes.
*
* @author Elias Ross
* @version 1.0
*/
public class ByteArrayDataPosterTest
extends junit.framework.TestCase
{
public ByteArrayDataPosterTest(String name) {
super(name);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(ByteArrayDataPosterTest.class);
}
public void testSend()
throws Exception
{
DataPoster poster = new ByteArrayDataPoster(new byte[] { 1, 2, 3});
ByteArrayOutputStream baos = new ByteArrayOutputStream();
poster.sendData(baos);
assertEquals(3, baos.size());
assertEquals(1, baos.toByteArray()[0]);
}
public void testSend2()
throws Exception
{
DataPoster poster = new ByteArrayDataPoster(new byte[] { 1, 2, 3, 4}, 1, 2);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
poster.sendData(baos);
assertEquals(2, baos.size());
assertEquals(2, baos.toByteArray()[0]);
}
public void testExceptions()
throws Exception
{
try {
new ByteArrayDataPoster(null);
fail("null array");
} catch (IllegalArgumentException e) { }
DataPoster poster = new ByteArrayDataPoster(new byte[0]);
try {
poster.sendData(null);
fail("null os");
} catch (IllegalArgumentException e) { }
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/ClientServerTest.java 0000644 0001750 0001750 00000051005 10762067376 031244 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
/**
* This class is for unit testing HttpClient and HttpServer.
*
* @author Elias Ross
* @version 1.0
*/
public class ClientServerTest
extends junit.framework.TestCase
{
MessageHeaders mh = new MessageHeaders();
public ClientServerTest(String name) {
super(name);
}
/*
public static junit.framework.TestSuite suite() {
return new org.hansel.CoverageDecorator(ClientServerTest.class,
new Class[] { RetryHttpClient.class });
}
public static junit.framework.TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ClientServerTest("testRedirectBadUrl"));
return suite;
}
*/
private static final byte stuff[] = { 1, 2, 3, 4 };
private static final RequestLine requestLine =
new RequestLine(Method.GET, "/", HttpVersion.HTTP11);
private static final RequestLine requestPost =
new RequestLine(Method.POST, "/", HttpVersion.HTTP11);
private static final MessageHeaders messageHeaders = new MessageHeaders();
static {
messageHeaders.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
}
private static final InputStream junkInput = new ByteArrayInputStream(stuff);
private static final OutputStream junkOutput = new ByteArrayOutputStream();
private static URL exampleURL = null;
static {
try {
exampleURL = new URL("http://example.com");
} catch (IOException e) {
}
}
public void testServerParam()
throws IOException
{
try {
new BasicHttpServer(null, null);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
new BasicHttpServer(new ByteArrayOutputStream(), null);
fail("null input");
} catch (IllegalArgumentException e) {
}
ByteArrayInputStream bais = new ByteArrayInputStream("GET /\r\n\r\n".getBytes());
HttpServer s = new BasicHttpServer(new ByteArrayOutputStream(), bais);
s.toString();
s.readRequest();
try {
s.writeResponse(null);
fail("null ServerResponse");
} catch (IllegalArgumentException e) {
}
ServerResponse sr = new ServerResponse(
StatusLine.HTTP11_200_OK,
new MessageHeaders(),
new ByteArrayDataPoster("ahou!".getBytes()));
s.writeResponse(sr);
}
public void testServerClose()
throws IOException
{
ByteArrayInputStream bais = new ByteArrayInputStream("1".getBytes());
HttpServer s = new BasicHttpServer(new ByteArrayOutputStream(), bais);
s.close();
// to get more code coverage
s.close();
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
Socket sock = new Socket("127.0.0.1", server.getPort());
s = new BasicHttpServer(sock);
s.close();
// Java 1.4-ism
// assertTrue("closed", sock.isClosed());
server.close();
}
public void testClientParam()
throws IOException
{
try {
new RetryHttpClient(null, 1);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
new RetryHttpClient(exampleURL, -1);
fail("bad tries");
} catch (IllegalArgumentException e) {
}
try {
new BasicHttpClient(null, junkInput);
fail("null output");
} catch (IllegalArgumentException e) {
}
try {
new BasicHttpClient(junkOutput, null);
fail("null input");
} catch (IllegalArgumentException e) {
}
HttpClient c = new BasicHttpClient(junkOutput, junkInput);
c.toString();
try {
c.writeRequest(null);
fail("null input");
} catch (IllegalArgumentException e) {
}
}
public void testServerState()
throws IOException
{
StatusLine statusLine = StatusLine.HTTP11_200_OK;
String head = "GET / HTTP/1.1\r\n\r\n";
InputStream junkInput = new ByteArrayInputStream((head + head + head + head + head + head).getBytes());
try {
HttpServer s = new BasicHttpServer(junkOutput, junkInput);
s.readRequest();
s.readRequest();
fail("cannot read twice");
} catch (IllegalStateException e) {
}
try {
HttpServer s = new BasicHttpServer(junkOutput, junkInput);
s.getOutputStream();
fail("cannot getOutputStream now");
} catch (IllegalStateException e) {
}
try {
HttpServer s = new BasicHttpServer(junkOutput, junkInput);
s.readRequest();
s.writeResponse(new ServerResponse(statusLine, messageHeaders));
s.getOutputStream();
s.getOutputStream();
fail("cannot getOutputStream twice");
} catch (IllegalStateException e) {
}
try {
HttpServer s = new BasicHttpServer(junkOutput, junkInput);
s.readRequest();
s.writeResponse(new ServerResponse(statusLine, messageHeaders));
s.writeResponse(new ServerResponse(statusLine, messageHeaders));
fail("cannot writeResponse twice");
} catch (IllegalStateException e) {
}
{
HttpServer s = new BasicHttpServer(junkOutput, junkInput);
s.readRequest();
s.writeResponse(new ServerResponse(statusLine, messageHeaders));
s.readRequest();
s.writeResponse(new ServerResponse(statusLine, messageHeaders));
// shouldn't fail
}
}
public void testClientState()
throws IOException
{
try {
HttpClient c = new BasicHttpClient(junkOutput, junkInput);
c.writeRequest(new ClientRequest(requestLine, messageHeaders));
c.writeRequest(new ClientRequest(requestLine, messageHeaders));
fail("cannot write twice");
} catch (IllegalStateException e) {
}
try {
HttpClient c = new BasicHttpClient(junkOutput, junkInput);
c.getOutputStream();
fail("cannot getOutputStream now");
} catch (IllegalStateException e) {
}
try {
HttpClient c = new BasicHttpClient(junkOutput, junkInput);
c.writeRequest(new ClientRequest(requestLine, messageHeaders));
c.getOutputStream();
c.getOutputStream();
fail("cannot getOutputStream twice");
} catch (IllegalStateException e) {
}
try {
HttpClient c = new BasicHttpClient(junkOutput, junkInput);
c.readResponse();
fail("cannot readResponse now");
} catch (IllegalStateException e) {
}
}
public void testClientIn()
throws IOException
{
ByteArrayOutputStream testout = new ByteArrayOutputStream();
String resp =
"HTTP/1.1 200 OK" + HttpUtil.CRLF +
"Content-Length: 0" + HttpUtil.CRLF +
HttpUtil.CRLF;
ByteArrayInputStream testin = new ByteArrayInputStream(resp.getBytes());
HttpClient c = new BasicHttpClient(testout, testin);
c.writeRequest(new ClientRequest(requestLine, messageHeaders));
ClientResponse r = c.readResponse();
assertEquals("HTTP/1.1", HttpVersion.HTTP11, r.getStatusLine().getHttpVersion());
assertEquals("200", 200, r.getStatusLine().getStatusCode());
assertEquals("OK", "OK", r.getStatusLine().getReasonPhrase());
MessageHeaders headers = r.getHeaders();
assertEquals("One header", 1, headers.count());
assertEquals("0 length", "0", headers.asList().get(0).getFieldContent());
assertEquals("0 remain", 0, testin.available());
InputStream in = r.getInputStream();
assertEquals("empty ", -1, in.read());
String s = new String(testout.toByteArray());
assertTrue("Starts with", s.startsWith("GET / HTTP/1.1"));
}
private static class MyHttpServer extends ThreadedHttpServer {
boolean doRead = true;
boolean failException = false;
ServerRequest r;
public MyHttpServer() throws IOException {
super();
}
@Override
protected void exception(Exception e) {
e.printStackTrace();
}
/**
* Reads one line and then says "got [line]"
*/
@Override
public void handleRequest(Request request)
throws IOException
{
if (failException)
throw new RuntimeException("fail");
HttpServer server = request.getServer();
r = server.readRequest();
String result = "got ";
InputStream is = r.getInputStream();
is = HttpUtil.wrapInputStream(is, r.getHeaders());
if (doRead) {
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line = in.readLine();
result += line;
}
MessageHeader mh;
mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "" + result.length());
server.writeResponse(new ServerResponse(StatusLine.HTTP11_200_OK,
new MessageHeaders(new MessageHeader[]{ mh })));
PrintWriter out = new PrintWriter(new OutputStreamWriter(server.getOutputStream()));
out.println(result);
out.flush();
}
}
public void testEasyGet()
throws Exception
{
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClient ec = new EasyHttpClient(url);
BufferedReader br = ec.doGet();
String got = HttpUtil.read(br).trim();
assertEquals("got", got);
server.close();
}
private class EasyHttpClientFactory2 {
EasyHttpClientFactory2()
throws IOException
{
}
public EasyHttpClient makePostClient(URL url) {
return new EasyHttpClient(url, Method.POST);
}
}
public void testEasyPost()
throws Exception
{
ThreadedHttpServer server = new MyHttpServer();
server.start();
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2();
EasyHttpClient ec = factory.makePostClient(url);
Map map = new HashMap();
map.put("a", "b");
byte[] body = HttpUtil.urlEncode(map);
BufferedReader br = ec.doPostUrlEncoded(body);
String got = HttpUtil.read(br).trim();
assertEquals("got " + new String(body), got);
ec.close();
server.close();
}
public void testClientClose()
throws IOException
{
ThreadedHttpServer server = new MyHttpServer();
Socket s = new Socket("127.0.0.1", server.getPort());
BasicHttpClient client = new BasicHttpClient(s.getOutputStream(), s.getInputStream());
client.close();
try {
client.writeRequest(new ClientRequest(requestLine, messageHeaders));
fail("should be closed");
} catch (IllegalStateException e) { }
}
public void testClientServer()
throws IOException
{
ThreadedHttpServer server = new MyHttpServer();
server.start();
Socket s = new Socket("127.0.0.1", server.getPort());
BasicHttpClient client = new BasicHttpClient(s.getOutputStream(), s.getInputStream());
client.writeRequest(new ClientRequest(requestLine, messageHeaders));
PrintWriter out = new PrintWriter(new OutputStreamWriter(new ChunkedOutputStream(s.getOutputStream())));
String orig = "hello HttpServer";
out.println(orig);
out.flush();
ClientResponse r = client.readResponse();
BufferedReader in = new BufferedReader(new InputStreamReader(r.getInputStream()));
String line = in.readLine();
assertEquals("we got something", "got " + orig, line);
server.close();
}
private static class ContinueHttpServer extends ThreadedHttpServer {
public ContinueHttpServer() throws IOException {
super();
}
@Override
public void handleRequest(Request request)
throws IOException
{
HttpServer server = request.getServer();
server.readRequest();
MessageHeader mh = new MessageHeader("whatever", "something");
MessageHeaders mhs = new MessageHeaders();
mhs.add(mh);
server.writeResponse(new ServerResponse(StatusLine.HTTP11_100, mhs));
StatusLine st = new StatusLine(199);
server.writeResponse(new ServerResponse(st, mhs));
server.writeResponse(new ServerResponse(StatusLine.HTTP11_200_OK, mhs));
}
}
private static class RedirHttpServer extends ThreadedHttpServer {
String url;
ServerRequest r;
boolean sendLocation = true;
public RedirHttpServer(String url) throws IOException {
this.url = url;
}
public RedirHttpServer(URL url) throws IOException {
super();
this.url = url.toString();
}
/**
* Reads one line and then redirects to a different location.
*/
public void handleRequest(Request request)
throws IOException
{
HttpServer server = request.getServer();
// System.out.println("ClientServerTest Reading request " + this);
r = server.readRequest();
// System.out.println("ClientServerTest Read request " + r);
MessageHeader mh;
MessageHeader mh2;
r.getInputStream();
String uri = r.getRequestLine().getRequestURI();
if (uri.equals("/")) {
mh = new MessageHeader(MessageHeader.FN_LOCATION, url);
mh2 = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "0");
if (!sendLocation)
mh = mh2;
server.writeResponse(new ServerResponse(StatusLine.HTTP11_301, new MessageHeader[] { mh, mh2 }));
} else {
mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "0");
server.writeResponse(new ServerResponse(StatusLine.HTTP11_200_OK, new MessageHeader[] { mh }));
}
// System.out.println("ClientServerTest Wrote response " + StatusLine.HTTP11_301);
}
}
private class MyRetryHttpClient extends RetryHttpClient
{
HttpClient c;
URL url;
MyRetryHttpClient(HttpClient c)
throws MalformedURLException
{
super(new URL("http://localhost"));
this.c = c;
}
protected HttpClient makeHttpClient(URL url) {
this.url = url;
return c;
}
}
public void testRedirect()
throws Exception
{
URL url = new URL("http://localhost/someplace");
RedirHttpServer server = new RedirHttpServer(url);
server.start();
Socket s = new Socket("localhost", server.getPort());
BasicHttpClient bclient = new BasicHttpClient(s);
MyRetryHttpClient client = new MyRetryHttpClient(bclient);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
client.readResponse();
String URI = server.r.getRequestLine().getRequestURI();
assertEquals("redir'ed did not change initial url", "http://localhost", client.url.toString());
assertEquals("redir'ed url", "/someplace", URI);
}
public void testRedirect2()
throws Exception
{
URL url = new URL("http://otherhost/someplace");
RedirHttpServer server = new RedirHttpServer(url);
server.start();
MyHttpServer server2 = new MyHttpServer();
server2.start();
Socket s = new Socket("localhost", server.getPort());
BasicHttpClient bclient = new BasicHttpClient(s.getOutputStream(), s.getInputStream());
Socket s2 = new Socket("localhost", server2.getPort());
server2.doRead = false;
BasicHttpClient bclient2 = new BasicHttpClient(s2);
MyRetryHttpClient client = new MyRetryHttpClient(bclient);
client.writeRequest(new ClientRequest(requestLine, messageHeaders));
client.c = bclient2;
client.readResponse();
assertTrue("make a request", server.r != null);
String URI = server2.r.getRequestLine().getRequestURI();
assertEquals("redir'ed url", "/someplace", URI);
server.close();
server2.close();
}
public void testRedirectLoop()
throws Exception
{
System.out.println("testRedirectLoop");
URL url = new URL("http://localhost/");
RedirHttpServer server = new RedirHttpServer(url);
server.start();
Socket s = new Socket("localhost", server.getPort());
BasicHttpClient bclient = new BasicHttpClient(s);
MyRetryHttpClient client = new MyRetryHttpClient(bclient);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
try {
client.readResponse();
fail("redirect loop");
} catch (HttpException e) {
// e.printStackTrace();
}
server.close();
}
public void testRedirectNoThanks()
throws Exception
{
System.out.println("testRedirectNoThanks");
URL url = new URL("http://localhost/");
RedirHttpServer server = new RedirHttpServer(url);
server.start();
URL url2 = new URL("http://localhost:" + server.getPort());
RetryHttpClient client = new RetryHttpClient(url2);
client.setFollowRedirects(false);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
Response r = client.readResponse();
assertEquals(301, r.getStatusLine().getStatusCode());
server.close();
}
public void testRedirectNoLocation()
throws Exception
{
System.out.println("testRedirectNoThanks");
URL url = new URL("http://localhost/");
RedirHttpServer server = new RedirHttpServer(url);
server.start();
server.sendLocation = false;
URL url2 = new URL("http://localhost:" + server.getPort());
RetryHttpClient client = new RetryHttpClient(url2);
client.setFollowRedirects(false);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
Response r = client.readResponse();
assertEquals(301, r.getStatusLine().getStatusCode());
server.close();
}
public void testRedirectBadUrl()
throws Exception
{
System.out.println("testRedirectBadUrl");
RedirHttpServer server = new RedirHttpServer("bad://URL_here");
server.start();
URL url = new URL("http://localhost:" + server.getPort());
RetryHttpClient client = new RetryHttpClient(url);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
try {
client.readResponse();
fail("redirect bad URL");
} catch (HttpException e) {
System.out.println("HTTP " + e + " " + client);
} catch (RuntimeException e) {
throw e;
}
System.out.println(" ETC " + client);
client.writeRequest(new ClientRequest(requestLine, new MessageHeaders()));
try {
client.readResponse();
fail("redirect loop");
} catch (HttpException e) {
}
}
public void testContinue()
throws Exception
{
ContinueHttpServer server = new ContinueHttpServer();
server.start();
Socket s = new Socket("localhost", server.getPort());
BasicHttpClient bclient = new BasicHttpClient(s);
MyRetryHttpClient client = new MyRetryHttpClient(bclient);
Response r;
client.writeRequest(new ClientRequest(requestLine, mh));
r = client.readResponse();
assertEquals(200, r.getStatusLine().getStatusCode());
client.writeRequest(new ClientRequest(requestPost, mh));
r = client.readResponse();
assertEquals(200, r.getStatusLine().getStatusCode());
client.setSkipContinues(false);
client.writeRequest(new ClientRequest(requestLine, mh));
r = client.readResponse();
assertEquals(100, r.getStatusLine().getStatusCode());
}
public void testClose()
throws Exception
{
MyHttpServer server = new MyHttpServer();
server.start();
server.doRead = false;
Socket s;
s = new Socket("localhost", server.getPort());
BasicHttpClient bclient;
bclient = new BasicHttpClient(s);
bclient.writeRequest(new ClientRequest(requestLine, mh));
bclient.readResponse();
try {
bclient.readResponse();
fail("closed, cannot write");
} catch (IllegalStateException e) { }
bclient.close();
s = new Socket("localhost", server.getPort());
bclient = new BasicHttpClient(s);
MyRetryHttpClient rclient = new MyRetryHttpClient(bclient);
rclient.writeRequest(new ClientRequest(requestLine, mh));
rclient.close();
try {
rclient.readResponse();
fail("closed, cannot read2");
} catch (IllegalStateException e) { }
rclient.close();
URL url = new URL("http://localhost:" + server.getPort());
EasyHttpClientFactory2 factory = new EasyHttpClientFactory2();
EasyHttpClient ec = factory.makePostClient(url);
ec.close();
server.close();
}
public void testFailToConnect()
throws Exception
{
MyHttpServer server = new MyHttpServer();
URL http = new URL("http://localhost:" + (server.getPort() + 10));
RetryHttpClient rhc = new RetryHttpClient(http);
try {
rhc.writeRequest(new ClientRequest(requestLine, messageHeaders));
fail("protocol");
} catch (IOException e) {}
}
public void testVariousConstructor()
throws Exception
{
RetryHttpClient rhc;
URL ftp = new URL("file:yo");
rhc = new RetryHttpClient(ftp);
try {
rhc.writeRequest(new ClientRequest(requestLine, messageHeaders));
fail("protocol");
} catch (IOException e) {}
rhc.close();
URL https = new URL("https://sourceforge.net");
rhc = new RetryHttpClient(https);
rhc.writeRequest(new ClientRequest(requestLine, messageHeaders));
URL http = new URL("http://sourceforge.net");
rhc = new RetryHttpClient(http);
rhc.writeRequest(new ClientRequest(requestLine, messageHeaders));
rhc.close();
}
public static void main(String s[]) throws Exception {
new ClientServerTest("testRedirectBadUrl").testRedirectBadUrl();
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/HttpVersionTest.java 0000644 0001750 0001750 00000004433 10762067376 031127 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.IOException;
/**
* This class is for unit testing HttpVersionImpl.
*
* @author Elias Ross
* @version 1.0
*/
public class HttpVersionTest
extends junit.framework.TestCase
{
public HttpVersionTest(String name) {
super(name);
}
/*
public static junit.framework.TestSuite suite() {
return new org.hansel.CoverageDecorator(HttpVersionTest.class,
new Class[] { HttpVersionImpl.class });
}
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(HttpVersionTest.class);
}
public void testBad()
throws IOException
{
try {
new HttpVersion(null);
fail("null argument");
} catch (IllegalArgumentException e) {
}
try {
new HttpVersion("blah");
fail("invalid prefix");
} catch (HttpException e) {
}
try {
new HttpVersion("HTTP/1");
fail("invalid number");
} catch (HttpException e) {
}
try {
new HttpVersion("HTTP/A.B");
fail("invalid integer");
} catch (HttpException e) {
}
}
public void testVersion()
throws IOException
{
String h11 = "HTTP/1.1";
String h12 = "HTTP/1.2";
assertEquals(new HttpVersion(h11), HttpVersion.HTTP11);
assertEquals(h11, new HttpVersion(h11).toString());
assertEquals(h12, new HttpVersion(h12).toString());
assertEquals(new HttpVersion("HTTP/1.0"), HttpVersion.HTTP10);
assertEquals(new HttpVersion(h12), new HttpVersion(1, 2));
HttpVersion v = HttpVersion.HTTP11;
assertEquals(v.hashCode(), new HttpVersion(1,1).hashCode());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/MessageHeaderTest.java 0000644 0001750 0001750 00000007066 10762067376 031344 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* This class is for unit testing HttpClient and HttpServer.
*
* @author Elias Ross
* @version 1.0
*/
public class MessageHeaderTest
extends junit.framework.TestCase
{
public MessageHeaderTest(String name) {
super(name);
}
public void testParam()
throws IOException
{
try {
MessageHeader.parse(null);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
new MessageHeader(null, "bob");
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
new MessageHeader("bob", null);
fail("null input");
} catch (IllegalArgumentException e) {
}
try {
MessageHeader.parse("franky");
fail("no colon");
} catch (HttpException e) {
}
try {
MessageHeader.parse("???:!!!");
fail("bad token: field name");
} catch (HttpException e) {
}
}
public void testHeadersIn()
throws IOException
{
String resp =
"Content-Length:0" + HttpUtil.CRLF +
"Bob-Length: XYZ " + HttpUtil.CRLF +
HttpUtil.CRLF;
ByteArrayInputStream testin = new ByteArrayInputStream(resp.getBytes());
MessageHeaders headers = MessageHeaders.readHeaders(testin);
assertEquals("Two header", 2, headers.count());
assertEquals("0 in content-length", "0", headers.getFieldContent("content-length"));
assertEquals("XYZ in Bob", "XYZ", headers.getFieldContent("bob-length"));
MessageHeader bob = new MessageHeader("BoB-LENgth", "XYZ");
MessageHeader bob2 = (MessageHeader) headers.asList().get(1);
assertEquals("BOB mixed case", headers.asList().get(1), bob);
assertEquals("BOB hash", bob2.hashCode(), bob.hashCode());
assertEquals("BOB string", bob2.toString(), bob.toString());
assertEquals("BOB same", bob, bob);
assertTrue("BOB string", !bob.equals("XYZ"));
MessageHeader.parse("foo:");
}
public void testHeadersCont() throws IOException {
String resp =
"Foo:" + HttpUtil.CRLF +
"\tbar" + HttpUtil.CRLF +
" baz" + HttpUtil.CRLF +
HttpUtil.CRLF;
ByteArrayInputStream testin = new ByteArrayInputStream(resp.getBytes());
MessageHeaders headers = MessageHeaders.readHeaders(testin);
assertEquals(1, headers.count());
assertEquals("bar baz", headers.getFieldContent("foo"));
resp =
" bad header:" + HttpUtil.CRLF +
HttpUtil.CRLF;
try {
testin = new ByteArrayInputStream(resp.getBytes());
MessageHeaders.readHeaders(testin);
fail("bad header");
} catch (IOException e) {
}
resp =
"header:" + HttpUtil.CRLF +
"cont:a" + HttpUtil.CRLF +
" b" + HttpUtil.CRLF +
"cont2:z" + HttpUtil.CRLF +
HttpUtil.CRLF;
testin = new ByteArrayInputStream(resp.getBytes());
headers = MessageHeaders.readHeaders(testin);
assertEquals("a b", headers.getFieldContent("cont"));
assertEquals("z", headers.getFieldContent("cont2"));
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/LimitStreamTest.java 0000644 0001750 0001750 00000005424 10762067376 031075 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* This class is for unit testing LimitedOutputStream and LimitedInputStream.
*
* @author Elias Ross
* @version 1.0
*/
public class LimitStreamTest
extends junit.framework.TestCase
{
public LimitStreamTest(String name) {
super(name);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(LimitStreamTest.class);
}
static final byte stuff[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
static byte dummy[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' };
public void testLimitSmall()
throws IOException
{
InputStream is = new ByteArrayInputStream(new byte[0]);
LimitedInputStream lis = new LimitedInputStream(is, 5);
assertEquals(-1, lis.read());
}
public void testInLimit()
throws IOException
{
InputStream is = new ByteArrayInputStream(stuff);
LimitedInputStream lis = new LimitedInputStream(is, 5);
assertEquals(3, lis.read(dummy, 0, 3));
assertEquals('d', lis.read());
assertEquals(1, lis.read(dummy, 0, 2));
assertEquals(-1, lis.read());
assertEquals(-1, lis.read(dummy, 0, 3));
try {
new LimitedInputStream(null, 0);
fail("IllegalArgumentException");
} catch (IllegalArgumentException e) { }
assertEquals(true, lis.markSupported());
lis.mark(0);
lis.reset();
lis.toString();
lis.close();
}
public void testOutLimit()
throws IOException
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
LimitedOutputStream los = new LimitedOutputStream(os, 5);
los.write(stuff, 0, 2);
los.write('a');
los.write(stuff, 0, 3);
los.write('a');
los.write(stuff, 0, 2);
byte result[] = os.toByteArray();
assertEquals("Length ", 5, result.length);
assertEquals("Length ", 'a', result[2]);
assertEquals("Length ", 'b', result[4]);
try {
new LimitedOutputStream(null, 0);
fail("IllegalArgumentException");
} catch (IllegalArgumentException e) { }
los.flush();
los.close();
los.toString();
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/StatusLineTest.java 0000644 0001750 0001750 00000003041 10762067376 030727 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import junit.framework.TestCase;
public class StatusLineTest extends TestCase {
public void testVarious() throws HttpException {
try {
new StatusLine((String)null);
fail("NPE");
} catch (IllegalArgumentException e) {}
try {
StatusLine.parseStatusLine((String)null);
fail("NPE");
} catch (IllegalArgumentException e) {}
try {
new StatusLine("HTTP/1.1 1000");
fail("NPE");
} catch (HttpException e) {}
try {
new StatusLine("HTTP/1.1 -404");
fail("NPE");
} catch (HttpException e) {}
try {
new StatusLine("HTTP/1.1");
fail("NPE");
} catch (HttpException e) {}
StatusLine sl = new StatusLine("HTTP/1.2 400 Oh no");
assertEquals(400, sl.getStatusCode());
assertEquals("Oh no", sl.getReasonPhrase());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/ContentTypeTest.java 0000644 0001750 0001750 00000007242 10762067376 031117 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import junit.framework.TestCase;
public class ContentTypeTest extends TestCase {
public void testIt() {
ContentType ct = ContentType.parse("text/plain");
assertEquals("text", ct.getType());
assertEquals("plain", ct.getSubtype());
ct = ContentType.parse("TEXT/plain");
assertEquals("text", ct.getType());
ct = ContentType.parse("x-foo/plain");
assertEquals("x-foo", ct.getType());
assertEquals(null, ct.getParameter("x"));
assertEquals(null, ct.getParameterValue("x"));
ct = ContentType.parse("X-foo/plain");
assertEquals("x-foo", ct.getType());
}
public void testCheck() {
ContentType.checkToken("ok");
try {
ContentType.checkToken("\b");
fail("invalid");
} catch (IllegalArgumentException e) {}
}
public void testInvalid() {
try {
new ContentType(null, null);
fail("bad");
} catch (NullPointerException e) {}
try {
new ContentType("text", null);
fail("bad");
} catch (NullPointerException e) {}
try {
ContentType.parse("bad/plain");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("noslash");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("text/\b");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("text/\u2222");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("text/plain; foo");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("text/plain; \u2222=bar");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
ContentType.parse("x-\u2222/plain");
fail("bad");
} catch (IllegalArgumentException e) {}
try {
new ContentType.Parameter(null, null);
fail("bad");
} catch (NullPointerException e) {}
try {
new ContentType.Parameter("x", null);
fail("bad");
} catch (NullPointerException e) {}
}
public void testParams() {
ContentType ct;
ct = ContentType.parse("text/plain; foo=bar; baz=\"biz\"");
assertEquals("text/plain;foo=bar;baz=biz", ct.toString());
ct = ContentType.parse("text/plain; baz=\"b\\\"iz\"");
assertEquals("text/plain;baz=\"b\\\"iz\"", ct.toString());
ct = ContentType.parse("texT/plain; baz=\"sp \\ace\"");
assertEquals("sp ace", ct.getParameters().get(0).getValue());
ct = ContentType.parse("texT/plain; baz=\";\"; a=b");
assertEquals(";", ct.getParameters().get(0).getValue());
assertEquals("b", ct.getParameters().get(1).getValue());
assertEquals("b", ct.getParameterValue("a"));
assertEquals("a=b", ct.getParameter("a").toString());
ContentType.Parameter p = new ContentType.Parameter("x", "\r \t\"");
assertEquals("x=\"\r \t\\\"\"", p.toString());
p = new ContentType.Parameter("x", "\";\"");
assertEquals("x=\"\\\";\\\"\"", p.toString());
p = new ContentType.Parameter("x", "\\");
assertEquals("\"\\\"", p.getQuoteValue());
}
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/PerfTest.java 0000644 0001750 0001750 00000006250 10762067376 027535 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URLEncoder;
/**
* This class is for unit testing HttpClient and HttpServer.
*
* @author Elias Ross
* @version 1.0
*/
public class PerfTest
extends junit.framework.TestCase
{
public PerfTest(String name) {
super(name);
}
public static class MyHttpServer extends ThreadedHttpServer {
public MyHttpServer() throws IOException {
super();
}
/**
* Writes a couple of lines.
*/
public void handleRequest(Request req)
throws IOException
{
HttpServer s = req.getServer();
s.readRequest();
String result = "Have a happy day!\n\nTry try again!\n\n";
MessageHeader mh;
mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "" + result.length());
s.writeResponse(new ServerResponse(StatusLine.HTTP11_200_OK,
new MessageHeader[] { mh, mh, mh }));
Writer out = new OutputStreamWriter(s.getOutputStream());
out.write(result);
out.flush();
}
}
@SuppressWarnings("deprecation")
public void testUrlEncode()
throws Exception
{
String k = "key";
String v = "A note from me & \uabcd you.";
String nv[] = new String[] { k, v };
int times = 100;
long start, end;
for (int j = 0; j < 4; j++) {
start = System.currentTimeMillis();
for (int i = 0; i < times; i++) {
@SuppressWarnings("unused")
String str = URLEncoder.encode(k) + "." + URLEncoder.encode(v);
}
end = System.currentTimeMillis();
System.out.println("java.net.URLEncoder Took " + (end - start) + " MS");
start = System.currentTimeMillis();
for (int i = 0; i < times; i++) {
HttpUtil.urlEncode(nv);
// String str = new String(b);
}
end = System.currentTimeMillis();
System.out.println("HttpUtil Took " + (end - start) + " MS");
}
}
/*
public void testEasyGet()
throws Exception
{
MyHttpServer server = new MyHttpServer();
Socket s = new Socket("127.0.0.1", server.getPort());
URL url = new URL("http://localhost/");
EasyHttpClientFactory factory = new EasyHttpClientFactory2(s);
EasyHttpClient ec = factory.makeGetClient(url);
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
BufferedReader br = ec.doGet();
String str = HttpUtil.read(br);
assertTrue("length", str.length() > 0);
}
long end = System.currentTimeMillis();
System.out.println("Took " + (end - start) + " MS");
}
}
*/
}
libexml-java-0.0.20080703.orig/http/src/test/java/net/noderunner/http/HttpUtilTest.java 0000644 0001750 0001750 00000020360 10762067376 030414 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* This class is for unit testing TokenUtil and HttpUtil.
*
* @author Elias Ross
* @version 1.0
*/
public class HttpUtilTest
extends junit.framework.TestCase
{
public HttpUtilTest(String name) {
super(name);
}
public void testHttpUtil()
throws IOException
{
byte stuff[] = new byte[2048];
java.util.Arrays.fill(stuff, (byte)'a');
InputStream is;
is = new ByteArrayInputStream(stuff);
try {
HttpUtil.readHttpLine(is);
fail("Long line");
} catch (HttpException e) { }
is = new ByteArrayInputStream(new byte[] { });
try {
HttpUtil.readHttpLine(is);
fail("EOF line");
} catch (EOFException e) { }
is = new ByteArrayInputStream(new byte[] { 'a', 'b', '\r', '\n' });
String line = HttpUtil.readHttpLine(is);
assertEquals("AB", "ab", line);
is = new ByteArrayInputStream(new byte[] { 'a', 'b', '\r', 'a' });
try {
HttpUtil.readHttpLine(is);
fail("Expected LN");
} catch (HttpException e) { }
is = new ByteArrayInputStream(new byte[] { 'a', 'b', '\n', 'a' });
assertEquals("ab", HttpUtil.readHttpLine(is));
}
public void testReadFullyClose()
throws IOException
{
final MessageHeaders mh = new MessageHeaders();
mh.add(MessageHeader.MH_CONNECTION_CLOSE);
ClientResponse cr;
cr = new ClientResponse() {
public StatusLine getStatusLine() { return null; }
public MessageHeaders getHeaders() { return mh; }
public InputStream getInputStream() {
return new ByteArrayInputStream(new byte[1]);
}
};
assertEquals(0, cr.readFully());
mh.add(new MessageHeader( MessageHeader.FN_CONTENT_LENGTH, "1"));
// TODO fix this
// assertEquals(1, cr.readFully());
}
public void testReadFully()
throws IOException
{
InputStream s;
s = new ByteArrayInputStream(new byte[4]);
assertEquals(4, HttpUtil.readFully(s));
s = new ByteArrayInputStream(new byte[4000]);
assertEquals(4000, HttpUtil.readFully(s));
s = new LimitedInputStream(new ByteArrayInputStream(new byte[4000]), 2000);
assertEquals(2000, HttpUtil.readFully(s));
try {
HttpUtil.readFully((InputStream)null);
fail("cannot read");
} catch (IllegalArgumentException e) { }
}
public void testWrapInputStream()
throws IOException
{
MessageHeaders headers = new MessageHeaders();
headers.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
headers.add(new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "10"));
InputStream s = new ByteArrayInputStream(new byte[] { } );
assertTrue("chunked input", HttpUtil.wrapInputStream(s, headers) instanceof ChunkedInputStream);
headers = new MessageHeaders();
headers.add(new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "10"));
assertTrue("chunked input", HttpUtil.wrapInputStream(s, headers) instanceof LimitedInputStream);
headers = new MessageHeaders();
InputStream is = HttpUtil.wrapInputStream(s, headers);
assertEquals(s, is);
try {
headers = new MessageHeaders();
headers.add(new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, "abacaba"));
HttpUtil.wrapInputStream(s, headers);
fail("bad content-length");
} catch (HttpException e) { }
try {
HttpUtil.wrapInputStream(null, headers);
fail("null");
} catch (IllegalArgumentException e) { }
try {
HttpUtil.wrapInputStream(s, null);
fail("null");
} catch (IllegalArgumentException e) { }
}
public void testTokenUtil()
throws IOException
{
assertTrue("(", !TokenUtil.isTokenChar('('));
assertTrue("\t", !TokenUtil.isTokenChar('\t'));
assertTrue("a", TokenUtil.isTokenChar('a'));
assertTrue("bob", TokenUtil.isValidToken("bob"));
assertTrue("bob ", !TokenUtil.isValidToken("bob "));
assertTrue("bo:b", !TokenUtil.isValidToken("bo:b"));
}
public void testEncodeDecode()
throws IOException
{
Map m = new HashMap();
m.put("ab ", "cd");
m.put("ef$", "&&&");
m.put("xy&", "=zy");
byte[] urlEncodedData = HttpUtil.urlEncode(m);
Map m2 = HttpUtil.urlDecode(new String(urlEncodedData));
assertEquals("same map", m.keySet(), m2.keySet());
assertEquals("cd", m2.get("ab ")[0]);
assertEquals("&&&", m2.get("ef$")[0]);
}
public void testEncodeDecode2()
throws IOException
{
String s[] = new String[] { "$&", "cd", "k y", "*?" };
byte[] urlEncodedData = HttpUtil.urlEncode(s);
String s2[] = HttpUtil.urlDecodeToArray(new String(urlEncodedData));
assertEquals("same length", s.length, s2.length);
for (int i = 0; i < s.length; i++)
assertEquals("same entry", s[i], s2[i]);
}
public void testEncodeDecodeStringEncoding()
throws IOException
{
String s[] = new String[] { "foo", "bar" };
byte[] urlEncodedData;
try {
urlEncodedData = HttpUtil.urlEncode(s, "fuddy-duddy");
fail("fuddy-duddy not valid");
} catch (UnsupportedEncodingException e) {
}
urlEncodedData = HttpUtil.urlEncode(s, "UTF-8");
String s2[] = HttpUtil.urlDecodeToArray(new String(urlEncodedData));
for (int i = 0; i < s.length; i++)
assertEquals("same entry", s[i], s2[i]);
}
public void testDecode()
throws IOException
{
String urlEncodedData = "apple&banana=&cherry";
Map m = HttpUtil.urlDecode(urlEncodedData);
assertTrue(m.containsKey("apple"));
assertTrue(m.containsKey("banana"));
assertTrue(m.containsKey("cherry"));
String urlEncodedData2 = "apple=a&banana=b&cherry=c";
Map m2 = HttpUtil.urlDecode(urlEncodedData2);
assertEquals("a", m2.get("apple")[0]);
assertEquals("b", m2.get("banana")[0]);
assertEquals("c", m2.get("cherry")[0]);
}
@SuppressWarnings("deprecation")
public void testEncodeSpace()
throws IOException
{
String a = " apple ";
String s;
s = new String(HttpUtil.urlEncode(new String[]{a, a}));
assertEquals(URLEncoder.encode(a) + "=" + URLEncoder.encode(a), s);
String a2 = "?apple?";
s = new String(HttpUtil.urlEncode(new String[]{a2, a2}));
assertEquals(URLEncoder.encode(a2) + "=" + URLEncoder.encode(a2), s);
}
public void testDecode2()
throws IOException
{
String urlEncodedData = "+apple&ban+ana=+++&cherry";
String s[] = HttpUtil.urlDecodeToArray(urlEncodedData);
assertEquals(6, s.length);
assertEquals(" apple", s[0]);
assertEquals(null, s[1]);
assertEquals("ban ana", s[2]);
assertEquals(" ", s[3]);
assertEquals("cherry", s[4]);
assertEquals(null, s[5]);
}
public void testAdd() {
String s[] = new String[] { "ab", "cd" };
String[] strings = HttpUtil.add(s, "ef");
assertEquals("ab", strings[0]);
assertEquals("ef", strings[2]);
}
public void testDiscard()
throws IOException
{
HttpUtil.discard((BufferedReader)null);
}
public void testDecodeInputStream()
throws IOException
{
String s[] = new String[] { "ab", "cd", "ab", "de" };
byte[] urlEncodedData = HttpUtil.urlEncode(s);
Map m = HttpUtil.urlDecode(new ByteArrayInputStream(urlEncodedData));
String sa[] = m.get("ab");
assertEquals("MAP " + m, 2, sa.length);
assertEquals("cd", sa[0]);
assertEquals("de", sa[1]);
String[] s2 = HttpUtil.urlDecodeToArray(new ByteArrayInputStream(urlEncodedData));
assertTrue(Arrays.equals(s, s2));
try {
HttpUtil.urlDecodeToArray((String)null);
fail();
} catch (RuntimeException e) {}
try {
HttpUtil.urlDecodeToArray((InputStream)null);
fail();
} catch (RuntimeException e) {}
}
}
libexml-java-0.0.20080703.orig/http/src/main/ 0000755 0001750 0001750 00000000000 11111351351 020205 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/main/java/ 0000755 0001750 0001750 00000000000 11111351351 021126 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/main/java/net/ 0000755 0001750 0001750 00000000000 11111351351 021714 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/ 0000755 0001750 0001750 00000000000 11111351351 024073 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/ 0000755 0001750 0001750 00000000000 11111351352 025053 5 ustar twerner twerner libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/EasyHttpClient.java 0000644 0001750 0001750 00000035034 10762067376 030650 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
/**
* An easy-to-use HTTP client that can perform any standard HTTP operation.
* Opens a connection that can be used over and over again, unlike the
* Java HTTP client. Also allows for streamed data input and output,
* and allows for data operations to be performed without the use of
* call-backs.
*
*
* The underlying connection is kept active until {@link #close} is called.
* After every operation, the data sent by the HTTP server must be fully read,
* otherwise, any following operation on the same connection may not execute
* successfully. The character readers returned can be read or discarded
* easily with the {@link HttpUtil#read} and {@link HttpUtil#discard} methods.
* If the HTTP connection is to be used again, do not call
* close on any returned character readers.
*
*
*
* Example GET usage: (Retrieves the root document)
*
* Design notes: This class is designed as a wrapper,
* allowing the underlying {@link HttpClient} behavior to be delegated
* in another class. The goal is to provide a lot of functionality
* that users will not have to re-implement deal with many of the common
* HTTP use-cases. If something significant must be altered in what
* HTTP-level functionality is needed, it should be implementable
* by extending an existing {@link HttpClient}. The operations
* on any {@link HttpClient} can then be simply extended with this wrapper.
*
*
* @see EasyHttpClientFactory
* @see HttpClient
*/
public class EasyHttpClient
{
private HttpClient client;
private RequestLine requestLine;
private MessageHeaders headers;
private ClientResponse lastResponse;
private boolean checkStatus;
private GeneralDataPoster dataPoster; // Constructed if needed
/**
* Constructs a new HTTP client with a specific wrapped
* client, request line, and headers.
*/
public EasyHttpClient(HttpClient client, RequestLine requestLine, MessageHeaders headers) {
if (client == null)
throw new IllegalArgumentException("Null client");
if (requestLine == null)
throw new IllegalArgumentException("Null requestLine");
if (headers == null)
throw new IllegalArgumentException("Null headers");
this.client = client;
this.requestLine = requestLine;
this.headers = headers;
this.checkStatus = true;
this.lastResponse = null;
}
/**
* Constructs a new HTTP client.
*/
public EasyHttpClient(URL url, Method method) {
this(makeHttpClient(url), RequestLine.create(url, method), MessageHeaders.defaultHeaders(url));
}
/**
* Constructs a new HTTP client.
*/
public EasyHttpClient(HttpClient c, URL url, Method method) {
this(c, RequestLine.create(url, method), MessageHeaders.defaultHeaders(url));
}
/**
* Constructs a new HTTP client.
*/
public EasyHttpClient(URL url) {
this(url, Method.GET);
}
/**
* Creates and returns a new {@link HttpClient}.
* By default, returns a new instance of {@link RetryHttpClient}.
*/
private static HttpClient makeHttpClient(URL url) {
return new RetryHttpClient(url);
}
/**
* Allows a subsequent operation to be repeated with a different file on
* the same connection. Any previously set headers remain identical.
*/
public void setFile(String fileName)
{
requestLine = new RequestLine(requestLine, fileName);
}
/**
* Allows a subsequent operation to be repeated with a different method on
* the same connection. Any previously set headers remain identical.
*/
public void setMethod(Method method)
{
if (requestLine.getMethod().equals(method))
return;
requestLine = new RequestLine(method,
requestLine.getRequestURI(), requestLine.getHttpVersion());
}
/**
* Returns the message headers in use.
* These may be modified as required.
*/
public MessageHeaders getHeaders() {
return headers;
}
/**
* Reads the HTTP response, checks the status, and
* returns a wrapped input stream based on the headers given.
*/
private InputStream readResponse2()
throws IOException
{
lastResponse = client.readResponse();
if (checkStatus) {
int code = lastResponse.getStatusLine().getStatusCode();
if ((code / 100) != 2) {
// Throw away contents
lastResponse.readFully();
throw new HttpException("Bad HTTP Status, expected 200 level: " + lastResponse);
}
}
MessageHeaders hl = lastResponse.getHeaders();
return HttpUtil.wrapInputStream(lastResponse.getInputStream(), hl);
}
private BufferedReader readResponse()
throws IOException
{
InputStream s = readResponse2();
if (s == null)
return null;
// TODO determine content encoding, and properly wrap that
return new BufferedReader(new InputStreamReader(s));
}
/**
* Sets if the status will automatically be checked for a 200-level
* response or whether or not the status will be ignored. By default, status
* is checked.
*/
public void setCheckStatus(boolean checkStatus) {
this.checkStatus = checkStatus;
}
/**
* Returns the last HTTP response, including headers, resulting
* from the last doPost, doGet, or
* doOperation call.
* Returns null if no response information exists.
*/
public Response getLastResponse() {
return lastResponse;
}
/**
* Performs a GET operation,
* returning a BufferedReader, which can be used to read the
* response body.
*
* @throws HttpException if the input stream could
* not be created, or the status was not allowed
* @return null if no body was obtained
* @see #getLastResponse
* @see #setCheckStatus
* @see HttpUtil#read
* @see HttpUtil#discard
*/
public BufferedReader doGet()
throws IOException
{
setMethod(Method.GET);
client.writeRequest(new ClientRequest(requestLine, headers));
client.getOutputStream(); // does nothing for now
return readResponse();
}
private void setLenHeader(int len) {
String slen = String.valueOf(len);
MessageHeader mh = new MessageHeader(MessageHeader.FN_CONTENT_LENGTH, slen);
headers.add(mh);
}
private void setContentType(String contentType) {
if (contentType != null) {
MessageHeader mh = new MessageHeader(MessageHeader.FN_CONTENT_TYPE, contentType);
headers.add(mh);
}
}
private void setChunkedHeader() {
headers.add(MessageHeader.MH_TRANSFER_ENCODING_CHUNKED);
}
/**
* Performs a POST operation, returning a
* BufferedReader for reading the response body. The data
* type to be transferred may be indicated.
*
* @param data source data array
* @param off zero-based offset in source
* @param len length of array to send
* @param contentType content type to indicate, optionally
* null to indicate no content type
*
* @return null if no body was obtained
* @see #getLastResponse
* @see #setCheckStatus
* @see HttpUtil#read
* @see HttpUtil#discard
*/
public BufferedReader doPost(byte[] data, int off, int len, String contentType)
throws IOException
{
setMethod(Method.POST);
setLenHeader(len);
setContentType(contentType);
DataPoster p = new ByteArrayDataPoster(data, off, len);
client.writeRequest(new ClientRequest(requestLine, headers, p));
return readResponse();
}
/**
* Performs a POST operation, returning a BufferedReader
* for reading the response body. The content type header is set
* to indicate the x-www-form-urlencoded type.
*
* @param urlEncodedData data to send (ASCII format)
* @see HttpUtil#urlEncode
*/
public BufferedReader doPostUrlEncoded(byte[] urlEncodedData)
throws IOException
{
if (urlEncodedData == null)
throw new IllegalArgumentException("null urlEncodedData");
headers.add(MessageHeader.MH_URL_ENCODED);
return doPost(urlEncodedData, 0, urlEncodedData.length, null);
}
/**
* Performs whatever operation was specified in the request line, as
* passed into the constructor. Handles no input or output.
* This method assumes no data will be returned by the server.
* If response data is returned, it is thrown away.
* Call the other {@link #doOperation(InputStream, int, String)
* doOperation} method to have the data returned.
*
* @throws HttpException if (unexpectedly) HTTP was obtained
*/
public void doOperation()
throws IOException
{
doOperation(null, 0, null);
lastResponse.readFully();
}
/**
* Performs whatever operation was specified in the request, as
* passed into the constructor. This method can be used to perform
* tasks not handled by the basic {@link #doPost doPost} and {@link
* #doGet doGet} methods. Utilizes the class {@link GeneralDataPoster}
* to do the data posting.
*
* @param is
* data stream to be copied and output over HTTP;
* if null, no data is written; if the input stream
* supports marking, the post operation may be retried,
* if not any retry will throw an HttpException
* @param len
* if len >= 0, sets the content-length header to this length;
* if len < 0, sets the chunked-encoding header
* @param contentType if not null, specifies the data content type
* in the request
*
* @return wrapped input stream for reading HTTP server data from
*
* @throws HttpException if the supplied input stream does not contain
* enough data to be sent
* @throws IllegalArgumentException if the supplied input stream is null
* and a non-zero length was indicated
*
* @see HttpUtil#readFully
*/
public InputStream doOperation(InputStream is, int len, String contentType)
throws IOException
{
setContentType(contentType);
if (len < 0)
setChunkedHeader();
else if (is != null)
setLenHeader(len);
if (dataPoster == null)
dataPoster = new GeneralDataPoster();
dataPoster.init(is, len);
client.writeRequest(new ClientRequest(requestLine, headers, dataPoster));
return readResponse2();
}
/**
* Closes the wrapped HttpClient.
*/
public void close()
throws IOException
{
client.close();
}
/**
* Returns debug information.
*/
public String toString() {
return "EasyHttpClient client=[" + client + "]";
}
/**
* Performs a command-line test.
*/
public static void main(String args[])
throws Exception
{
if (args.length == 0) {
System.err.println("Usage: EasyHttpClient URL ['post'] [post params]");
System.err.println(" Performs an HTTP GET on the given URL");
System.err.println(" If 'post' is indicated, does an HTTP POST with a string");
System.err.println(" Else, if params are given, does an HTTP POST");
System.err.println(" Post param format: a=b,c=d,e=f");
return;
}
EasyHttpClient c = null;
try {
BufferedReader br;
if (args.length == 2) {
c = new EasyHttpClient(new URL(args[0]), Method.POST);
byte pp[];
StringTokenizer st = new StringTokenizer(args[1], "=, ");
Map m = new HashMap();
while (st.hasMoreTokens()) {
m.put(st.nextToken(), st.nextToken());
}
pp = HttpUtil.urlEncode(m);
System.err.println("Post body");
System.err.println(new String(pp));
br = c.doPostUrlEncoded(pp);
} else if (args.length == 3) {
c = new EasyHttpClient(new URL(args[0]), Method.POST);
byte pp[];
// PLAIN TEXT
pp = args[2].getBytes();
System.err.println("Post body");
System.err.println(new String(pp));
// BAD CHUNKED
// c.getHeaders().add("Transfer-Encoding", "Chunked");
br = c.doPost(pp, 0, pp.length, "text/xml");
/* CORRECTLY CHUNKED
ByteArrayInputStream is = new ByteArrayInputStream("foobar asdjfklajdsf".getBytes());
InputStream is1 = c.doOperation(is, -1, "text/plain");
br = new BufferedReader(new InputStreamReader(is1));
*/
} else {
c = new EasyHttpClient(new URL(args[0]), Method.GET);
br = c.doGet();
}
String s = HttpUtil.read(br);
System.out.println(s);
c.getLastResponse();
// System.out.println(HttpUtil.read(br));
} catch (Exception e) {
System.err.println("Client failed: " + c);
e.printStackTrace();
}
}
}
libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/RequestLine.java 0000644 0001750 0001750 00000007775 10762067376 030223 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http;
import java.net.URL;
import java.util.StringTokenizer;
/**
* This is a immutable implementation of an HTTP request line.
*/
public class RequestLine {
private Method method;
private String requestURI;
private HttpVersion version;
private String toString;
/**
* Constructs using a method, a request URI, and the default HTTP/1.1
* version. If the URI is empty, defaults to the file /.
*/
public RequestLine(Method method, String requestURI) {
this(method, requestURI, HttpVersion.HTTP11);
}
/**
* Constructs using all Request-Line parts.
*/
public RequestLine(Method method, String requestURI, HttpVersion version) {
if (method == null)
throw new IllegalArgumentException("Null method");
if (requestURI == null)
throw new IllegalArgumentException("Null requestURI string");
if (version == null)
throw new IllegalArgumentException("Null version");
this.method = method;
if (requestURI.length() == 0)
requestURI = "/";
this.requestURI = requestURI;
this.version = version;
}
/**
* Construct using an unparsed request line. This string should not end in
* CRLF.
*
* @throws HttpException
* if an invalid HTTP Request-Line was used in initialization
*/
public RequestLine(String line) throws HttpException {
StringTokenizer st = new StringTokenizer(line, " ");
try {
method = Method.valueOf(st.nextToken());
requestURI = st.nextToken();
if (st.hasMoreTokens())
version = HttpVersion.parseVersion(st.nextToken());
else
version = HttpVersion.HTTP10;
} catch (RuntimeException e) {
throw new HttpException("Invalid Request-Line: " + line);
}
}
/**
* Copy-constructs a new RequestLine using a different requestURI.
* @param requestLine existing request line
* @param fileName new file name
*/
public RequestLine(RequestLine requestLine, String requestURI) {
this(requestLine.getMethod(), requestURI, requestLine.getHttpVersion());
}
/**
* Creates and returns a request line based on a URL and method.
* For any method, the line consists of the given method, the filename,
* and HTTP/1.1 request line. For example, a valid method
* is the constant {@link RequestLine#METHOD_GET}.
*/
public static RequestLine create(URL url, Method method) {
if (url == null)
throw new IllegalArgumentException("Null url");
if (method == null)
throw new IllegalArgumentException("Null method");
return new RequestLine(method, url.getFile());
}
/**
* Returns the name of the request method. This should be either one of the
* constant string methods in this class, or an
* extension-method.
*/
public Method getMethod() {
return method;
}
/**
* Returns the URI of this request.
*/
public String getRequestURI() {
return requestURI;
}
/**
* Returns the version of this request.
*/
public HttpVersion getHttpVersion() {
return version;
}
/**
* Returns this RequestLine as:
*
*
*
* Note: Does not include CRLF.
*/
public String toString() {
if (toString == null)
toString = getMethod().name() + ' ' + getRequestURI() + ' '
+ getHttpVersion();
return toString;
}
}
libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/servlet/ 0000755 0001750 0001750 00000000000 11111351352 026537 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/servlet/HttpServletRequestImpl.java libexml-java-0.0.20080703.orig/http/src/main/java/net/noderunner/http/servlet/HttpServletRequestImpl0000644 0001750 0001750 00000022064 10770532150 033154 0 ustar twerner twerner /*
* E-XML Library: For XML, XML-RPC, HTTP, and related.
* Copyright (C) 2002-2008 Elias Ross
*
* genman@noderunner.net
* http://noderunner.net/~genman
*
* 1025 NE 73RD ST
* SEATTLE WA 98115
* USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* $Id$
*/
package net.noderunner.http.servlet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.security.Principal;
import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import net.noderunner.http.ContentType;
import net.noderunner.http.HttpUtil;
import net.noderunner.http.MessageHeader;
import net.noderunner.http.MessageHeaders;
import net.noderunner.http.ServerRequest;
/**
* Simple HTTP servlet request.
* @author Elias Ross
*/
public class HttpServletRequestImpl implements HttpServletRequest {
private ServerRequest request;
private BasicHttpSession session;
private String encoding;
private InputStream inputStream;
private String serverName;
private int serverPort;
private String remoteHost;
private int remotePort;
private String remoteAddr;
private Map parameters = new HashMap();
private Map attributes = new HashMap();
private String localAddr;
private String localName;
private int localPort;
private boolean initParams = false;
/**
* Constructs a new HttpServletRequestImpl based on a server request.
*/
public HttpServletRequestImpl(ServerRequest request) throws IOException {
this.request = request;
this.encoding = getCharacterEncoding0();
try {
URI uri = new URI(request.getRequestLine().getRequestURI());
String rq = uri.getRawQuery();
if (rq != null) {
parameters.putAll(HttpUtil.urlDecode(uri.getRawQuery()));
}
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
inputStream = HttpUtil.wrapInputStream(request.getInputStream(), request.getHeaders());
}
void serverSocket(ServerSocket ss) {
serverName = ss.getLocalSocketAddress().toString();
localName = ss.getLocalSocketAddress().toString();
localAddr = ss.getLocalSocketAddress().toString();
serverPort = ss.getLocalPort();
localPort = ss.getLocalPort();
}
void remoteAddress(InetSocketAddress address) {
remoteHost = address.getHostName();
remoteAddr = address.getAddress().getHostAddress();
remotePort = address.getPort();
}
public String getAuthType() {
return null;
}
private String getURI() {
String uri = request.getRequestLine().getRequestURI();
return uri;
}
public String getContextPath() {
return getURI();
}
public Cookie[] getCookies() {
return new Cookie[0];
}
public long getDateHeader(String fieldName) {
try {
Date date = new HttpDateFormat().parse(getHeader(fieldName));
return date.getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
public String getHeader(String fieldName) {
return request.getHeaders().getFieldContent(fieldName);
}
public Enumeration getHeaderNames() {
return Collections.enumeration(request.getHeaders().getNames());
}
public Enumeration