Examples of HttpMethodBase


Examples of org.apache.commons.httpclient.HttpMethodBase

    * through the classloading service.
    */
   public void testHttpRequestRevealInstallationDirectory() throws Exception
   {
      URL url = new URL(baseURL + "org.jboss.web.WebServer.class");
      HttpMethodBase request = HttpUtils.accessURL(url, null, HttpURLConnection.HTTP_NOT_FOUND);
      String statusText = request.getStatusText();
     
      if (statusText.indexOf(".jar") > 0)
         fail("Status text reveals installation directory information: " + statusText);
   }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

    * test isUserInRole.
    */
   public void testUserInRoleServlet() throws Exception
   {
      URL url = new URL(baseURL+"jbosstest/restricted/UserInRoleServlet");
      HttpMethodBase request = HttpUtils.accessURL(url);
      Header errors = request.getResponseHeader("X-ExpectedUserRoles-Errors");
      log.info("X-ExpectedUserRoles-Errors: "+errors);
      assertTrue("X-ExpectedUserRoles-Errors("+errors+") is null", errors == null);
      errors = request.getResponseHeader("X-UnexpectedUserRoles-Errors");
      log.info("X-UnexpectedUserRoles-Errors: "+errors);
      assertTrue("X-UnexpectedUserRoles-Errors("+errors+") is null", errors == null);
   }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

   /** Access the http://{host}/jbosstest/restricted/SubjectServlet
    */
   public void testSubjectServlet() throws Exception
   {
      URL url = new URL(baseURL+"jbosstest/restricted/SubjectServlet");
      HttpMethodBase request = HttpUtils.accessURL(url);
      Header hdr = request.getResponseHeader("X-SubjectServlet");
      log.info("X-SubjectServlet: "+hdr);
      assertTrue("X-SubjectServlet("+hdr+") is NOT null", hdr != null);
      hdr = request.getResponseHeader("X-SubjectFilter-ENC");
      log.info("X-SubjectFilter-ENC: "+hdr);
      assertTrue("X-SubjectFilter-ENC("+hdr+") is NOT null", hdr != null);
      hdr = request.getResponseHeader("X-SubjectFilter-SubjectSecurityManager");
      log.info("X-SubjectFilter-SubjectSecurityManager: "+hdr);
      assertTrue("X-SubjectFilter-SubjectSecurityManager("+hdr+") is NOT null", hdr != null);
   }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

      deploy("manifest-web.ear");
      try
      {
         String baseURL = "http://" + getServerHostForURL() + ":" + Integer.getInteger("web.port", 8080) + '/';
         URL url = new URL(baseURL+"manifest/classpath.jsp");
         HttpMethodBase request = HttpUtils.accessURL(url);
         Header errors = request.getResponseHeader("X-Exception");
         log.info("X-Exception: "+errors);
         assertTrue("X-Exception("+errors+") is null", errors == null);
      }
      finally
      {
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

      try
      {
         String baseURL = "http://" + getServerHostForURL() + ":" + Integer.getInteger("web.port", 8080) + '/';
         // Load a log4j class
         URL url = new URL(baseURL+"class-loading/ClasspathServlet2?class=org.apache.log4j.net.SocketAppender");
         HttpMethodBase request = HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
         Header cs = request.getResponseHeader("X-CodeSource");
         log.info(cs);
         // Validate it has not come from the war
         assertTrue("X-CodeSource("+cs+") does not contain war",
               cs.getValue().indexOf(".war") < 0 );
         getLog().debug(url+" OK");
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

      try
      {
         String baseURL = "http://" + getServerHostForURL() + ":" + Integer.getInteger("web.port", 8080) + '/';
         // Load a servlet class
         URL url = new URL(baseURL+"servlet-classes/ClasspathServlet2?class=javax.servlet.http.HttpServletResponse");
         HttpMethodBase request = HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK);
         Header cs = request.getResponseHeader("X-CodeSource");
         log.info(cs);
         // Validate it has not come from the war
         assertTrue("X-CodeSource("+cs+") does not contain war",
               cs.getValue().indexOf(".war") < 0 );
         getLog().debug(url+" OK");
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

   @SuppressWarnings("unchecked")
   public ClientResponse execute(ClientRequest request) throws Exception
   {
      String uri = request.getUri();
      final HttpMethodBase httpMethod = createHttpMethod(uri, request.getHttpMethod());
      loadHttpMethod(request, httpMethod);

      int status = httpClient.executeMethod(httpMethod);

      BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
      {
         InputStream stream;

         public InputStream getInputStream() throws IOException
         {
            if (stream == null)
            {
               stream = new SelfExpandingBufferredInputStream(httpMethod.getResponseBodyAsStream());
            }
            return stream;
         }

         public void performReleaseConnection()
         {
            try
            {
               httpMethod.releaseConnection();
            }
            catch (Exception ignored)
            {}
            try
            {
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

        String urlStr = url.toString();

        log.debug("Start : sample " + urlStr);
        log.debug("method " + method);

        HttpMethodBase httpMethod = null;

        HTTPSampleResult res = new HTTPSampleResult();
        res.setMonitor(isMonitor());

        res.setSampleLabel(urlStr); // May be replaced later
        res.setHTTPMethod(method);
        res.setURL(url);

        res.sampleStart(); // Count the retries as well in the time
        try {
            // May generate IllegalArgumentException
            if (method.equals(POST)) {
                httpMethod = new PostMethod(urlStr);
            } else if (method.equals(PUT)){
                httpMethod = new PutMethod(urlStr);
            } else if (method.equals(HEAD)){
                httpMethod = new HeadMethod(urlStr);
            } else if (method.equals(TRACE)){
                httpMethod = new TraceMethod(urlStr);
            } else if (method.equals(OPTIONS)){
                httpMethod = new OptionsMethod(urlStr);
            } else if (method.equals(DELETE)){
                httpMethod = new DeleteMethod(urlStr);
            } else if (method.equals(GET)){
                httpMethod = new GetMethod(urlStr);
            } else {
                throw new IllegalArgumentException("Unexpected method: "+method);
            }

            final CacheManager cacheManager = getCacheManager();
            if (cacheManager != null && GET.equalsIgnoreCase(method)) {
               if (cacheManager.inCache(url)) {
                   res.sampleEnd();
                   res.setResponseNoContent();
                   res.setSuccessful(true);
                   return res;
               }
            }

            // Set any default request headers
            setDefaultRequestHeaders(httpMethod);

            // Setup connection
            HttpClient client = setupConnection(url, httpMethod, res);
            savedClient = client;

            // Handle the various methods
            if (method.equals(POST)) {
                String postBody = sendPostData((PostMethod)httpMethod);
                res.setQueryString(postBody);
            } else if (method.equals(PUT)) {
                String putBody = sendPutData((PutMethod)httpMethod);
                res.setQueryString(putBody);
            }

            int statusCode = client.executeMethod(httpMethod);

            // Needs to be done after execute to pick up all the headers
            res.setRequestHeaders(getConnectionHeaders(httpMethod));

            // Request sent. Now get the response:
            InputStream instream = httpMethod.getResponseBodyAsStream();

            if (instream != null) {// will be null for HEAD
                instream = new CountingInputStream(instream);
                try {
                    Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
                    if (responseHeader!= null && ENCODING_GZIP.equals(responseHeader.getValue())) {
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                       
                    } else {
                        res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
                    }
                } finally {
                    JOrphanUtils.closeQuietly(instream);
                }
            }

            res.sampleEnd();
            // Done with the sampling proper.

            // Now collect the results into the HTTPSampleResult:

            res.setSampleLabel(httpMethod.getURI().toString());
            // Pick up Actual path (after redirects)

            res.setResponseCode(Integer.toString(statusCode));
            res.setSuccessful(isSuccessCode(statusCode));

            res.setResponseMessage(httpMethod.getStatusText());

            String ct = null;
            Header h = httpMethod.getResponseHeader(HEADER_CONTENT_TYPE);
            if (h != null)// Can be missing, e.g. on redirect
            {
                ct = h.getValue();
                res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1
                res.setEncodingAndType(ct);
            }

            res.setResponseHeaders(getResponseHeaders(httpMethod));
            if (res.isRedirect()) {
                final Header headerLocation = httpMethod.getResponseHeader(HEADER_LOCATION);
                if (headerLocation == null) { // HTTP protocol violation, but avoids NPE
                    throw new IllegalArgumentException("Missing location header");
                }
                res.setRedirectLocation(headerLocation.getValue());
            }

            // record some sizes to allow HTTPSampleResult.getBytes() with different options
            if (instream != null) {
                res.setBodySize(((CountingInputStream) instream).getCount());
            }
            res.setHeadersSize(calculateHeadersSize(httpMethod));
            if (log.isDebugEnabled()) {
                log.debug("Response headersSize=" + res.getHeadersSize() + " bodySize=" + res.getBodySize()
                        + " Total=" + (res.getHeadersSize() + res.getBodySize()));
            }
           
            // If we redirected automatically, the URL may have changed
            if (getAutoRedirects()){
                res.setURL(new URL(httpMethod.getURI().toString()));
            }

            // Store any cookies received in the cookie manager:
            saveConnectionCookies(httpMethod, res.getURL(), getCookieManager());

            // Save cache information
            if (cacheManager != null){
                cacheManager.saveDetails(httpMethod, res);
            }

            // Follow redirects and download page resources if appropriate:
            res = resultProcessing(areFollowingRedirect, frameDepth, res);

            log.debug("End : sample");
            return res;
        } catch (IllegalArgumentException e)// e.g. some kinds of invalid URL
        {
            res.sampleEnd();
            HTTPSampleResult err = errorResult(e, res);
            err.setSampleLabel("Error: " + url.toString());
            return err;
        } catch (IOException e) {
            res.sampleEnd();
            HTTPSampleResult err = errorResult(e, res);
            err.setSampleLabel("Error: " + url.toString());
            return err;
        } finally {
            savedClient = null;
            if (httpMethod != null) {
                httpMethod.releaseConnection();
            }
        }
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

     * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
     * @param httMethod supports just GET and POST methods
     * @throws IOException
     * @throws HttpException */
    public String getContent(String url, String expectedContentType, List<NameValuePair> params, int expectedStatusCode, String httpMethod) throws IOException {
      HttpMethodBase method = null;
     
      if (HTTP_METHOD_GET.equals(httpMethod)){
        method= new GetMethod(url);
      }else if (HTTP_METHOD_POST.equals(httpMethod)){
        method = new PostMethod(url);
      else{
        fail("Http Method not supported in this test suite, method: "+httpMethod);
      }
     
      if(params != null) {
            final NameValuePair [] nvp = new NameValuePair[0];
            method.setQueryString(params.toArray(nvp));
        }
        final int status = httpClient.executeMethod(method);
        final String content = getResponseBodyAsStream(method, 0);
        assertEquals("Expected status " + expectedStatusCode + " for " + url + " (content=" + content + ")",
                expectedStatusCode,status);
        final Header h = method.getResponseHeader("Content-Type");
        if(expectedContentType == null) {
            if(h!=null) {
                fail("Expected null Content-Type, got " + h.getValue());
            }
        } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethodBase

    private String requestTicket(String url, RenderRequest request, RenderResponse response)
    {
        // ...set up URL and HttpClient stuff
      String ticket = "";
      HttpClient client = new HttpClient();
        HttpMethodBase httpMethod = null;
        httpMethod = new PostMethod();
        //String useragentProperty = request.getProperty("User-Agent");
        httpMethod.addRequestHeader( "User-Agent", "Firefox" );
        httpMethod.setPath(url);
        try
        {
            client.executeMethod(httpMethod);
            int responseCode  = httpMethod.getStatusCode();
            if (responseCode >= 300 && responseCode <= 399)
            {
                // redirection that could not be handled automatically!!! (probably from a POST)
                Header locationHeader = httpMethod.getResponseHeader("location");
                String redirectLocation = locationHeader != null ? locationHeader.getValue() : null ;
                if (redirectLocation != null)
                {
                    // one more time (assume most params are already encoded & new URL is using GET protocol!)
                    return requestTicket( redirectLocation,null,null) ;
                }
                else
                {
                    // The response is a redirect, but did not provide the new location for the resource.
                    throw new PortletException("Redirection code: "+responseCode+", but with no redirectionLocation set.");
                }
            }
            else if (responseCode == 200)
            {         
    //          String body = httpMethod.getResponseBodyAsString();
    //          Header [] head =  httpMethod.getResponseHeaders();
              TicketParamRewriter ticketWriter =  new TicketParamRewriter();
                String ticketName = (String)request.getPreferences().getValue(SSO_PREF_TICKET_NAME, null);
                if (ticketName != null)
                {
                    ticketWriter.setTicketName(ticketName);
                    Reader reader = new InputStreamReader(httpMethod.getResponseBodyAsStream());
                    createParserAdaptor().parse(ticketWriter, reader);
                    ticket = ticketWriter.getTicket();
                }
            }
        }
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.