Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.GetMethod


   }
  
   protected void makeWebRequest(String url, String responseContent)
   {
      HttpClient client = new HttpClient();
      GetMethod method = new GetMethod(url);
      int responseCode = 0;
      try
      {
         responseCode = client.executeMethod(method);
        
         assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
               , responseCode == HttpURLConnection.HTTP_OK);
        
         InputStream rs = method.getResponseBodyAsStream();
         InputStreamReader reader = new InputStreamReader(rs);
         StringWriter writer = new StringWriter();
         int c;
         while ((c = reader.read())  != -1)
            writer.write(c);
        
         String rsp = writer.toString();
        
         assertTrue("Response contains " + responseContent, rsp.indexOf(responseContent) >= 0);
      }
      catch (IOException e)
      {
         e.printStackTrace();
         fail("HttpClient executeMethod fails." +e.toString());
      }
      finally
      {
         method.releaseConnection();
      }
   }
View Full Code Here


   /**
    *  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

   }
  
   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

   {
      HttpMethodBase request = null;
      switch( type )
      {
         case GET:
            request = new GetMethod(url.toString());
            break;
         case POST:
            request = new PostMethod(url.toString());
            break;
         case HEAD:
View Full Code Here

   }

   public 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

   private HttpClient client = new HttpClient();
   public static final String BASE_URI = "http://localhost:8080/resteasy-cdi/";
  
   public void testPlainTextReadonlyResource(String uri, String body)
   {
      GetMethod get = new GetMethod(uri);
      get.addRequestHeader("Accept", "text/plain");
      try
      {
         int status = client.executeMethod(get);
         assertEquals(200, status);
         assertTrue(get.getResponseBodyAsString().contains(body));
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
      }
      finally
      {
         get.releaseConnection();
      }
   }
View Full Code Here

  
   @Test
   public void testTheSameInstanceIsUsedForEveryRequest()
   {
      HttpClient client = new HttpClient();
      GetMethod get1 = new GetMethod(BASE_URI + getTestPrefix());
      get1.addRequestHeader("Accept", "text/plain");
      GetMethod get2 = new GetMethod(BASE_URI + getTestPrefix());
      get2.addRequestHeader("Accept", "text/plain");
      try
      {
         int status1 = client.executeMethod(get1);
         assertEquals(status1, 200);
         String response1 = get1.getResponseBodyAsString();
         get1.releaseConnection();
         int status2 = client.executeMethod(get2);
         assertEquals(status2, 200);
         String response2 = get2.getResponseBodyAsString();
         get2.releaseConnection();
         assertEquals(response1, response2);
      }
      catch (Exception e)
      {
         throw new RuntimeException(e);
View Full Code Here

    return "v";
  }

  private InputStream retreiveXMLReply(String partOfSpeech, String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair posValues = new NameValuePair(PART_OF_SPEECH_PARAM, partOfSpeech);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebug()) {
      String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + PART_OF_SPEECH_PARAM + "=" + partOfSpeech + "&" + GLOSS_TERM_PARAM + "=" + word;
      log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { posValues, wordValues });
    try {
      client.executeMethod(method);
      int status = method.getStatusCode();
      if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
        if (log.isDebug()) {
          log.debug("got a valid reply!");
        }
      } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString());
      } else {
        log.error("Unexpected HTTP Status::" + method.getStatusLine().toString());
      }
    } catch (Exception e) {
      log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
      // error
      log.error("URL not found!");
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
View Full Code Here

          authentication.getPassword());
      client.getState().setCredentials(authentication.getRealm(), parseDomain(url), credentials);
    }

    // Create the GET method with the correct URL:
    GetMethod get = new GetMethod(url);
    get.setDoAuthentication(true);

    // Execute the GET:
    client.executeMethod(get);

    return new WmsHttpServiceStream(get);
View Full Code Here

    public ImageResult call() throws Exception {
      log.debug("Fetching image: {}", result.getRasterImage().getUrl());
      int triesLeft = retries;
      while (true) {
        try {
          GetMethod get = new GetMethod(result.getRasterImage().getUrl());
          httpClient.executeMethod(get);
          InputStream inputStream = get.getResponseBodyAsStream();
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
          byte[] bytes = new byte[1024];
          int readBytes;
          while ((readBytes = inputStream.read(bytes)) > 0) {
            outputStream.write(bytes, 0, readBytes);
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.GetMethod

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.