Examples of HttpMethod


Examples of org.apache.commons.httpclient.HttpMethod

    tureq.setFirstName(firstName);
    tureq.setLastName(lastName);
    tureq.setUserName(userName);
    //}

    HttpMethod meth = fetch(tureq, httpClientInstance);
    if (meth == null) {
      setFetchError();
      return null;
    }

    Header responseHeader = meth.getResponseHeader("Content-Type");
    if (responseHeader == null) {
      setFetchError();
      return null;
    }

    String mimeType = responseHeader.getValue();
    if (mimeType != null && mimeType.startsWith("text/html")) {
      // we have html content, let doDispatch handle it for
      // inline rendering, update hreq for next content request
      String body;
      try {
        body = meth.getResponseBodyAsString();
      } catch (IOException e) {
        Tracing.logWarn("Problems when tunneling URL::" + tureq.getUri(), e, TunnelComponent.class);
        return null;
      }
      SimpleHtmlParser parser = new SimpleHtmlParser(body);
      if (!parser.isValidHtml()) { // this is not valid HTML, deliver
        // asynchronuous
        return new HttpRequestMediaResource(meth);
      }
      meth.releaseConnection();
      htmlHead = parser.getHtmlHead();
      jsOnLoad = parser.getJsOnLoad();
      htmlContent = parser.getHtmlContent();
      setDirty(true);
    } else return new HttpRequestMediaResource(meth); // this is a async browser
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

   */
  public HttpMethod fetch(TURequest tuReq, HttpClient client) {

    String modulePath = tuReq.getUri();

    HttpMethod meth = null;
    String method = tuReq.getMethod();
    if (method.equals("GET")) {
      GetMethod cmeth = new GetMethod(modulePath);
      String queryString = tuReq.getQueryString();
      if (queryString != null) cmeth.setQueryString(queryString);
      meth = cmeth;
      if (meth == null) return null;
      // if response is a redirect, follow it
      meth.setFollowRedirects(true);
     
    } else if (method.equals("POST")) {
      String type = tuReq.getContentType();
      if (type == null || type.equals("application/x-www-form-urlencoded")) {
        //regular post, no file upload
      }

      PostMethod pmeth = new PostMethod(modulePath);
      Set postKeys = tuReq.getParameterMap().keySet();
      for (Iterator iter = postKeys.iterator(); iter.hasNext();) {
        String key = (String) iter.next();
        String vals[] = (String[])tuReq.getParameterMap().get(key);
        for (int i = 0; i < vals.length; i++) {
          pmeth.addParameter(key, vals[i]);
        }
        meth = pmeth;
      }
      if (meth == null) return null;
      // Redirects are not supported when using POST method!
      // See RFC 2616, section 10.3.3, page 62
    }
   
    // Add olat specific headers to the request, can be used by external
    // applications to identify user and to get other params
    // test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py
    meth.addRequestHeader("X-OLAT-USERNAME", tuReq.getUserName());
    meth.addRequestHeader("X-OLAT-LASTNAME", tuReq.getLastName());
    meth.addRequestHeader("X-OLAT-FIRSTNAME", tuReq.getFirstName());
    meth.addRequestHeader("X-OLAT-EMAIL", tuReq.getEmail());

    try {
      client.executeMethod(meth);
      return meth;
    } catch (Exception e) {
      meth.releaseConnection();
    }
    return null;
  }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

      Mapper mapper = new Mapper() {
        public MediaResource handle(String relPath, HttpServletRequest hreq) {
          MediaResource mr = null;
          String method = hreq.getMethod();
          String uri = relPath;
          HttpMethod meth = null;
 
          if (uri == null) uri = (startUri == null) ? "" : startUri;
          if (uri.length() > 0 && uri.charAt(0) != '/') uri = "/" + uri;
         
          //String contentType = hreq.getContentType();
 
          // if (allowedToSendPersonalHeaders) {
          String userName = ident.getName();
          User u = ident.getUser();
          String lastName = u.getProperty(UserConstants.LASTNAME, loc);
          String firstName = u.getProperty(UserConstants.FIRSTNAME, loc);
          String email = u.getProperty(UserConstants.EMAIL, loc);
 
          if (method.equals("GET")) {
            GetMethod cmeth = new GetMethod(uri);
            String queryString = hreq.getQueryString();
            if (queryString != null) cmeth.setQueryString(queryString);
            meth = cmeth;
            // if response is a redirect, follow it
            if (meth == null) return null;
            meth.setFollowRedirects(true);
           
          } else if (method.equals("POST")) {
            //if (contentType == null || contentType.equals("application/x-www-form-urlencoded")) {
              // regular post, no file upload
            //}
            Map params = hreq.getParameterMap();
            PostMethod pmeth = new PostMethod(uri);
            Set postKeys = params.keySet();
            for (Iterator iter = postKeys.iterator(); iter.hasNext();) {
              String key = (String) iter.next();
              String vals[] = (String[]) params.get(key);
              for (int i = 0; i < vals.length; i++) {
                pmeth.addParameter(key, vals[i]);
              }
              meth = pmeth;
            }
            if (meth == null) return null;
            // Redirects are not supported when using POST method!
            // See RFC 2616, section 10.3.3, page 62

          }
 
         
          // Add olat specific headers to the request, can be used by external
          // applications to identify user and to get other params
          // test page e.g. http://cgi.algonet.se/htbin/cgiwrap/ug/test.py
          meth.addRequestHeader("X-OLAT-USERNAME", userName);
          meth.addRequestHeader("X-OLAT-LASTNAME", lastName);
          meth.addRequestHeader("X-OLAT-FIRSTNAME", firstName);
          meth.addRequestHeader("X-OLAT-EMAIL", email);
 
          boolean ok = false;
          try {
            httpClientInstance.executeMethod(meth);
            ok = true;
          } catch (Exception e) {
            // handle error later
          }
 
          if (!ok) {
            // error
            meth.releaseConnection();
            return new NotFoundMediaResource(relPath);
          }
 
          // get or post successfully
          Header responseHeader = meth.getResponseHeader("Content-Type");
          if (responseHeader == null) {
            // error
            return new NotFoundMediaResource(relPath);
          }
          mr = new HttpRequestMediaResource(meth);
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

      httpClientParams.setConnectionManagerTimeout(2500);
      httpClient.setParams(httpClientParams);
      try {
        // Could throw IllegalArgumentException if argument is not a valid url
        // (e.g. contains whitespaces)
        HttpMethod httpMethod = new GetMethod(XING_NAME_VALIDATION_URL + textElement.getValue());
        // Don't allow redirects since otherwise, we won't be able to get the correct status
        httpMethod.setFollowRedirects(false);
        // 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 Xing name exists.
        if (httpStatusCode == HttpStatus.SC_OK) {
          // If the user exists, we get a 200...
          result = true;
        } else if (httpStatusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
View Full Code Here

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

Examples of org.apache.commons.httpclient.HttpMethod

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

Examples of org.apache.commons.httpclient.HttpMethod

   
    @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

Examples of org.apache.commons.httpclient.HttpMethod

    }
    @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

Examples of org.apache.commons.httpclient.HttpMethod

        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

Examples of org.apache.commons.httpclient.HttpMethod

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