Examples of HttpMethod


Examples of org.apache.commons.httpclient.HttpMethod

   public void testSuccessfulLogin() throws Exception
   {
      String baseURLNoAuth = "http://" + getServerHostForURL()
              + ":" + Integer.getInteger("web.port", 8080) + "/";
      String path1 = "war1/TestServlet?operation=login&username=jduke&pass=theduke";
      HttpMethod indexGet = null;
      HttpMethod indexGet2 = null;
      try
      {
         indexGet = new GetMethod(baseURLNoAuth + path1);
         int responseCode = httpConn.executeMethod(indexGet);
         assertTrue("Get OK(" + responseCode + ")", responseCode == HttpURLConnection.HTTP_OK);
         // assert access to the restricted are of the first application is now allowed.
         SSOBaseCase.checkAccessAllowed(this.httpConn, baseURLNoAuth +
               "war1/restricted/restricted.html");
         // assert the sso cookie has been created.
         SSOBaseCase.processSSOCookie(this.httpConn.getState(), baseURLNoAuth, baseURLNoAuth);
         // assert access to the second application is allowed.
         SSOBaseCase.checkAccessAllowed(this.httpConn, baseURLNoAuth + "war2/index.html");

         // perform a programmatic logout and assert access is not allowed anymore.
         indexGet2 = new GetMethod(baseURLNoAuth + "war1/TestServlet?operation=logout");
         responseCode = httpConn.executeMethod(indexGet2);
         assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth +
               "war1/restricted/restricted.html");
         SSOBaseCase.checkAccessDenied(this.httpConn, baseURLNoAuth + "war2/index.html");
      }
      finally
      {
         if(indexGet != null)
           indexGet.releaseConnection();
         if(indexGet2 != null)
           indexGet2.releaseConnection();
      }
   }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        // Make sure it's the same as version 1.
        Assert.assertEquals("<p>" + versionOne + "</p>", TestUtils.getPageAsString(pageURL));

        // Make sure the latest current version is actually v3.1
        HttpMethod ret =
            doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
                new HashMap<String, String>() {{
                    put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
                }});
        Assert.assertEquals("<p>3.1</p>", new String(ret.getResponseBody(), "UTF-8"));
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        doPostAsAdmin("Test", "Attachment", null, "save", null,
            new HashMap<String, String>() {{
                put("content", test);
            }});

        HttpMethod ret = null;

        // Test getAttachment()
        ret = doPostAsAdmin("Test", "Attachment", null, "view", "xpage=plain", null);
        Assert.assertEquals("<p>" + ATTACHMENT_CONTENT + "</p>", ret.getResponseBodyAsString());

        // Test downloadAction.
        ret = doPostAsAdmin("Test", "Attachment", FILENAME, "download", null, null);
        Assert.assertEquals(ATTACHMENT_CONTENT, new String(ret.getResponseBody(), "UTF-8"));
        Assert.assertEquals(200, ret.getStatusCode());

        // Make sure there is exactly 1 version of this attachment.
        ret = doPostAsAdmin("Test", "Attachment", null, "preview", "xpage=plain",
            new HashMap<String, String>() {{
                put("content", "{{velocity}}$doc.getAttachment('"
                    + FILENAME + "').getVersions().size(){{/velocity}}");
            }});
        Assert.assertEquals("<p>1</p>", ret.getResponseBodyAsString());

        // Make sure that version contains the correct content.
        ret = doPostAsAdmin("Test", "Attachment", null, "preview", "xpage=plain",
            new HashMap<String, String>() {{
                put("content", "{{velocity}}$doc.getAttachment('" + FILENAME
                    + "').getAttachmentRevision('1.1').getContentAsString(){{/velocity}}");
            }});
        Assert.assertEquals("<p>" + ATTACHMENT_CONTENT + "</p>", ret.getResponseBodyAsString());
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        final String attachURL = this.getAddressPrefix() + "download/" + spaceName + "/" + pageName + "/" + FILENAME;

        // Delete the document if it exists.
        doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);

        HttpMethod ret = null;
        // Upload the XAR to import.
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(this.getClass().getResourceAsStream("/Test.Attachment2.xar"), baos);
        ret = doUploadAsAdmin("XWiki", "XWikiPreferences",
            new HashMap<String, byte[]>() {{
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);

        // Create a document.
        doPostAsAdmin(spaceName, pageName, null, "save", null, null);

        HttpMethod ret = null;
        // Upload the attachment
        ret = doUploadAsAdmin(spaceName, pageName,
            new HashMap<String, byte[]>() {{
                put(FILENAME, ATTACHMENT_CONTENT.getBytes());
            }});
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        doPostAsAdmin(spaceName, pageName, null, "delete", "?confirm=1", null);

        // Create a document.
        doPostAsAdmin(spaceName, pageName, null, "save", null, null);

        HttpMethod ret = null;
        // Upload the attachment
        ret = doUploadAsAdmin(spaceName, pageName,
            new HashMap<String, byte[]>() {{
                put(FILENAME, ATTACHMENT_CONTENT.getBytes());
            }});

        // Make sure it's there.
        Assert.assertEquals(ATTACHMENT_CONTENT, TestUtils.getPageAsString(attachURL));

        // Do a rollback.
        doPostAsAdmin(spaceName, pageName, null, "rollback", "?rev=1.1&confirm=1", null);

        // Make sure it's nolonger there.
        ret = doPostAsAdmin(spaceName, pageName, FILENAME, "download", null, null);
        Assert.assertFalse(ATTACHMENT_CONTENT.equals(new String(ret.getResponseBody(), "UTF-8")));
        Assert.assertEquals(404, ret.getStatusCode());
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);

        // Create a document.
        doPostAsAdmin(spaceName, pageName, null, "save", null, null);

        HttpMethod ret = null;
        // Upload the attachment
        ret = doUploadAsAdmin(spaceName, pageName,
            new HashMap<String, byte[]>() {{
                put(FILENAME, ATTACHMENT_CONTENT.getBytes());
            }});
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

        doPostAsAdmin(spaceName, pageName, null, "delete", "confirm=1", null);

        // Create a document. v1.1
        doPostAsAdmin(spaceName, pageName, null, "save", null, null);

        HttpMethod ret = null;
        // Upload the attachment v2.1
        ret = doUploadAsAdmin(spaceName, pageName,
            new HashMap<String, byte[]>() {{
                put(FILENAME, ATTACHMENT_CONTENT.getBytes());
            }});

        // Make sure it's there.
        Assert.assertEquals(ATTACHMENT_CONTENT, TestUtils.getPageAsString(attachURL));

        // Delete it v3.1
        doPostAsAdmin(spaceName, pageName, FILENAME, "delattachment", null, null);

        // Upload again v4.1
        ret = doUploadAsAdmin(spaceName, pageName,
            new HashMap<String, byte[]>() {{
                put(FILENAME, versionTwo.getBytes());
            }});

        // Make sure it's there.
        Assert.assertEquals(versionTwo, TestUtils.getPageAsString(attachURL));

        // Do a rollback. v5.1
        doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=2.1&confirm=1", null);

        // Make sure the latest current version is actually v5.1
        ret = doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
            new HashMap<String, String>() {{
                put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
            }});
        Assert.assertEquals("<p>5.1</p>", new String(ret.getResponseBody(), "UTF-8"));

        // Make sure it is version1
        Assert.assertEquals(ATTACHMENT_CONTENT, TestUtils.getPageAsString(attachURL));

        // Do rollback to version2. v6.1
        doPostAsAdmin(spaceName, pageName, null, "rollback", "rev=4.1&confirm=1", null);

        // Make sure it is version2
        Assert.assertEquals(versionTwo, TestUtils.getPageAsString(attachURL));

        // Make sure the latest current version is actually v6.1
        ret = doPostAsAdmin(spaceName, pageName, null, "preview", "xpage=plain",
            new HashMap<String, String>() {{
                put("content", "{{velocity}}$doc.getVersion(){{/velocity}}");
            }});
        Assert.assertEquals("<p>6.1</p>", new String(ret.getResponseBody(), "UTF-8"));
    }
View Full Code Here

Examples of org.apache.commons.httpclient.HttpMethod

{
    public static final String[] ADMIN_CREDENTIALS = new String[] {"Admin", "admin"};

    public static String getPageAsString(final String address) throws IOException
    {
        final HttpMethod ret = doPost(address, null, null);
        return new String(ret.getResponseBody(), "UTF-8");
    }
View Full Code Here

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();
    }else{

      Header responseHeader = meth.getResponseHeader("Content-Type");
      String mimeType;
      if (responseHeader == null) {
        setFetchError();
        mimeType = null;
      } else {
        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);
          htmlContent = "Error: cannot display inline :"+tureq.getUri()+": Unknown transfer problem '";
          return;
        }
        SimpleHtmlParser parser = new SimpleHtmlParser(body);
        if (!parser.isValidHtml()) { // this is not valid HTML, deliver
          // asynchronuous
        }
        meth.releaseConnection();
        htmlHead = parser.getHtmlHead();
        jsOnLoad = parser.getJsOnLoad();
        htmlContent = parser.getHtmlContent();
      } else {
        htmlContent = "Error: cannot display inline :"+tureq.getUri()+": mime type was '" + mimeType +
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.