Search in sources :

Example 6 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project azure-iot-sdk-java by Azure.

the class DeviceMethodTests method invokeMethodWithServiceSideProxy.

@Test
@StandardTierHubOnlyTest
public void invokeMethodWithServiceSideProxy() throws Exception {
    if (testInstance.protocol != IotHubClientProtocol.MQTT || testInstance.authenticationType != AuthenticationType.SAS || testInstance.clientType != ClientType.DEVICE_CLIENT) {
        // when the device is using MQTT with SAS auth
        return;
    }
    String testProxyHostname = "127.0.0.1";
    int testProxyPort = 8894;
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(testProxyPort).start();
    try {
        Proxy serviceSideProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
        ProxyOptions proxyOptions = new ProxyOptions(serviceSideProxy);
        DeviceMethodClientOptions options = DeviceMethodClientOptions.builder().proxyOptions(proxyOptions).httpReadTimeout(HTTP_READ_TIMEOUT).build();
        this.testInstance.methodServiceClient = DeviceMethod.createFromConnectionString(iotHubConnectionString, options);
        super.openDeviceClientAndSubscribeToMethods();
        super.invokeMethodSucceed();
    } finally {
        proxyServer.stop();
    }
}
Also used : DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) Proxy(java.net.Proxy) ProxyOptions(com.microsoft.azure.sdk.iot.service.ProxyOptions) DeviceMethodClientOptions(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethodClientOptions) InetSocketAddress(java.net.InetSocketAddress) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test)

Example 7 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer 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 8 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer 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)

Example 9 with HttpProxyServer

use of org.littleshoot.proxy.HttpProxyServer in project jackrabbit by apache.

the class ConnectionTest method testObtainViaProxyWithValidCredentials.

public void testObtainViaProxyWithValidCredentials() throws URISyntaxException, RepositoryException {
    ProxyAuthenticator authenticator = new ProxyAuthenticator() {

        @Override
        public String getRealm() {
            return null;
        }

        @Override
        public boolean authenticate(String userName, String password) {
            if (userName.equals("test") && password.equals("valid")) {
                return true;
            }
            return false;
        }
    };
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
    0).withProxyAuthenticator(authenticator).start();
    try {
        Map<String, String> parameters = new HashMap<>();
        ConnectionOptions.Builder builder = ConnectionOptions.builder();
        builder.proxyHost("127.0.0.1");
        builder.proxyPort(proxyServer.getListenAddress().getPort());
        builder.proxyUsername("test");
        builder.proxyPassword("valid");
        parameters.putAll(builder.build().toServiceFactoryParameters());
        RepositoryService repositoryService = createRepositoryService(false, parameters);
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
    } finally {
        proxyServer.stop();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HashMap(java.util.HashMap) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Aggregations

HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)9 Test (org.junit.Test)6 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)5 DefaultHttpProxyServer (org.littleshoot.proxy.DefaultHttpProxyServer)4 ProxyAuthorizationHandler (org.littleshoot.proxy.ProxyAuthorizationHandler)4 File (java.io.File)3 HashMap (java.util.HashMap)3 SimpleCredentials (javax.jcr.SimpleCredentials)3 RepositoryService (org.apache.jackrabbit.spi.RepositoryService)3 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)2 ProxyOptions (com.microsoft.azure.sdk.iot.service.ProxyOptions)2 InetSocketAddress (java.net.InetSocketAddress)2 Proxy (java.net.Proxy)2 ProxyAuthenticator (org.littleshoot.proxy.ProxyAuthenticator)2 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)2 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)2 DeviceMethodClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethodClientOptions)1 DeviceTwinClientOptions (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinClientOptions)1 RepositoryException (javax.jcr.RepositoryException)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1