Package org.apache.commons.httpclient.methods

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


    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + BOB_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementPoliteBlock.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    tx = presenceSession.waitForNotify(); // 13
    //System.out.println("11:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 14
    presence = getPresence(tx.getRequest());
View Full Code Here


    assertEquals(getBobUri(), watcher.getStringValue());
    assertEquals(Status.WAITING, watcher.getStatus())
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + ALICE_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementCondAliceBob.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    presenceSession = new SubscribeSession(getBobPhone(), "presence");
    subscribe = presenceSession.newInitialSubscribe(0, getAliceUri()); // 13
    presenceSession.sendRequest(subscribe, Response.OK); // 14
View Full Code Here

        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)){
View Full Code Here

 
        String testuri = this.root + "iftest";
   
        int status;
        try {
            PutMethod put = new PutMethod(testuri);
            String condition = "<" + testuri + "> ([" + "\"an-etag-this-testcase-invented\"" + "])";
            put.setRequestEntity(new StringRequestEntity("1"));
            put.setRequestHeader("If", condition);
            status = this.client.executeMethod(put);
            assertEquals("status: " + status, 412, status);
        }
        finally {
            DeleteMethod delete = new DeleteMethod(testuri);
View Full Code Here

      String testuri = this.root + "iflocktest";
      String locktoken = null;
     
      int status;
      try {
          PutMethod put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("1"));
          status = this.client.executeMethod(put);
          assertTrue("status: " + status, status == 200 || status == 201 || status == 204);

          LockMethod lock = new LockMethod(testuri, new LockInfo(
                  Scope.EXCLUSIVE, Type.WRITE, "testcase", 10000, true));
          status = this.client.executeMethod(lock);
          assertEquals("status", 200, status);
          locktoken = lock.getLockToken();
          assertNotNull(locktoken);
         
          // try to overwrite without lock token
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("2"));
          status = this.client.executeMethod(put);
          assertEquals("status: " + status, 423, status);
         
          // try to overwrite using bad lock token
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("2"));
          put.setRequestHeader("If", "(<" + "DAV:foobar" + ">)");
          status = this.client.executeMethod(put);
          assertEquals("status: " + status, 412, status);
         
          // try to overwrite using correct lock token, using  No-Tag-list format
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("2"));
          put.setRequestHeader("If", "(<" + locktoken + ">)");
          status = this.client.executeMethod(put);
          assertTrue("status: " + status, status == 200 || status == 204);

          // try to overwrite using correct lock token, using Tagged-list format
          // and full URI
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("3"));
          put.setRequestHeader("If", "<" + testuri + ">" + "(<" + locktoken + ">)");
          status = this.client.executeMethod(put);
          assertTrue("status: " + status, status == 200 || status == 204);

          // try to overwrite using correct lock token, using Tagged-list format
          // and absolute path only
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("4"));
          put.setRequestHeader("If", "<" + new URI(testuri).getRawPath() + ">" + "(<" + locktoken + ">)");
          status = this.client.executeMethod(put);
          assertTrue("status: " + status, status == 200 || status == 204);

          // try to overwrite using correct lock token, using Tagged-list format
          // and bad path
          put = new PutMethod(testuri);
          put.setRequestEntity(new StringRequestEntity("5"));
          put.setRequestHeader("If", "</foobar>" + "(<" + locktoken + ">)");
          status = this.client.executeMethod(put);
          assertTrue("status: " + status, status == 404 || status == 412);
      }
      finally {
          DeleteMethod delete = new DeleteMethod(testuri);
View Full Code Here

 
        String testuri = this.root + "iftest";
   
        int status;
        try {
            PutMethod put = new PutMethod(testuri);
            put.setRequestEntity(new StringRequestEntity("1"));
            status = this.client.executeMethod(put);
            assertEquals("status: " + status, 201, status);
           
            DavPropertyNameSet names = new DavPropertyNameSet();
            names.add(DeltaVConstants.COMMENT);
View Full Code Here

    @Test
    public void testUpdateBook() throws Exception {
        String endpointAddress = "http://localhost:" + PORT + "/bookstore/books";

        File input = new File(getClass().getResource("resources/update_book.txt").toURI());
        PutMethod put = new PutMethod(endpointAddress);
        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
        put.setRequestEntity(entity);
        HttpClient httpclient = new HttpClient();

        try {
            int result = httpclient.executeMethod(put);
            assertEquals(200, result);
            InputStream expected = getClass().getResourceAsStream("resources/expected_update_book.txt");
            assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
                         stripXmlInstructionIfNeeded(getStringFromInputStream(put.getResponseBodyAsStream())));
        } finally {
            // Release current connection to the connection pool once you are
            // done
            put.releaseConnection();
        }
    } 
View Full Code Here

    @Test
    public void testUpdateBookWithDom() throws Exception {
        String endpointAddress = "http://localhost:" + PORT + "/bookstore/bookswithdom";

        File input = new File(getClass().getResource("resources/update_book.txt").toURI());
        PutMethod put = new PutMethod(endpointAddress);
        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
        put.setRequestEntity(entity);
        HttpClient httpclient = new HttpClient();
        try {
            int result = httpclient.executeMethod(put);
            assertEquals(200, result);
            String resp = put.getResponseBodyAsString();
            InputStream expected = getClass().getResourceAsStream("resources/update_book.txt");
            String s = getStringFromInputStream(expected);
            //System.out.println(resp);
            //System.out.println(s);           
            assertTrue(resp.indexOf(s) >= 0);
        } finally {
            // Release current connection to the connection pool once you are
            // done
            put.releaseConnection();
        }
    }
View Full Code Here

    @Test
    public void testUpdateBookWithJSON() throws Exception {
        String endpointAddress = "http://localhost:" + PORT + "/bookstore/bookswithjson";

        File input = new File(getClass().getResource("resources/update_book_json.txt").toURI());
        PutMethod put = new PutMethod(endpointAddress);
        RequestEntity entity = new FileRequestEntity(input, "application/json; charset=ISO-8859-1");
        put.setRequestEntity(entity);
        HttpClient httpclient = new HttpClient();

        try {
            int result = httpclient.executeMethod(put);
            assertEquals(200, result);
            InputStream expected = getClass().getResourceAsStream("resources/expected_update_book.txt");
            assertEquals(stripXmlInstructionIfNeeded(getStringFromInputStream(expected)),
                         stripXmlInstructionIfNeeded(getStringFromInputStream(put.getResponseBodyAsStream())));
        } finally {
            // Release current connection to the connection pool once you are
            // done
            put.releaseConnection();
        }
    }
View Full Code Here

    public void testUpdateBookFailed() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/books";

        File input = new File(getClass().getResource("resources/update_book_not_exist.txt").toURI());        
        PutMethod post = new PutMethod(endpointAddress);
        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
        post.setRequestEntity(entity);
        HttpClient httpclient = new HttpClient();
       
        try {
            int result = httpclient.executeMethod(post);
            assertEquals(304, result);
        } finally {
            // Release current connection to the connection pool once you are done
            post.releaseConnection();
        }              
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.PutMethod

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.