Search in sources :

Example 6 with SimpleHttpServer

use of org.apache.commons.httpclient.server.SimpleHttpServer in project ecf by eclipse.

the class TestBadContentLength method setUp.

// ----------------------------------------------------------- Test Methods
public void setUp() throws IOException {
    client = new HttpClient();
    // use arbitrary port
    server = new SimpleHttpServer();
    server.setTestname(getName());
    server.setRequestHandler(new MyHttpRequestHandler());
}
Also used : SimpleHttpServer(org.apache.commons.httpclient.server.SimpleHttpServer)

Example 7 with SimpleHttpServer

use of org.apache.commons.httpclient.server.SimpleHttpServer in project ecf by eclipse.

the class RestServiceTest method testServerCreation.

public void testServerCreation() {
    assertNotNull(service);
    SimpleHttpServer server = service.getServer();
    assertNotNull(server);
    assertTrue(server.isRunning());
}
Also used : SimpleHttpServer(org.apache.commons.httpclient.server.SimpleHttpServer)

Example 8 with SimpleHttpServer

use of org.apache.commons.httpclient.server.SimpleHttpServer in project ecf by eclipse.

the class RestServiceTest method testStop.

public void testStop() {
    SimpleHttpServer server = service.getServer();
    assertNotNull(server);
    service.shutdown();
    server = service.getServer();
    assertNull(server);
}
Also used : SimpleHttpServer(org.apache.commons.httpclient.server.SimpleHttpServer)

Example 9 with SimpleHttpServer

use of org.apache.commons.httpclient.server.SimpleHttpServer in project ecf by eclipse.

the class SimpleRestService method createServer.

private void createServer() {
    try {
        server = new SimpleHttpServer();
        server.setRequestHandler(reqHandler);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : SimpleHttpServer(org.apache.commons.httpclient.server.SimpleHttpServer) IOException(java.io.IOException)

Example 10 with SimpleHttpServer

use of org.apache.commons.httpclient.server.SimpleHttpServer in project ecf by eclipse.

the class URLRetrieveTestCancelConnectJob method testReceiveFile_cancelConnectJob.

// TODO: add test that cancel without connect job, when server does not
// respond
public void testReceiveFile_cancelConnectJob() throws Exception {
    if (!CANCEL_SUPPORTED_ON_CONNECT) {
        trace("WARNING:  Cancel not supported by this provider.  testReceiveFile_cancelConnectJob cannot be used");
        return;
    }
    final Object[] doCancel = new Object[1];
    final IFileTransferListener listener = createFileTransferListener();
    final FileTransferListenerWrapper lw = new FileTransferListenerWrapper(listener) {

        protected void handleStartConnectEvent(final IFileTransferConnectStartEvent event) {
            assertNotNull(event.getFileID());
            assertNotNull(event.getFileID().getFilename());
            FileTransferJob connectJob = event.prepareConnectJob(null);
            connectJob.addJobChangeListener(new JobChangeTraceListener(startTime) {

                public void running(IJobChangeEvent jobEvent) {
                    super.running(jobEvent);
                    spawnCancelThread(doCancel, new ICancelable() {

                        public void cancel() {
                            assertNotNull(socketInReadWrapper);
                            assertTrue(socketInReadWrapper.inRead);
                            event.cancel();
                        }
                    });
                }
            });
            event.connectUsingJob(connectJob);
        }
    };
    final SimpleServer server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

        public boolean processRequest(SimpleHttpServerConnection conn, SimpleRequest request) throws IOException {
            trace("Not responding to request " + request.getRequestLine());
            return stalledInRequestHandler(doCancel);
        }
    });
    try {
        // path does not matter as server does not respond.
        testReceive(server.getServerURL() + "/foo", lw);
        assertHasEvent(startConnectEvents, IFileTransferConnectStartEvent.class);
        assertHasNoEvent(startEvents, IIncomingFileTransferReceiveStartEvent.class);
        assertHasNoEvent(dataEvents, IIncomingFileTransferReceiveDataEvent.class);
        IIncomingFileTransferReceiveDoneEvent doneEvent = getDoneEvent();
        assertTrue(doneEvent.getException().toString(), doneEvent.getException() instanceof UserCancelledException);
        assertTrue(doneEvent.getSource().isDone());
        assertSame(doneEvent.getException(), doneEvent.getSource().getException());
        assertNull(tmpFile);
        assertFalse(socketInReadWrapper.inRead);
        socketEvents.validateOneSocketCreatedAndClosed();
    } finally {
        server.shutdown();
    }
}
Also used : SimpleServer(org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer) HttpRequestHandler(org.apache.commons.httpclient.server.HttpRequestHandler) UserCancelledException(org.eclipse.ecf.filetransfer.UserCancelledException) SimpleHttpServerConnection(org.apache.commons.httpclient.server.SimpleHttpServerConnection) IFileTransferListener(org.eclipse.ecf.filetransfer.IFileTransferListener) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SimpleRequest(org.apache.commons.httpclient.server.SimpleRequest) IOException(java.io.IOException) IFileTransferConnectStartEvent(org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent) FileTransferJob(org.eclipse.ecf.filetransfer.FileTransferJob) SimpleHttpServer(org.apache.commons.httpclient.server.SimpleHttpServer) IIncomingFileTransferReceiveDoneEvent(org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveDoneEvent)

Aggregations

SimpleHttpServer (org.apache.commons.httpclient.server.SimpleHttpServer)12 IOException (java.io.IOException)5 HttpRequestHandler (org.apache.commons.httpclient.server.HttpRequestHandler)4 SimpleHttpServerConnection (org.apache.commons.httpclient.server.SimpleHttpServerConnection)4 SimpleRequest (org.apache.commons.httpclient.server.SimpleRequest)4 SimpleServer (org.eclipse.ecf.internal.tests.filetransfer.httpserver.SimpleServer)4 ResponseWriter (org.apache.commons.httpclient.server.ResponseWriter)3 FileTransferJob (org.eclipse.ecf.filetransfer.FileTransferJob)3 IFileTransferListener (org.eclipse.ecf.filetransfer.IFileTransferListener)3 IFileTransferConnectStartEvent (org.eclipse.ecf.filetransfer.events.IFileTransferConnectStartEvent)3 IIncomingFileTransferReceiveStartEvent (org.eclipse.ecf.filetransfer.events.IIncomingFileTransferReceiveStartEvent)2 Map (java.util.Map)1 FakeHttpMethod (org.apache.commons.httpclient.FakeHttpMethod)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)1 GetMethod (org.apache.commons.httpclient.methods.GetMethod)1 Protocol (org.apache.commons.httpclient.protocol.Protocol)1 SimpleProxy (org.apache.commons.httpclient.server.SimpleProxy)1 SimpleSocketFactory (org.apache.commons.httpclient.server.SimpleSocketFactory)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1