use of org.eclipse.jetty.client.util.DigestAuthentication in project jetty.project by eclipse.
the class DigestPostTest method testServerWithHttpClientStreamContent.
@Test
public void testServerWithHttpClientStreamContent() throws Exception {
String srvUrl = "http://127.0.0.1:" + ((NetworkConnector) _server.getConnectors()[0]).getLocalPort() + "/test/";
HttpClient client = new HttpClient();
try {
AuthenticationStore authStore = client.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
client.start();
String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
Request request = client.newRequest(srvUrl);
request.method(HttpMethod.POST);
request.content(new StringContentProvider(sent));
_received = null;
request = request.timeout(5, TimeUnit.SECONDS);
ContentResponse response = request.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(sent, _received);
} finally {
client.stop();
}
}
use of org.eclipse.jetty.client.util.DigestAuthentication in project jetty.project by eclipse.
the class HttpClientAuthenticationTest method test_DigestAuthentication.
@Test
public void test_DigestAuthentication() throws Exception {
startDigest(new EmptyServerHandler());
URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
test_Authentication(new DigestAuthentication(uri, realm, "digest", "digest"));
}
use of org.eclipse.jetty.client.util.DigestAuthentication in project jetty.project by eclipse.
the class HttpClientAuthenticationTest method test_DigestAnyRealm.
@Test
public void test_DigestAnyRealm() throws Exception {
startDigest(new EmptyServerHandler());
URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
test_Authentication(new DigestAuthentication(uri, Authentication.ANY_REALM, "digest", "digest"));
}
use of org.eclipse.jetty.client.util.DigestAuthentication in project camel by apache.
the class SalesforceComponentVerifier method configureHttpProxy.
private void configureHttpProxy(SalesforceHttpClient httpClient, Map<String, Object> parameters) throws NoSuchOptionException, URISyntaxException {
Optional<String> httpProxyHost = getOption(parameters, "httpProxyHost", String.class);
Optional<Integer> httpProxyPort = getOption(parameters, "httpProxyPort", Integer.class);
Optional<String> httpProxyUsername = getOption(parameters, "httpProxyUsername", String.class);
Optional<String> httpProxyPassword = getOption(parameters, "httpProxyPassword", String.class);
if (httpProxyHost.isPresent() && httpProxyPort.isPresent()) {
Origin.Address address = new Origin.Address(httpProxyHost.get(), httpProxyPort.get());
Boolean isHttpProxySocks4 = getOption(parameters, "isHttpProxySocks4", Boolean.class, () -> false);
Boolean isHttpProxySecure = getOption(parameters, "isHttpProxySecure", Boolean.class, () -> true);
if (isHttpProxySocks4) {
httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(address, isHttpProxySecure));
} else {
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(address, isHttpProxySecure));
}
}
if (httpProxyUsername.isPresent() && httpProxyPassword.isPresent()) {
Boolean httpProxyUseDigestAuth = getOption(parameters, "httpProxyUseDigestAuth", Boolean.class, () -> false);
String httpProxyAuthUri = getMandatoryOption(parameters, "httpProxyAuthUri", String.class);
String httpProxyRealm = getMandatoryOption(parameters, "httpProxyRealm", String.class);
if (httpProxyUseDigestAuth) {
httpClient.getAuthenticationStore().addAuthentication(new DigestAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
} else {
httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
}
}
}
use of org.eclipse.jetty.client.util.DigestAuthentication in project jetty.project by eclipse.
the class DigestPostTest method testServerWithHttpClientStringContent.
@Test
public void testServerWithHttpClientStringContent() throws Exception {
String srvUrl = "http://127.0.0.1:" + ((NetworkConnector) _server.getConnectors()[0]).getLocalPort() + "/test/";
HttpClient client = new HttpClient();
try {
AuthenticationStore authStore = client.getAuthenticationStore();
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
client.start();
Request request = client.newRequest(srvUrl);
request.method(HttpMethod.POST);
request.content(new BytesContentProvider(__message.getBytes("UTF8")));
_received = null;
request = request.timeout(5, TimeUnit.SECONDS);
ContentResponse response = request.send();
Assert.assertEquals(__message, _received);
Assert.assertEquals(200, response.getStatus());
} finally {
client.stop();
}
}
Aggregations