Package org.apache.http.client.fluent

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


    @Test
    public void testAuthenticationWithAuthenticableAndCorrectContext() throws Exception {
        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
                "foo", "bar");
        Executor authenticable = Executor.newInstance();
        TransportAuthenticationContext context = new TransportAuthenticationContext();
        context.addAttribute("endpoint", new ReplicationEndpoint("http://www.apache.org"));
        authenticationHandler.authenticate(authenticable, context);
    }
View Full Code Here


    @Override
    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

        executeQuery("sm:chgrp(xs:anyURI('" + resourceUri + "'), '" + group_gid + "')", uid, pwd);
    }

    @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

        executeQuery("xmldb:create-group('" + group_gid + "', '" + uid + "')", uid, pwd);
    }

    @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

      // demo2: 获取图片, 增加超时设定。
      byte[] resultBytes = Request.Get(contentUrl).connectTimeout(TIMEOUT_SECONDS * 1000)
          .socketTimeout(TIMEOUT_SECONDS * 1000).execute().returnContent().asBytes();

      // demo3: 获取图片,使用之前设置好了的自定义连接池与超时的httpClient
      Executor executor = Executor.newInstance(httpClient);
      String resultString2 = executor.execute(Request.Get(contentUrl)).returnContent().asString();
    } catch (HttpResponseException e) {
      logger.error("Status code:" + e.getStatusCode(), 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.