use of org.littleshoot.proxy.HttpProxyServer 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();
}
use of org.littleshoot.proxy.HttpProxyServer 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();
}
use of org.littleshoot.proxy.HttpProxyServer in project jackrabbit by apache.
the class ConnectionTest method testObtainViaProxy.
public void testObtainViaProxy() throws URISyntaxException, RepositoryException {
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
0).start();
try {
Map<String, String> parameters = new HashMap<>();
ConnectionOptions.Builder builder = ConnectionOptions.builder();
builder.proxyHost("127.0.0.1");
builder.proxyPort(proxyServer.getListenAddress().getPort());
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(false, parameters);
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
} finally {
proxyServer.stop();
}
}
use of org.littleshoot.proxy.HttpProxyServer in project jackrabbit by apache.
the class ConnectionTest method testObtainViaProxyWithInvalidCredentials.
public void testObtainViaProxyWithInvalidCredentials() throws URISyntaxException, RepositoryException {
ProxyAuthenticator authenticator = new ProxyAuthenticator() {
@Override
public String getRealm() {
return null;
}
@Override
public boolean authenticate(String userName, String password) {
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("invalid");
parameters.putAll(builder.build().toServiceFactoryParameters());
RepositoryService repositoryService = createRepositoryService(false, parameters);
try {
repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
fail("should have failed with proxy authentication failure!");
} catch (RepositoryException expected) {
}
} finally {
proxyServer.stop();
}
}
use of org.littleshoot.proxy.HttpProxyServer in project azure-iot-sdk-java by Azure.
the class GetTwinTests method testGetDeviceTwinWithProxy.
@Test
@StandardTierHubOnlyTest
public void testGetDeviceTwinWithProxy() throws IOException, InterruptedException, IotHubException, GeneralSecurityException, ModuleClientException, URISyntaxException {
if (testInstance.protocol != IotHubClientProtocol.MQTT || testInstance.authenticationType != AuthenticationType.SAS || testInstance.clientType != ClientType.DEVICE_CLIENT) {
// when the device is using MQTT with SAS auth
return;
}
super.setUpNewDeviceAndModule();
String testProxyHostname = "127.0.0.1";
int testProxyPort = 8892;
HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(testProxyPort).start();
try {
Proxy serviceSideProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(testProxyHostname, testProxyPort));
ProxyOptions proxyOptions = new ProxyOptions(serviceSideProxy);
DeviceTwinClientOptions options = DeviceTwinClientOptions.builder().proxyOptions(proxyOptions).build();
testInstance.twinServiceClient = DeviceTwin.createFromConnectionString(iotHubConnectionString, options);
super.testGetDeviceTwin();
} finally {
proxyServer.stop();
}
}
Aggregations