Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpMethod


      // Use an HttpClient to fetch a profile information page from MSN.
      HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
      HttpClientParams httpClientParams = httpClient.getParams();
      httpClientParams.setConnectionManagerTimeout(2500);
      httpClient.setParams(httpClientParams);
      HttpMethod httpMethod = new GetMethod(MSN_NAME_VALIDATION_URL);
      NameValuePair idParam = new NameValuePair(MSN_NAME_URL_PARAMETER, textElement.getValue());
      httpMethod.setQueryString(new NameValuePair[] {idParam});
      // Don't allow redirects since otherwise, we won't be able to get the correct status
      httpMethod.setFollowRedirects(false);
      try {
        // Get the user profile page
        httpClient.executeMethod(httpMethod);
        int httpStatusCode = httpMethod.getStatusCode();
        // Looking at the HTTP status code tells us whether a user with the given MSN name exists.
        if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
          // If the user exists, we get a 301...
          result = true;
        } else if (httpStatusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
View Full Code Here


      // Use an HttpClient to fetch a profile information page from ICQ.
      HttpClient httpClient = HttpClientFactory.getHttpClientInstance();
      HttpClientParams httpClientParams = httpClient.getParams();
      httpClientParams.setConnectionManagerTimeout(2500);
      httpClient.setParams(httpClientParams);
      HttpMethod httpMethod = new GetMethod(ICQ_NAME_VALIDATION_URL);
      NameValuePair uinParam = new NameValuePair(ICQ_NAME_URL_PARAMETER, textElement.getValue());
      httpMethod.setQueryString(new NameValuePair[] {uinParam});
      // Don't allow redirects since otherwise, we won't be able to get the HTTP 302 further down.
      httpMethod.setFollowRedirects(false);
      try {
        // Get the user profile page
        httpClient.executeMethod(httpMethod);
        int httpStatusCode = httpMethod.getStatusCode();
        // Looking at the HTTP status code tells us whether a user with the given ICQ name exists.
        if (httpStatusCode == HttpStatus.SC_OK) {
          // ICQ tells us that a user name is valid if it sends an HTTP 200...
          result = true;
        } else if (httpStatusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
View Full Code Here

   
    @Test
    public void testGetEcho() throws Exception {
        HttpClient httpClient = createClient();
        String url = "http://localhost:" + PORT + "/Echo/echo/echo/hello";
        HttpMethod method = null;
        method = new GetMethod(url);
        int status = httpClient.executeMethod(method);
        assertEquals(HttpStatus.SC_OK, status);
        String result = method.getResponseBodyAsString();
        assertTrue(result.contains("hello"));
        method.releaseConnection();
       
        httpClient = createClient();
        url = "http://localhost:" + PORT + "/Echo/echo/echo/hello?wsdl";
        method = new GetMethod(url);
        status = httpClient.executeMethod(method);
        assertEquals(HttpStatus.SC_OK, status);
        Document doc = StaxUtils.read(method.getResponseBodyAsStream());
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("xsd", "http://www.w3.org/2001/XMLSchema");
        NodeList nl = XPathAssert.assertValid("//xsd:element[@name='firstHeader']",
                                              doc.getDocumentElement(),
                                              ns);
View Full Code Here

    }
    @Test
    public void testGetEchoSimple() throws Exception {
        HttpClient httpClient = createClient();
        String url = "http://localhost:" + PORT + "/SimpleEcho/simpleEcho/string/hello";
        HttpMethod method = null;
        method = new GetMethod(url);
        int status = httpClient.executeMethod(method);
        assertEquals(HttpStatus.SC_OK, status);
        String result = method.getResponseBodyAsString();
        assertTrue(result.contains("hello"));
        method.releaseConnection();
    }
View Full Code Here

        String clearMessage =  "TestMessage2";
        final String message = topologyRequestValidator.encodeMessage(clearMessage);
        topologyRequestValidator.trustMessage(response, request, message);
       
        final HttpMethod method = context.mock(HttpMethod.class);
        context.checking(new Expectations(){
            {
                allowing(method).getResponseHeader(with(any(String.class)));
                will(new Action() {
                    public void describeTo(Description desc) {
View Full Code Here

        // simulate a browser request
        List<Header> headers = new ArrayList<Header>();
        headers.add(new Header("User-Agent", "Mozilla/5.0 Sling Integration Test"));

        HttpMethod post = assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check",
                HttpServletResponse.SC_MOVED_TEMPORARILY, params, headers, null);

        final String location = post.getResponseHeader("Location").getValue();
        assertNotNull(location);
        assertTrue(location.startsWith(HttpTest.HTTP_BASE_URL + "/system/sling/selector/login?"));
        assertTrue(location.contains("resource=%2F"));
        assertTrue(location.contains("j_reason=INVALID_CREDENTIALS"));
    }
View Full Code Here

    postParams.add(new NameValuePair(SlingPostConstants.RP_CHECKIN, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_REPLACE_PROPERTIES, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_AUTO_CHECKOUT, "true"));
    postParams.add(new NameValuePair(SlingPostConstants.RP_CONTENT, "{ \"abc\": \"def2\" }"));
    postParams.add(new NameValuePair(":http-equiv-accept", "application/json,*/*;q=0.9"));
        HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
       
        String responseBodyAsString = post.getResponseBodyAsString();
    JSONObject responseJSON = new JSONObject(responseBodyAsString);
        JSONArray changes = responseJSON.getJSONArray("changes");
        JSONObject checkoutChange = changes.getJSONObject(0);
        assertEquals("checkout", checkoutChange.getString("type"));
   
View Full Code Here

import org.apache.sling.commons.testing.integration.HttpTestBase;

public class FiltersTest extends HttpTestBase {

    public void testCounters() throws IOException {
        HttpMethod get = assertHttpStatus(HTTP_BASE_URL + "/index.html", HttpServletResponse.SC_OK);
        final String [] headers = {
            "FILTER_COUNTER_HTTPSERVICE",
            "FILTER_COUNTER_SLING",
            "FILTER_COUNTER_NOPROP"
        };
        for(String header : headers) {
            assertNotNull("Expecting header '" + header + "'", get.getResponseHeader(header));
            assertEquals("Expecting value 1 for header '" + header + "'", "1", get.getResponseHeader(header).getValue());
        }
    }
View Full Code Here

        List<Header> headers = new ArrayList<Header>();
        headers.add(new Header("X-Requested-With", "XMLHttpRequest"));
        headers.add(new Header("User-Agent", "Mozilla/5.0 Sling Integration Test"));

        HttpMethod post = assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check",
                HttpServletResponse.SC_FORBIDDEN, params, headers, null);
        assertNotNull(post.getResponseHeader("X-Reason"));
        assertEquals("Username and Password do not match", post.getResponseHeader("X-Reason").getValue());
    }
View Full Code Here

    public void testValidatingCorrectFormCredentials() throws Exception {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new NameValuePair("j_username", "admin"));
        params.add(new NameValuePair("j_password", "admin"));
        params.add(new NameValuePair("j_validate", "true"));
        HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_OK,
                params, null);
        assertTrue(post.getResponseBodyAsString().length() == 0);

        List<NameValuePair> params2 = new ArrayList<NameValuePair>();
        params2.add(new NameValuePair("j_validate", "true"));
        HttpMethod post2 = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_OK,
                params2, null);
        assertTrue(post2.getResponseBodyAsString().length() == 0);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpMethod

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.