use of org.apache.commons.httpclient.server.SimpleProxy in project ecf by eclipse.
the class HttpClientTestBase method setUp.
// ------------------------------------------------- TestCase setup/shutdown
public void setUp() throws IOException {
// Configure socket factories
SimpleSocketFactory serversocketfactory = null;
Protocol testhttp = null;
/* XXX removed because ssl test code not included
if (this.useSSL) {
serversocketfactory = new SimpleSSLSocketFactory();
testhttp = new Protocol("https",
(ProtocolSocketFactory)new SimpleSSLTestProtocolSocketFactory(), 443);
} else {
serversocketfactory = new SimplePlainSocketFactory();
testhttp = Protocol.getProtocol("http");
}
*/
// use arbitrary port
this.server = new SimpleHttpServer(serversocketfactory, 0);
this.server.setTestname(getName());
this.client = new HttpClient();
this.client.getHostConfiguration().setHost(this.server.getLocalAddress(), this.server.getLocalPort(), testhttp);
if (this.useProxy) {
this.proxy = new SimpleProxy();
client.getHostConfiguration().setProxy(proxy.getLocalAddress(), proxy.getLocalPort());
}
}
use of org.apache.commons.httpclient.server.SimpleProxy in project ecf by eclipse.
the class TestConnectionPersistence method testProxyConnClose.
public void testProxyConnClose() throws Exception {
this.server.setHttpService(new EchoService());
this.proxy = new SimpleProxy();
this.client.getHostConfiguration().setProxy(proxy.getLocalAddress(), proxy.getLocalPort());
AccessibleHttpConnectionManager connman = new AccessibleHttpConnectionManager();
this.client.setHttpConnectionManager(connman);
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertTrue(connman.getConection().isOpen());
httpget = new GetMethod("/test/");
httpget.setRequestHeader("Proxy-Connection", "Close");
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertFalse(connman.getConection().isOpen());
assertEquals("Close", httpget.getRequestHeader("Proxy-Connection").getValue());
}
use of org.apache.commons.httpclient.server.SimpleProxy in project ecf by eclipse.
the class TestHostConfiguration method testAbsoluteURLOverridesDefaultHostParam.
public void testAbsoluteURLOverridesDefaultHostParam() throws IOException {
this.proxy = new SimpleProxy();
this.server.setHttpService(new EchoService());
// reset default host configuration
HostConfiguration hostconfig = new HostConfiguration();
hostconfig.setHost("somehwere.outthere.in.pampa", 9999);
hostconfig.setProxy(this.proxy.getLocalAddress(), this.proxy.getLocalPort());
GetMethod httpget = new GetMethod("http://" + this.server.getLocalAddress() + ":" + this.server.getLocalPort() + "/test/");
try {
this.client.executeMethod(hostconfig, httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertNotNull(httpget.getResponseHeader("Via"));
} finally {
httpget.releaseConnection();
}
httpget = new GetMethod("/test/");
try {
this.client.executeMethod(hostconfig, httpget);
assertEquals(HttpStatus.SC_NOT_FOUND, httpget.getStatusCode());
} finally {
httpget.releaseConnection();
}
}
Aggregations