Examples of GetMethod


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

   {
      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

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

   }

   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

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

   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

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

  
   @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

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

    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

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

          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

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

    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

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

   }
  
   private void performCustomAuth(String headerId, Cookie cookie,
         String usecase) throws Exception
   {
      GetMethod indexGet = new GetMethod(baseURLNoAuth+path);
      indexGet.addRequestHeader(headerId, "jduke");
      httpConn.getState().addCookie(cookie);
      int responseCode = httpConn.executeMethod(indexGet);
      String response = indexGet.getStatusText();
      log.debug("Response from " + usecase + " case:"+response);
      Header jex = indexGet.getResponseHeader("X-JException");
      log.debug("Saw X-JException, "+jex);
      assertNull("X-JException == null", jex);
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
   }
View Full Code Here

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

   }
  
   private PostMethod doSecureGetWithLogin(String path, String username, String password)
   throws Exception
   {
      GetMethod indexGet = new GetMethod(baseURLNoAuth+path);
      int responseCode = httpConn.executeMethod(indexGet);
      String body = indexGet.getResponseBodyAsString();
      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
      assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );

      HttpState state = httpConn.getState();
      Cookie[] cookies = state.getCookies();
      String sessionID = null;
      for(int c = 0; c < cookies.length; c ++)
      {
         Cookie k = cookies[c];
         if( k.getName().equalsIgnoreCase("JSESSIONID") )
            sessionID = k.getValue();
      }
      getLog().debug("Saw JSESSIONID="+sessionID);

      // Submit the login form
      PostMethod formPost = new PostMethod(baseURLNoAuth+"header-form-auth/j_security_check");
      formPost.addRequestHeader("Referer", baseURLNoAuth+"header-form-auth/restricted/login.html");
      formPost.addParameter("j_username", username);
      formPost.addParameter("j_password", password);
      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
            formPost, state);
      String response = formPost.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);

      //  Follow the redirect to the SecureServlet
      Header location = formPost.getResponseHeader("Location");
      String indexURI = location.getValue();
      GetMethod war1Index = new GetMethod(indexURI);
      responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
            war1Index, state);
      response = war1Index.getStatusText();
      log.debug("responseCode="+responseCode+", response="+response);
      assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
      body = war1Index.getResponseBodyAsString();
      if( body.indexOf("j_security_check") > 0 )
         fail("get of "+indexURI+" redirected to login page");
      return formPost;
   }
View Full Code Here

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

   public void testHeaderBasedAuthentication() throws Exception
   {
      String location = baseURLNoAuth + "header-auth/index.jsp";
      int responseCode = 0;
      HttpClient httpConn = new HttpClient();
      GetMethod indexGet = null;
      try
      {
         indexGet = new GetMethod(location);
         indexGet.setFollowRedirects(false);
         responseCode = httpConn.executeMethod(indexGet);
         assertEquals(HttpURLConnection.HTTP_FORBIDDEN, responseCode);
      }
      finally
      {
         indexGet.releaseConnection();
      }
      indexGet = null;
      try
      {
         indexGet = new GetMethod(location);
         indexGet.setFollowRedirects(false);
         // Add the request headers
         indexGet.addRequestHeader("JBOSS_TEST_USER_NAME", "jduke");
         indexGet.addRequestHeader("JBOSS_TEST_CREDENTIAL", "theduke");
         responseCode = httpConn.executeMethod(indexGet);
         assertEquals(HttpURLConnection.HTTP_OK, responseCode);
      }
      finally
      {
         indexGet.releaseConnection();
      }
   }
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.