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();
}
}
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();
}
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();
}
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();
}
}
Aggregations