Package org.apache.http.client.fluent

Examples of org.apache.http.client.fluent.Executor.execute()


            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


            // 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

    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

        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

        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

    protected void removeCol(final String collectionName, final String uid, final String pwd) throws ApiException {
        final String collectionUri = REST_URI + baseUri + "/" + collectionName;
       
        final Executor exec = getExecutor(uid, pwd);
        try {
            final HttpResponse resp = exec.execute(Request.Delete(collectionUri)).returnResponse();
           
            if(resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new ApiException("Could not remove collection: " + collectionUri + ". " + getResponseBody(resp.getEntity()));
            }
        } catch(final IOException ioe) {
View Full Code Here

    @Override
    protected String getXmlResourceContent(final String resourceUri, final String uid, final String pwd) throws ApiException {
        final Executor exec = getExecutor(uid, pwd);
        try {
            final HttpResponse resp = exec.execute(Request.Get(REST_URI + resourceUri)).returnResponse();
           
            if(resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new ApiException("Could not get XML resource from uri: " + resourceUri + ". " + getResponseBody(resp.getEntity()));
            } else {
                return getResponseBody(resp.getEntity());
View Full Code Here

    @Override
    protected void createXmlResource(final String resourceUri, final String content, final String uid, final String pwd) throws ApiException {
        final Executor exec = getExecutor(uid, pwd);
        try {
            final HttpResponse resp = exec.execute(
                    Request.Put(REST_URI + resourceUri)
                    .addHeader("Content-Type", "application/xml")
                    .bodyByteArray(content.getBytes())
            ).returnResponse();
           
View Full Code Here

    @Override
    protected void createBinResource(final String resourceUri, final byte[] content, final String uid, final String pwd) throws ApiException {
         final Executor exec = getExecutor(uid, pwd);
        try {
            final HttpResponse resp = exec.execute(
                    Request.Put(REST_URI + resourceUri)
                    .addHeader("Content-Type", "application/octet-stream")
                    .bodyByteArray(content)
            ).returnResponse();
           
View Full Code Here

    private void executeQuery(final String xquery, final String uid, final String pwd) throws ApiException {
        final Executor exec = getExecutor(uid, pwd);
        try {
            final String queryUri = createQueryUri(xquery);
           
            final HttpResponse resp = exec.execute(Request.Get(queryUri)).returnResponse();
           
            if(resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new ApiException("Could not execute query uri: " + queryUri + ". " + getResponseBody(resp.getEntity()));
            }
        } catch(final IOException ioe) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.