Package org.apache.http.client.fluent

Examples of org.apache.http.client.fluent.Executor


        log.info("delivering package {} to {} using auth {}",
                new Object[]{replicationPackage.getId(),
                        replicationEndpoint.getUri(), transportAuthenticationProvider});

        try {
            Executor executor = Executor.newInstance();
            TransportAuthenticationContext context = new TransportAuthenticationContext();
            context.addAttribute("endpoint", replicationEndpoint);
            executor = transportAuthenticationProvider.authenticate(executor, context);

            deliverPackage(executor, replicationPackage, replicationEndpoint);
View Full Code Here


        if (endpoint == null) {
            throw new TransportAuthenticationException("the endpoint to authenticate is missing from the context");
        }

        if (authenticable instanceof Executor) {
            Executor executor = (Executor) authenticable;

            Executor authenticated = executor.auth(new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort()),
                    username, password).authPreemptive(
                        new HttpHost(endpoint.getUri().getHost(), endpoint.getUri().getPort()));
            log.debug("authenticated executor HTTP client with user and password");
            return authenticated;
View Full Code Here

                        replicationEndpoint.getUri(),
                        transportAuthenticationProvider
        });

        try {
            Executor executor = Executor.newInstance();

            TransportAuthenticationContext context = new TransportAuthenticationContext();
            context.addAttribute("endpoint", replicationEndpoint);
            executor = transportAuthenticationProvider.authenticate(executor, context);

            Request req = Request.Post(replicationEndpoint.getUri()).useExpectContinue();

            InputStream inputStream = null;
            Response response = null;
            try {

                inputStream = replicationPackage.createInputStream();

                req = req.bodyStream(inputStream, ContentType.APPLICATION_OCTET_STREAM);
                response = executor.execute(req);
            } finally {
                IOUtils.closeQuietly(inputStream);
            }

            if (response != null) {
View Full Code Here

            URI replicationURI = RequestUtils.appendReplicationRequest(replicationEndpoint.getUri(), replicationRequest);
            List<ReplicationPackage> result = new ArrayList<ReplicationPackage>();

            // TODO : executor should be cached and reused

            Executor executor = Executor.newInstance();
            TransportAuthenticationContext context = new TransportAuthenticationContext();
            context.addAttribute("endpoint", replicationEndpoint);
            executor = transportAuthenticationProvider.authenticate(executor, context);

            Request req = Request.Post(replicationURI).useExpectContinue();

            // TODO : add queue parameter

            // continuously requests package streams as long as type header is received with the response (meaning there's a package of a certain type)
            HttpResponse httpResponse;
            try {

                int polls = 0;
                while ((httpResponse = executor.execute(req).returnResponse())
                        .getStatusLine().getStatusCode() == 200
                        && polls < maxNumberOfPackages) {
                    HttpEntity entity = httpResponse.getEntity();
                    if (entity != null) {
                        final ReplicationPackage responsePackage = packageBuilder.readPackage(resourceResolver, entity.getContent());
View Full Code Here

    @Test
    public void testDeliverPackage() throws Exception {
        TransportAuthenticationProvider<Executor, Executor> authProvider = mock(TransportAuthenticationProvider.class);
        when(authProvider.canAuthenticate(Executor.class)).thenReturn(true);
        Executor executor = mock(Executor.class);
        Response response = mock(Response.class);
        when(executor.execute(any(Request.class))).thenReturn(response);
        when(authProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
        ReplicationEndpoint endpoint = new ReplicationEndpoint("http://127.0.0.1:8080/some/resource");
        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
        int maxNoOfPackages = Integer.MAX_VALUE;
        SimpleHttpReplicationTransportHandler simpleHttpReplicationTransportHandler = new SimpleHttpReplicationTransportHandler(
View Full Code Here

    @Test
    public void testRetrievePackagesRemotelyFailing() throws Exception {
        TransportAuthenticationProvider<Executor, Executor> authProvider = mock(TransportAuthenticationProvider.class);
        when(authProvider.canAuthenticate(Executor.class)).thenReturn(true);
        Executor executor = mock(Executor.class);
        Response response = mock(Response.class);
        HttpResponse httpResponse = mock(HttpResponse.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(statusLine.getStatusCode()).thenReturn(404);
        when(httpResponse.getStatusLine()).thenReturn(statusLine);
        when(response.returnResponse()).thenReturn(httpResponse);
        when(executor.execute(any(Request.class))).thenReturn(response);
        when(authProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
        ReplicationEndpoint endpoint = new ReplicationEndpoint("http://127.0.0.1:8080/some/resource");
        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
        int maxNoOfPackages = 1;
        SimpleHttpReplicationTransportHandler simpleHttpReplicationTransportHandler = new SimpleHttpReplicationTransportHandler(
View Full Code Here

    @Test
    public void testRetrievePackagesRemotelyWorking() throws Exception {
        TransportAuthenticationProvider<Executor, Executor> authProvider = mock(TransportAuthenticationProvider.class);
        when(authProvider.canAuthenticate(Executor.class)).thenReturn(true);
        Executor executor = mock(Executor.class);
        Response response = mock(Response.class);
        HttpResponse httpResponse = mock(HttpResponse.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(statusLine.getStatusCode()).thenReturn(200);
        when(httpResponse.getStatusLine()).thenReturn(statusLine);
        HttpEntity entity = mock(HttpEntity.class);
        InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
        when(entity.getContent()).thenReturn(stream);
        when(httpResponse.getEntity()).thenReturn(entity);
        when(response.returnResponse()).thenReturn(httpResponse);
        when(executor.execute(any(Request.class))).thenReturn(response);
        when(authProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
        ReplicationEndpoint endpoint = new ReplicationEndpoint("http://127.0.0.1:8080/some/resource");
        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
        when(replicationPackage.getInfo()).thenReturn(mock(ReplicationPackageInfo.class));
View Full Code Here

    @Test
    public void testAuthenticationWithNullAuthenticableAndContext() throws Exception {
        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
                "foo", "bar");
        Executor authenticable = null;
        TransportAuthenticationContext context = null;
        try {
            authenticationHandler.authenticate(authenticable, context);
            fail("could not authenticate a null authenticable");
        } catch (Exception e) {
View Full Code Here

    @Test
    public void testAuthenticationWithAuthenticableAndNullContext() throws Exception {
        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
                "foo", "bar");
        Executor authenticable = Executor.newInstance();
        TransportAuthenticationContext context = null;
        try {
            authenticationHandler.authenticate(authenticable, context);
            fail("could not authenticate with a null context");
        } catch (Exception e) {
View Full Code Here

    @Test
    public void testAuthenticationWithAuthenticableAndEmptyContext() throws Exception {
        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
                "foo", "bar");
        Executor authenticable = Executor.newInstance();
        TransportAuthenticationContext context = new TransportAuthenticationContext();
        try {
            authenticationHandler.authenticate(authenticable, context);
            fail("could not authenticate with an empty context");
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.http.client.fluent.Executor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.