Examples of HttpMethodBase


Examples of com.dotcms.repackage.org.apache.commons.httpclient.HttpMethodBase

    }

    public synchronized void get(String url, StreamReceiver receiver, List<Range> rangeList, ProgressListener listener) throws com.ettrema.httpclient.HttpException, Utils.CancelledException, NotAuthorizedException, BadRequestException, ConflictException, NotFoundException {
        LogUtils.trace(log, "get: ", url);
        notifyStartRequest();
        HttpMethodBase m;
        if (rangeList != null) {
            m = new RangedGetMethod(url, rangeList);
        } else {
            m = new GetMethod(url);
        }
        InputStream in = null;
        NotifyingFileInputStream nin = null;
        try {
            int res = client.executeMethod(m);
            Utils.processResultCode(res, url);
            in = m.getResponseBodyAsStream();
            nin = new NotifyingFileInputStream(in, m.getResponseContentLength(), url, listener);
            receiver.receive(nin);
        } catch (com.dotcms.repackage.org.apache.commons.httpclient.HttpException ex) {
            m.abort();
            throw new GenericHttpException(ex.getReasonCode(), url);
        } catch (Utils.CancelledException ex) {
            m.abort();
            throw ex;
        } catch (IOException ex) {
            m.abort();
            throw new RuntimeException(ex);
        } finally {
            Utils.close(in);
            m.releaseConnection();
            notifyFinishRequest();
        }
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

    }
  }

  public HTTPRequest head() {
    // FIXME: Allow HEAD request to send a message body?
    HttpMethodBase method = new PostMethod(url) {

      @Override
      public String getName() {
        return "HEAD";
      }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

    return new HTTPRequest(this, method);
  }

  public HTTPRequest get() {
    // FIXME: Allow GET request to send a message body?
    HttpMethodBase method = new PostMethod(url) {

      @Override
      public String getName() {
        return "GET";
      }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

    /* Init Client */
    HttpClient client = initClient(properties);

    /* Init the connection */
    HttpMethodBase method = null;
    InputStream inS = null;
    try {

      /* Create Method (GET or POST) */
      method = initConnection(link, properties);

      /* Proxy if required */
      setupProxy(link, client);

      /* Authentication if required */
      setupAuthentication(authLink, authRealm, client, method);

      /* Open the connection */
      inS = openConnection(client, method);

      /* Try to pipe the resulting stream into a GZipInputStream */
      if (inS != null)
        inS = pipeStream(inS, method);
    } catch (IOException e) {
      throw new ConnectionException(Activator.getDefault().createErrorStatus(e.getMessage(), e));
    }

    /* In case authentication required / failed */
    if (method.getStatusCode() == HTTP_ERROR_AUTH_REQUIRED) {
      AuthState hostAuthState = method.getHostAuthState();
      throw new AuthenticationRequiredException(hostAuthState != null ? hostAuthState.getRealm() : null, Activator.getDefault().createErrorStatus(Messages.DefaultProtocolHandler_ERROR_AUTHENTICATION_REQUIRED, null));
    }

    /* In case proxy-authentication required / failed */
    if (method.getStatusCode() == HTTP_ERROR_PROXY_AUTH_REQUIRED)
      throw new ProxyAuthenticationRequiredException(Activator.getDefault().createErrorStatus(Messages.DefaultProtocolHandler_ERROR_PROXY_AUTHENTICATION_REQUIRED, null));

    /* If status code is 4xx, throw an IOException with the status code included */
    if (method.getStatusCode() >= HTTP_ERRORS) {
      String error = getError(method.getStatusCode());
      if (error != null)
        throw new ConnectionException(Activator.getDefault().createErrorStatus(NLS.bind(Messages.DefaultProtocolHandler_ERROR_HTTP_STATUS_MSG, String.valueOf(method.getStatusCode()), error), null));

      throw new ConnectionException(Activator.getDefault().createErrorStatus(NLS.bind(Messages.DefaultProtocolHandler_ERROR_HTTP_STATUS, String.valueOf(method.getStatusCode())), null));
    }

    /* In case the Feed has not been modified since */
    if (method.getStatusCode() == HTTP_STATUS_NOT_MODIFIED)
      throw new NotModifiedException(Activator.getDefault().createInfoStatus(Messages.DefaultProtocolHandler_INFO_NOT_MODIFIED_SINCE, null));

    /* In case response body is not available */
    if (inS == null)
      throw new ConnectionException(Activator.getDefault().createErrorStatus(Messages.DefaultProtocolHandler_ERROR_STREAM_UNAVAILABLE, null));
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

  }

  private HttpMethodBase initConnection(URI link, Map<Object, Object> properties) throws IOException {

    /* Create the Method. Wrap any RuntimeException into an IOException */
    HttpMethodBase method = null;
    try {
      if (properties != null && properties.containsKey(IConnectionPropertyConstants.POST))
        method = new PostMethod(link.toString());
      else
        method = new GetMethod(link.toString());
    } catch (RuntimeException e) {
      throw new IOException(e.getMessage());
    }

    /* Ignore Cookies */
    if (method instanceof GetMethod)
      method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);

    /* Set Headers */
    setHeaders(properties, method);

    /* Follow Redirects */
    if (method instanceof GetMethod)
      method.setFollowRedirects(true);

    return method;
  }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

            + "&array=1,2,3,4,5,6,7,8,9,10");
      try
      {
         deploy("staticarray.sar");
         // Set the static array value to a non-default from war1
         HttpMethodBase request = HttpUtils.accessURL(url);
         Header errors = request.getResponseHeader("X-Error");
         log.info("war1 X-Error: "+errors);
         assertTrue("war1 X-Error("+errors+") is null", errors == null);
         // Validate that war2 sees the changed values
         url = new URL(baseURL+"staticarray-web2/validate.jsp"
               + "?Sequencer.info.expected=1,2,3,4,5,6,7,8,9,10");
         request = HttpUtils.accessURL(url);
         errors = request.getResponseHeader("X-Error");
         log.info("war2 X-Error: "+errors);
         assertTrue("war2 X-Error("+errors+") is null", errors == null);
        
      }
      catch(Exception e)
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

   }
  
   private String accessURL(String url) throws Exception
   {
      HttpClient httpConn = new HttpClient();
      HttpMethodBase request = new GetMethod(baseURL + url);
      log.debug("RequestURI: " + request.getURI());
      int responseCode = httpConn.executeMethod(request);
      String response = request.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      String content = request.getResponseBodyAsString();
      log.debug(content);
      assertEquals(HttpURLConnection.HTTP_OK, responseCode);
      return content;
   }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

   /**
    *  Access the passed URL and return back the response
    */
   private String getResponse(String url) throws Exception
   {
      HttpMethodBase request = new GetMethod(url);
      client.executeMethod(request);

      String responseBody = request.getResponseBodyAsString();
      if (responseBody == null)
      {
         throw new Exception("Unable to get response from server for URL: " + url);
      }

View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

   public static HttpMethodBase accessURL(URL url, String realm,
      int expectedHttpCode, Header[] hdrs, int type)
      throws Exception
   {
      HttpClient httpConn = new HttpClient();
      HttpMethodBase request = createMethod(url, type);
      int hdrCount = hdrs != null ? hdrs.length : 0;
      for(int n = 0; n < hdrCount; n ++)
         request.addRequestHeader(hdrs[n]);
      try
      {
         log.debug("Connecting to: "+url);
         String userInfo = url.getUserInfo();
         if( userInfo != null )
         {
            UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo);
            httpConn.getState().setCredentials(realm, url.getHost(), auth);
         }
         log.debug("RequestURI: "+request.getURI());
         int responseCode = httpConn.executeMethod(request);
         String response = request.getStatusText();
         log.debug("responseCode="+responseCode+", response="+response);
         String content = request.getResponseBodyAsString();
         log.debug(content);
         // Validate that we are seeing the requested response code
         if( responseCode != expectedHttpCode )
         {
            throw new IOException("Expected reply code:"+expectedHttpCode
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

      return request;
   }

   public static HttpMethodBase createMethod(URL url, int type)
   {
      HttpMethodBase request = null;
      switch( type )
      {
         case GET:
            request = new GetMethod(url.toString());
            break;
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.