Search in sources :

Example 1 with DigestAuthentication

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();
    }
}
Also used : StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) FileInputStream(java.io.FileInputStream) AuthenticationStore(org.eclipse.jetty.client.api.AuthenticationStore) Test(org.junit.Test)

Example 2 with DigestAuthentication

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"));
}
Also used : DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) Test(org.junit.Test)

Example 3 with DigestAuthentication

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"));
}
Also used : DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) Test(org.junit.Test)

Example 4 with DigestAuthentication

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()));
        }
    }
}
Also used : Origin(org.eclipse.jetty.client.Origin) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) HttpProxy(org.eclipse.jetty.client.HttpProxy) Socks4Proxy(org.eclipse.jetty.client.Socks4Proxy) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication)

Example 5 with DigestAuthentication

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();
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HttpClient(org.eclipse.jetty.client.HttpClient) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) URI(java.net.URI) AuthenticationStore(org.eclipse.jetty.client.api.AuthenticationStore) Test(org.junit.Test)

Aggregations

DigestAuthentication (org.eclipse.jetty.client.util.DigestAuthentication)8 URI (java.net.URI)7 Test (org.junit.Test)5 BasicAuthentication (org.eclipse.jetty.client.util.BasicAuthentication)4 HttpProxy (org.eclipse.jetty.client.HttpProxy)3 Origin (org.eclipse.jetty.client.Origin)3 Socks4Proxy (org.eclipse.jetty.client.Socks4Proxy)3 Authentication (org.eclipse.jetty.client.api.Authentication)3 AuthenticationStore (org.eclipse.jetty.client.api.AuthenticationStore)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SalesforceSession (org.apache.camel.component.salesforce.internal.SalesforceSession)2 SSLContextParameters (org.apache.camel.util.jsse.SSLContextParameters)2 HttpClient (org.eclipse.jetty.client.HttpClient)2 ProxyConfiguration (org.eclipse.jetty.client.ProxyConfiguration)2 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 Request (org.eclipse.jetty.client.api.Request)2 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1