Example usage for org.apache.http.message BasicHttpRequest BasicHttpRequest

List of usage examples for org.apache.http.message BasicHttpRequest BasicHttpRequest

Introduction

In this page you can find the example usage for org.apache.http.message BasicHttpRequest BasicHttpRequest.

Prototype

public BasicHttpRequest(String str, String str2, ProtocolVersion protocolVersion) 

Source Link

Usage

From source file:net.spy.memcached.CouchbaseClient.java

/**
 * Asynchronously queries a Couchbase view by calling its map function and
 * then the views reduce function./*  w  ww  .j a  v a2  s. c o  m*/
 *
 * @param view the view to run the query against.
 * @param query the type of query to run against the view.
 * @return a Future containing the results of the query.
 */
private HttpFuture<ViewResponse> asyncQueryAndReduce(final View view, final Query query) {
    if (!view.hasReduce()) {
        throw new RuntimeException("This view doesn't contain a reduce function");
    }
    String uri = view.getURI() + query.toString();
    final CountDownLatch couchLatch = new CountDownLatch(1);
    final HttpFuture<ViewResponse> crv = new HttpFuture<ViewResponse>(couchLatch, 60000);

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new ReducedOperationImpl(request, new ViewCallback() {
        private ViewResponse vr = null;

        @Override
        public void receivedStatus(OperationStatus status) {
            crv.set(vr, status);
        }

        @Override
        public void complete() {
            couchLatch.countDown();
        }

        @Override
        public void gotData(ViewResponse response) {
            vr = response;
        }
    });
    crv.setOperation(op);
    addOp(op);
    return crv;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Gets access to a view contained in a design document from the cluster.
 *
 * The purpose of a view is take the structured data stored within the
 * Couchbase Server database as JSON documents, extract the fields and
 * information, and to produce an index of the selected information.
 *
 * The result is a view on the stored data. The view that is created
 * during this process allows you to iterate, select and query the
 * information in your database from the raw data objects that have
 * been stored./*  w  w w. j  av a2s. co  m*/
 *
 * Note that since an HttpFuture is returned, the caller must also check to
 * see if the View is null. The HttpFuture does provide a getStatus() method
 * which can be used to check whether or not the view request has been
 * successful.
 *
 * @param designDocumentName the name of the design document.
 * @param viewName the name of the view to get.
 * @return a View object from the cluster.
 * @throws InterruptedException if the operation is interrupted while in
 *           flight
 * @throws ExecutionException if an error occurs during execution
 */
public HttpFuture<View> asyncGetView(String designDocumentName, final String viewName) {
    CouchbaseConnectionFactory factory = (CouchbaseConnectionFactory) connFactory;

    designDocumentName = MODE_PREFIX + designDocumentName;
    String bucket = factory.getBucketName();
    String uri = "/" + bucket + "/_design/" + designDocumentName;
    final CountDownLatch couchLatch = new CountDownLatch(1);
    final HttpFuture<View> crv = new HttpFuture<View>(couchLatch, factory.getViewTimeout());

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new ViewFetcherOperationImpl(request, bucket, designDocumentName, viewName,
            new ViewFetcherOperation.ViewFetcherCallback() {
                private View view = null;

                @Override
                public void receivedStatus(OperationStatus status) {
                    crv.set(view, status);
                }

                @Override
                public void complete() {
                    couchLatch.countDown();
                }

                @Override
                public void gotData(View v) {
                    view = v;
                }
            });
    crv.setOperation(op);
    addOp(op);
    assert crv != null : "Problem retrieving view";
    return crv;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Gets access to a spatial view contained in a design document from the
 * cluster.//from   w  ww . ja  va  2s .  co  m
 *
 *
 * Note that since an HttpFuture is returned, the caller must also check to
 * see if the View is null. The HttpFuture does provide a getStatus() method
 * which can be used to check whether or not the view request has been
 * successful.
 *
 * @param designDocumentName the name of the design document.
 * @param viewName the name of the spatial view to get.
 * @return a HttpFuture<SpatialView> object from the cluster.
 * @throws InterruptedException if the operation is interrupted while in
 *           flight
 * @throws ExecutionException if an error occurs during execution
 */
public HttpFuture<SpatialView> asyncGetSpatialView(String designDocumentName, final String viewName) {
    CouchbaseConnectionFactory factory = (CouchbaseConnectionFactory) connFactory;
    designDocumentName = MODE_PREFIX + designDocumentName;
    String bucket = factory.getBucketName();
    String uri = "/" + bucket + "/_design/" + designDocumentName;
    final CountDownLatch couchLatch = new CountDownLatch(1);
    final HttpFuture<SpatialView> crv = new HttpFuture<SpatialView>(couchLatch, factory.getViewTimeout());

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new SpatialViewFetcherOperationImpl(request, bucket, designDocumentName, viewName,
            new SpatialViewFetcherOperation.ViewFetcherCallback() {
                private SpatialView view = null;

                @Override
                public void receivedStatus(OperationStatus status) {
                    crv.set(view, status);
                }

                @Override
                public void complete() {
                    couchLatch.countDown();
                }

                @Override
                public void gotData(SpatialView v) {
                    view = v;
                }
            });
    crv.setOperation(op);
    addOp(op);
    assert crv != null : "Problem retrieving spatial view";
    return crv;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Gets a future with a design document from the cluster.
 *
 * If no design document was found, the enclosed DesignDocument inside
 * the future will be null./*from w  w w.  j  ava 2s  .c  o m*/
 *
 * @param designDocumentName the name of the design document.
 * @return a future containing a DesignDocument from the cluster.
 */
public HttpFuture<DesignDocument> asyncGetDesignDocument(String designDocumentName) {
    designDocumentName = MODE_PREFIX + designDocumentName;
    String bucket = ((CouchbaseConnectionFactory) connFactory).getBucketName();
    String uri = "/" + bucket + "/_design/" + designDocumentName;
    final CountDownLatch couchLatch = new CountDownLatch(1);
    final HttpFuture<DesignDocument> crv = new HttpFuture<DesignDocument>(couchLatch, 60000);

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new DesignDocFetcherOperationImpl(request, designDocumentName,
            new DesignDocFetcherOperation.DesignDocFetcherCallback() {
                private DesignDocument design = null;

                @Override
                public void receivedStatus(OperationStatus status) {
                    crv.set(design, status);
                }

                @Override
                public void complete() {
                    couchLatch.countDown();
                }

                @Override
                public void gotData(DesignDocument d) {
                    design = d;
                }
            });
    crv.setOperation(op);
    addOp(op);
    return crv;
}

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java

/**
 * Creates the CONNECT request for tunnelling.
 * Called by {@link #createTunnelToTarget createTunnelToTarget}.
 * //www.  j ava  2s.c om
 * @param route
 *            the route to establish
 * @param context
 *            the context for request execution
 * 
 * @return the CONNECT request for tunnelling
 */
private HttpRequest createConnectRequest(HttpRoute route) {
    // see RFC 2817, section 5.2 and
    // INTERNET-DRAFT: Tunneling TCP based protocols through
    // Web proxy servers

    HttpHost target = route.getTargetHost();

    String host = target.getHostName();
    int port = target.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
        port = scheme.getDefaultPort();
    }

    StringBuilder buffer = new StringBuilder(host.length() + 6);
    buffer.append(host);
    buffer.append(':');
    buffer.append(Integer.toString(port));

    String authority = buffer.toString();
    ProtocolVersion ver = HttpProtocolParams.getVersion(params);
    HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);

    return req;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Asynchronously queries a Couchbase view and returns the result.
 * The result can be accessed row-wise via an iterator. This
 * type of query will return the view result along with all of the documents
 * for each row in the query./*from   w  w w .  j a  va  2  s  .c  o m*/
 *
 * @param view the view to run the query against.
 * @param query the type of query to run against the view.
 * @return a Future containing the results of the query.
 */
private HttpFuture<ViewResponse> asyncQueryAndIncludeDocs(AbstractView view, Query query) {
    assert view != null : "Who passed me a null view";
    assert query != null : "who passed me a null query";
    String viewUri = view.getURI();
    String queryToRun = query.toString();
    assert viewUri != null : "view URI seems to be null";
    assert queryToRun != null : "query seems to be null";
    String uri = viewUri + queryToRun;
    getLogger().info("lookin for:" + uri);
    final CountDownLatch couchLatch = new CountDownLatch(1);
    int timeout = ((CouchbaseConnectionFactory) connFactory).getViewTimeout();
    final ViewFuture crv = new ViewFuture(couchLatch, timeout, view);

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new DocsOperationImpl(request, view, new ViewCallback() {
        private ViewResponse vr = null;

        @Override
        public void receivedStatus(OperationStatus status) {
            if (vr != null) {
                Collection<String> ids = new LinkedList<String>();
                Iterator<ViewRow> itr = vr.iterator();
                while (itr.hasNext()) {
                    ids.add(itr.next().getId());
                }
                crv.set(vr, asyncGetBulk(ids), status);
            } else {
                crv.set(null, null, status);
            }
        }

        @Override
        public void complete() {
            couchLatch.countDown();
        }

        @Override
        public void gotData(ViewResponse response) {
            vr = response;
        }
    });
    crv.setOperation(op);
    addOp(op);
    return crv;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Asynchronously queries a Couchbase view and returns the result.
 * The result can be accessed row-wise via an iterator. This
 * type of query will return the view result but will not
 * get the documents associated with each row of the query.
 *
 * @param view the view to run the query against.
 * @param query the type of query to run against the view.
 * @return a Future containing the results of the query.
 *///w  w  w .  j a  va 2s  .  c  o  m
private HttpFuture<ViewResponse> asyncQueryAndExcludeDocs(AbstractView view, Query query) {
    String uri = view.getURI() + query.toString();
    final CountDownLatch couchLatch = new CountDownLatch(1);
    int timeout = ((CouchbaseConnectionFactory) connFactory).getViewTimeout();
    final HttpFuture<ViewResponse> crv = new HttpFuture<ViewResponse>(couchLatch, timeout);

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new NoDocsOperationImpl(request, view, new ViewCallback() {
        private ViewResponse vr = null;

        @Override
        public void receivedStatus(OperationStatus status) {
            crv.set(vr, status);
        }

        @Override
        public void complete() {
            couchLatch.countDown();
        }

        @Override
        public void gotData(ViewResponse response) {
            vr = response;
        }
    });
    crv.setOperation(op);
    addOp(op);
    return crv;
}

From source file:com.couchbase.client.CouchbaseClient.java

/**
 * Asynchronously queries a Couchbase view and returns the result.
 * The result can be accessed row-wise via an iterator.
 *
 * @param view the view to run the query against.
 * @param query the type of query to run against the view.
 * @return a Future containing the results of the query.
 */// www.jav a  2  s  .c  om
private HttpFuture<ViewResponse> asyncQueryAndReduce(final AbstractView view, final Query query) {
    if (!view.hasReduce()) {
        throw new RuntimeException("This view doesn't contain a reduce function");
    }
    String uri = view.getURI() + query.toString();
    final CountDownLatch couchLatch = new CountDownLatch(1);
    int timeout = ((CouchbaseConnectionFactory) connFactory).getViewTimeout();
    final HttpFuture<ViewResponse> crv = new HttpFuture<ViewResponse>(couchLatch, timeout);

    final HttpRequest request = new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
    final HttpOperation op = new ReducedOperationImpl(request, view, new ViewCallback() {
        private ViewResponse vr = null;

        @Override
        public void receivedStatus(OperationStatus status) {
            crv.set(vr, status);
        }

        @Override
        public void complete() {
            couchLatch.countDown();
        }

        @Override
        public void gotData(ViewResponse response) {
            vr = response;
        }
    });
    crv.setOperation(op);
    addOp(op);
    return crv;
}

From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java

/**
 * Creates the CONNECT request for tunnelling.
 * Called by {@link #createTunnelToTarget createTunnelToTarget}.
 *
 * @param route     the route to establish
 * @param context   the context for request execution
 *
 * @return  the CONNECT request for tunnelling
 *//*from   ww  w  . j av a2 s .c  om*/
protected HttpRequest createConnectRequest(HttpRoute route, HttpContext context) {
    // see RFC 2817, section 5.2 and
    // INTERNET-DRAFT: Tunneling TCP based protocols through
    // Web proxy servers

    HttpHost target = route.getTargetHost();

    String host = target.getHostName();
    int port = target.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
        port = scheme.getDefaultPort();
    }

    StringBuilder buffer = new StringBuilder(host.length() + 6);
    buffer.append(host);
    buffer.append(':');
    buffer.append(Integer.toString(port));

    String authority = buffer.toString();
    ProtocolVersion ver = HttpProtocolParams.getVersion(params);
    HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);

    return req;
}

From source file:org.apache.http.impl.client.DefaultRequestDirector.java

/**
 * Creates the CONNECT request for tunnelling.
 * Called by {@link #createTunnelToTarget createTunnelToTarget}.
 *
 * @param route     the route to establish
 * @param context   the context for request execution
 *
 * @return  the CONNECT request for tunnelling
 *///from w ww  .  ja  v  a  2s . com
protected HttpRequest createConnectRequest(final HttpRoute route, final HttpContext context) {
    // see RFC 2817, section 5.2 and
    // INTERNET-DRAFT: Tunneling TCP based protocols through
    // Web proxy servers

    final HttpHost target = route.getTargetHost();

    final String host = target.getHostName();
    int port = target.getPort();
    if (port < 0) {
        final Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
        port = scheme.getDefaultPort();
    }

    final StringBuilder buffer = new StringBuilder(host.length() + 6);
    buffer.append(host);
    buffer.append(':');
    buffer.append(Integer.toString(port));

    final String authority = buffer.toString();
    final ProtocolVersion ver = HttpProtocolParams.getVersion(params);
    final HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);

    return req;
}