Package org.apache.http.client.methods

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


    } else if (request.getHttpMethod() == HttpMethodName.GET) {
      httpRequest = new HttpGet(uri);
    } else if (request.getHttpMethod() == HttpMethodName.DELETE) {
      httpRequest = new HttpDelete(uri);
    } else if (request.getHttpMethod() == HttpMethodName.HEAD) {
      httpRequest = new HttpHead(uri);
    } else {
      throw new AmazonClientException("Unknown HTTP method name: " + request.getHttpMethod());
    }

    configureHeaders(httpRequest, request, context, clientConfiguration);
View Full Code Here


            if (method.equals(HTTPConstants.POST)) {
                httpRequest = new HttpPost(uri);
            } else if (method.equals(HTTPConstants.PUT)) {
                httpRequest = new HttpPut(uri);
            } else if (method.equals(HTTPConstants.HEAD)) {
                httpRequest = new HttpHead(uri);
            } else if (method.equals(HTTPConstants.TRACE)) {
                httpRequest = new HttpTrace(uri);
            } else if (method.equals(HTTPConstants.OPTIONS)) {
                httpRequest = new HttpOptions(uri);
            } else if (method.equals(HTTPConstants.DELETE)) {
View Full Code Here

        return method;
    }

    private HttpHead doHead() {
        HttpHead method = new HttpHead(requestURI);

        for (Header header : headers) {
            method.addHeader(header);
        }

        return method;
    }
View Full Code Here

    URI baseURI = URI.create(base);
    final URI uri = baseURI.resolve(href);
    String sch = uri.getScheme();
    if ("http".equalsIgnoreCase(sch) || "https".equalsIgnoreCase(sch)) {
      final HttpContext localContext = new BasicHttpContext();
      HttpHead head = new HttpHead(uri);
      head.setHeader("Accept", accept);
      execute(head, new ResponseHandler<Void>() {
        public Void handleResponse(HttpResponse response)
            throws IOException {
          URI contentId = getContentId(localContext);
          HttpEntity entity = response.getEntity();
View Full Code Here

    private String waitForHttp(URI uri) {
        SystemDefaultHttpClient client = new SystemDefaultHttpClient();
        client.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(3, false));
        HttpContext localContext = new BasicHttpContext();
        HttpUriRequest httpRequest = new HttpHead(uri);
        HttpResponse httpResponse = null;

        httpResponse = head(client, httpRequest, localContext);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        String date = null;
View Full Code Here

        this.shellHttpClient = shellHttpClient;
    }

    @SuppressWarnings("unused")
    public HttpCommandResponse execute(String url) throws IOException {
        return new HttpCommandResponse(shellHttpClient.getHttpClient().execute(new HttpHead(url)));
    }
View Full Code Here

                request = new HttpPost(_baseAddress);
                ((HttpPost) request).setEntity(new InputStreamEntity(httpRequest.getBodyBytes(), httpRequest.getBodyBytes().available()));
            } else if (_httpMethod.equals(HTTP_DELETE)) {
                request = new HttpDelete(_baseAddress);
            } else if (_httpMethod.equals(HTTP_HEAD)) {
                request = new HttpHead(_baseAddress);
            } else if (_httpMethod.equals(HTTP_PUT)) {
                request = new HttpPut(_baseAddress);
                ((HttpPut) request).setEntity(new InputStreamEntity(httpRequest.getBodyBytes(), httpRequest.getBodyBytes().available()));
            } else if (_httpMethod.equals(HTTP_OPTIONS)) {
                request = new HttpOptions(_baseAddress);
View Full Code Here

     * @throws FilesAuthorizationException The client's login was invalid.
     */
   public FilesAccountInfo getAccountInfo() throws IOException, HttpException, FilesAuthorizationException, FilesException
   {
      if (this.isLoggedin()) {
        HttpHead method = null;

        try {
          method = new HttpHead(getStorageURL());
          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.removeHeaders(FilesConstants.X_AUTH_TOKEN);
            if(login()) {
              method.abort();
              method = new HttpHead(getStorageURL());
              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)
          {
            int nContainers = response.getAccountContainerCount();
            long totalSize  = response.getAccountBytesUsed();
            return new FilesAccountInfo(totalSize,nContainers);
          }
          else {
            throw new FilesException("Unexpected return from server", response.getResponseHeaders(), response.getStatusLine());
          }
        }
        finally {
          if (method != null) method.abort();
        }
      }
      else {
           throw new FilesAuthorizationException("You must be logged in", null, null);
      }
View Full Code Here

      if (this.isLoggedin())
      {
        if (isValidContainerName(container))
        {

          HttpHead method = null;
          try {
            method = new HttpHead(getStorageURL()+"/"+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.removeHeaders(FilesConstants.X_AUTH_TOKEN);
              if(login()) {
                method = new HttpHead(getStorageURL()+"/"+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)
            {
              int objCount = response.getContainerObjectCount();
              long objSize  = response.getContainerBytesUsed();
              return new FilesContainerInfo(container, objCount,objSize);
            }
            else if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND)
            {
              throw new FilesNotFoundException("Container not found: " + container, response.getResponseHeaders(), response.getStatusLine());
            }
            else {
              throw new FilesException("Unexpected result from server", response.getResponseHeaders(), response.getStatusLine());
            }
          }
          finally {
            if (method != null) method.abort();
          }
        }
        else
        {
          throw new FilesInvalidNameException(container);
View Full Code Here

    public FilesCDNContainer getCDNContainerInfo(String container) throws IOException, FilesNotFoundException, 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)
            {
              FilesCDNContainer result = new FilesCDNContainer(response.getCdnUrl());
              result.setName(container);
              result.setSSLURL(response.getCdnSslUrl());
              result.setStreamingURL(response.getCdnStreamingUrl());
              for (Header hdr : response.getResponseHeaders()) {
                String name = hdr.getName().toLowerCase();
                if ("x-cdn-enabled".equals(name)) {
                  result.setEnabled(Boolean.valueOf(hdr.getValue()));
                }
                else if ("x-log-retention".equals(name)) {
                  result.setRetainLogs(Boolean.valueOf(hdr.getValue()));
                }
                else if ("x-ttl".equals(name)) {
                  result.setTtl(Integer.parseInt(hdr.getValue()));
                }
                else if ("x-referrer-acl".equals(name)) {
                  result.setReferrerACL(hdr.getValue());
                }
                else if ("x-user-agent-acl".equals(name)) {
                  result.setUserAgentACL(hdr.getValue());
                }
              }
              return result;
            }
            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) {
               throw new FilesNotFoundException("Container is not CDN enabled",response.getResponseHeaders(), response.getStatusLine());
            }
            else {
              throw new FilesException("Unexpected result from server: ", response.getResponseHeaders(), response.getStatusLine());
            }
          }
          finally {
            if (method != null) {
              method.abort();
            }
          }
        }
        else
        {
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.