Search in sources :

Example 1 with ProxyAuthorizationHandler

use of org.littleshoot.proxy.ProxyAuthorizationHandler in project camel by apache.

the class SftpSimpleProduceThroughProxyTest method testSftpSimpleTwoSubPathProduceThroughProxy.

@Test
public void testSftpSimpleTwoSubPathProduceThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub/myother?username=admin&password=admin&proxy=#proxy", "Farewell World", Exchange.FILE_NAME, "farewell.txt");
    File file = new File(FTP_ROOT_DIR + "/mysub/myother/farewell.txt");
    assertTrue("File should exist: " + file, file.exists());
    assertEquals("Farewell World", context.getTypeConverter().convertTo(String.class, file));
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) File(java.io.File) Test(org.junit.Test)

Example 2 with ProxyAuthorizationHandler

use of org.littleshoot.proxy.ProxyAuthorizationHandler in project camel by apache.

the class SftpSimpleConsumeThroughProxyTest method testSftpSimpleConsumeThroughProxy.

@Test
public void testSftpSimpleConsumeThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    String expected = "Hello World";
    // create file using regular file
    template.sendBodyAndHeader("file://" + FTP_ROOT_DIR, expected, Exchange.FILE_NAME, "hello.txt");
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedHeaderReceived(Exchange.FILE_NAME, "hello.txt");
    mock.expectedBodiesReceived(expected);
    context.startRoute("foo");
    assertMockEndpointsSatisfied();
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) Test(org.junit.Test)

Example 3 with ProxyAuthorizationHandler

use of org.littleshoot.proxy.ProxyAuthorizationHandler in project camel by apache.

the class SftpSimpleProduceThroughProxyTest method testSftpSimpleSubPathProduceThroughProxy.

@Test
public void testSftpSimpleSubPathProduceThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "/mysub?username=admin&password=admin&proxy=#proxy", "Bye World", Exchange.FILE_NAME, "bye.txt");
    File file = new File(FTP_ROOT_DIR + "/mysub/bye.txt");
    assertTrue("File should exist: " + file, file.exists());
    assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, file));
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) File(java.io.File) Test(org.junit.Test)

Example 4 with ProxyAuthorizationHandler

use of org.littleshoot.proxy.ProxyAuthorizationHandler in project camel by apache.

the class SftpSimpleProduceThroughProxyTest method testSftpSimpleProduceThroughProxy.

@Test
public void testSftpSimpleProduceThroughProxy() throws Exception {
    if (!canTest()) {
        return;
    }
    // start http proxy
    HttpProxyServer proxyServer = new DefaultHttpProxyServer(proxyPort);
    proxyServer.addProxyAuthenticationHandler(new ProxyAuthorizationHandler() {

        @Override
        public boolean authenticate(String userName, String password) {
            return "user".equals(userName) && "password".equals(password);
        }
    });
    proxyServer.start();
    template.sendBodyAndHeader("sftp://localhost:" + getPort() + "/" + FTP_ROOT_DIR + "?username=admin&password=admin&proxy=#proxy", "Hello World", Exchange.FILE_NAME, "hello.txt");
    File file = new File(FTP_ROOT_DIR + "/hello.txt");
    assertTrue("File should exist: " + file, file.exists());
    assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, file));
    proxyServer.stop();
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) ProxyAuthorizationHandler(org.littleshoot.proxy.ProxyAuthorizationHandler) DefaultHttpProxyServer(org.littleshoot.proxy.DefaultHttpProxyServer) File(java.io.File) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DefaultHttpProxyServer (org.littleshoot.proxy.DefaultHttpProxyServer)4 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)4 ProxyAuthorizationHandler (org.littleshoot.proxy.ProxyAuthorizationHandler)4 File (java.io.File)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1