Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpHead


    public boolean isCDNEnabled(String container) throws IOException, HttpException, FilesException
    {
      if (isLoggedin()) {
        if (isValidContainerName(container))
        {
          HttpHead method = null;
          try {
            method= new HttpHead(getCdnManagementURL()+"/"+sanitizeForURI(container));
            method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
            method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
            FilesResponse response = new FilesResponse(client.execute(method));

            if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
              method.abort();
              if(login()) {
                method= new HttpHead(getCdnManagementURL()+"/"+sanitizeForURI(container));
                method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
                method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
                response = new FilesResponse(client.execute(method));
              }
              else {
                throw new FilesAuthorizationException("Re-login failed", response.getResponseHeaders(), response.getStatusLine());
              }
            }

            if (response.getStatusCode() == HttpStatus.SC_NO_CONTENT)
            {
               for (Header hdr : response.getResponseHeaders()) {
                String name = hdr.getName().toLowerCase();
                if ("x-cdn-enabled".equals(name)) {
                   return Boolean.valueOf(hdr.getValue());
                }
              }
               throw new FilesException("Server did not return X-CDN-Enabled header: ", response.getResponseHeaders(), response.getStatusLine());
            }
            else if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
              logger.warn("Unauthorized access");
              throw new FilesAuthorizationException("User not Authorized!",response.getResponseHeaders(), response.getStatusLine());
            }
               else if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
               return false;
            }
            else {
              throw new FilesException("Unexpected result from server: ", response.getResponseHeaders(), response.getStatusLine());
            }
          }
          finally {
            if (method != null) {
              method.abort();
            }
          }
        }
        else
        {
View Full Code Here


      FilesObjectMetaData metaData;
      if (this.isLoggedin())
      {
        if (isValidContainerName(container) && isValidObjectName(objName))
        {
          HttpHead method = new HttpHead(getStorageURL()+"/"+sanitizeForURI(container)+"/"+sanitizeForURI(objName));
          try {
            method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
            method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
            FilesResponse response = new FilesResponse(client.execute(method));
          
                 if (response.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                   method.abort();
                login();
                   method.getParams().setIntParameter("http.socket.timeout", connectionTimeOut);
                method.setHeader(FilesConstants.X_AUTH_TOKEN, authToken);
                response = new FilesResponse(client.execute(method));
              }

                 if (response.getStatusCode() == HttpStatus.SC_NO_CONTENT ||
                     response.getStatusCode() == HttpStatus.SC_OK)
            {
              logger.debug ("Object metadata retreived  : "+objName);
              String mimeType = response.getContentType();
              String lastModified = response.getLastModified();
              String eTag = response.getETag();
              String contentLength = response.getContentLength();

              metaData = new FilesObjectMetaData(mimeType, contentLength, eTag, lastModified);

              Header [] headers = response.getResponseHeaders();
              HashMap<String,String> headerMap = new HashMap<String,String>();

              for (Header h: headers)
              {
                if ( h.getName().startsWith(FilesConstants.X_OBJECT_META) )
                {
                  headerMap.put(h.getName().substring(FilesConstants.X_OBJECT_META.length()), unencodeURI(h.getValue()));
                }
              }
              if (headerMap.size() > 0)
                metaData.setMetaData(headerMap);

              return metaData;
            }
            else if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND)
            {
              throw new FilesNotFoundException("Container: " + container + " did not have object " + objName,
                 response.getResponseHeaders(), response.getStatusLine());
            }
            else {
                throw new FilesException("Unexpected Return Code from Server",
                    response.getResponseHeaders(), response.getStatusLine());
            }
          }
          finally {
            method.abort();
          }
        }
        else
        {
          if (!isValidObjectName(objName)) {
View Full Code Here

            } else if (method.equals(HTTP_DELETE)) {
                httpMethod = new HttpDelete(endpointURL);
            } else if (method.equals(HTTP_OPTIONS)) {
                httpMethod = new HttpOptions(endpointURL);
            } else if (method.equals(HTTP_HEAD)) {
                httpMethod = new HttpHead(endpointURL);
            } else {
                httpMethod = new HttpGet(endpointURL);
            }
            response = execute(httpMethod);
        } catch (UnsupportedEncodingException e) {
View Full Code Here

        final String revision = dbInstance.execute(new HttpCall<String>() {
            @Override
            public HttpRequest getRequest() throws URISyntaxException,
                    IOException {
                return new HttpHead("/" + dbName + "/_design/" + docId);
            }

            @Override
            public String doWithResponse(HttpResponse response)
                    throws IOException {
View Full Code Here

    public String getLastRevision(final String id) {
        return dbInstance.execute(new HttpCall<String>() {
            @Override
            public HttpRequest getRequest() throws URISyntaxException,
                    IOException {
                return new HttpHead(buildUri("/" + dbName + "/" + id));
            }

            @Override
            public String doWithResponse(HttpResponse response)
                    throws IOException {
View Full Code Here

    private boolean resourceExists( int wait, String resourceName )
        throws TransferFailedException, AuthorizationException
    {
        String repositoryUrl = getRepository().getUrl();
        String url = repositoryUrl + ( repositoryUrl.endsWith( "/" ) ? "" : "/" ) + resourceName;
        HttpHead headMethod = new HttpHead( url );
        try
        {
            CloseableHttpResponse response = execute( headMethod );
            try
            {
View Full Code Here

        methodConfig.addParam("http.protocol.max-redirects", "%i," + maxRedirects);

        HttpConfiguration config = new HttpConfiguration();
        config.setAll(methodConfig);

        HttpHead method = new HttpHead();
        RequestConfig.Builder builder = RequestConfig.custom();
        ConfigurationUtils.copyConfig( config.getMethodConfiguration( method ), builder );
        RequestConfig requestConfig = builder.build();

        assertEquals(2, requestConfig.getMaxRedirects());
View Full Code Here

        config.setAll( new HttpMethodConfiguration() );

        TestWagon wagon = new TestWagon();
        wagon.setHttpConfiguration( config );

        HttpHead method = new HttpHead();
        wagon.setHeaders( method );

        // these are the default headers.
        // method.addRequestHeader( "Cache-control", "no-cache" );
        // method.addRequestHeader( "Cache-store", "no-store" );
        // method.addRequestHeader( "Pragma", "no-cache" );
        // method.addRequestHeader( "Expires", "0" );
        // method.addRequestHeader( "Accept-Encoding", "gzip" );

        Header header = method.getFirstHeader( "Cache-control" );
        assertNotNull( header );
        assertEquals( "no-cache", header.getValue() );

        header = method.getFirstHeader( "Cache-store" );
        assertNotNull( header );
        assertEquals( "no-store", header.getValue() );

        header = method.getFirstHeader( "Pragma" );
        assertNotNull( header );
        assertEquals( "no-cache", header.getValue() );

        header = method.getFirstHeader( "Expires" );
        assertNotNull( header );
        assertEquals( "0", header.getValue() );

        header = method.getFirstHeader( "Accept-Encoding" );
        assertNotNull( header );
        assertEquals( "gzip", header.getValue() );
    }
View Full Code Here

        config.setAll( new HttpMethodConfiguration().setUseDefaultHeaders( false ) );

        TestWagon wagon = new TestWagon();
        wagon.setHttpConfiguration( config );

        HttpHead method = new HttpHead();
        wagon.setHeaders( method );

        // these are the default headers.
        // method.addRequestHeader( "Cache-control", "no-cache" );
        // method.addRequestHeader( "Cache-store", "no-store" );
        // method.addRequestHeader( "Pragma", "no-cache" );
        // method.addRequestHeader( "Expires", "0" );
        // method.addRequestHeader( "Accept-Encoding", "gzip" );

        Header header = method.getFirstHeader( "Cache-control" );
        assertNull( header );

        header = method.getFirstHeader( "Cache-store" );
        assertNull( header );

        header = method.getFirstHeader( "Pragma" );
        assertNull( header );

        header = method.getFirstHeader( "Expires" );
        assertNull( header );

        header = method.getFirstHeader( "Accept-Encoding" );
        assertNull( header );
    }
View Full Code Here

    @Test
    public void sendHttpHead() throws IOException {
        connection = null;
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        HttpHead head = new HttpHead(DefaultServer.getDefaultServerURL() + "/path");
        TestHttpClient client = new TestHttpClient();
        try {
            generateMessage(1);
            HttpResponse result = client.execute(get);
            Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpHead

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.