Examples of RequestOptions


Examples of org.apache.abdera.protocol.client.RequestOptions

  }
 
  private void _responseNoCache(int type) throws Exception {
   
    Client client = new CommonsClient();
    RequestOptions options = client.getDefaultRequestOptions();
    options.setHeader("Connection", "close");
    options.setHeader("x-reqnum", "1");
    options.setHeader("x-reqtest", String.valueOf(type));
    ClientResponse response = client.get(CHECK_NO_CACHE, options);
 
    String resp1 = getResponse(response);
    assertEquals(resp1, "1");
   
    // Should not use the cache
    options.setHeader("x-reqnum", "2");
    response = client.get(CHECK_NO_CACHE, options);
 
    String resp2 = getResponse(response);
    assertEquals(resp2, "2");
   
    // Should use the cache
    options.setHeader("x-reqnum", "3");
    response = client.get(CHECK_NO_CACHE, options);
 
    String resp3 = getResponse(response);
    assertEquals(resp3, "3");
  }
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

 
 
  public void testAppClient() throws Exception {
    Client client = new CommonsClient();
    Entry entry = getFactory().newEntry();
    RequestOptions options = client.getDefaultRequestOptions();
    options.setHeader("Connection", "close");

    // do the introspection step
    ClientResponse response = client.get("http://localhost:8080/service",
                                         options);
    String col_uri;

    try {
      assertEquals(200, response.getStatus());

      Document<Service> service_doc = response.getDocument();
      assertNotNull(service_doc);
      assertEquals(1, service_doc.getRoot().getWorkspaces().size());

      Workspace workspace = service_doc.getRoot().getWorkspace("Test");
      assertNotNull(workspace);

      for (Collection c: workspace.getCollections()) {
        assertNotNull(c.getTitle());
        assertNotNull(c.getHref());
      }
   
      col_uri = getBase() + "/collections/entries";
    } finally {
      response.release();
    }

    // post a new entry
    response = client.post(col_uri, entry, options);

    String self_uri;

    try {
      assertEquals(201, response.getStatus());
      assertNotNull(response.getLocation());
      assertNotNull(response.getContentLocation());
   
      self_uri = response.getLocation().toString();
    } finally {
      response.release();
    }
    // get the collection to see if our entry is there
    response = client.get(col_uri, options);

    try {
      assertEquals(200, response.getStatus());
      Document<Feed> feed_doc = response.getDocument();
      assertEquals(1, feed_doc.getRoot().getEntries().size());
    } finally {
      response.release();
    }

    // get the entry to see if we can get it
    response = client.get(self_uri, options);

    String edit_uri;

    try {
      assertEquals(200, response.getStatus());
      Document<Entry> entry_doc = response.getDocument();

      // this isn't always true, but for our tests they are the same
      assertEquals(self_uri, entry_doc.getRoot().getId().toString());
   
      // get the edit uri from the entry
      edit_uri = entry_doc.getRoot().getEditLink().getHref().toString();
   
      // change the entry
      Document<Entry> doc = response.getDocument();
      entry = (Entry) doc.getRoot().clone();
      entry.setTitle("New title");
    } finally
      response.release();
    }

    // submit the changed entry back to the server
    response = client.put(edit_uri, entry, options);

    try {
      assertEquals(204, response.getStatus());
    } finally {
      response.release();
    }

    // check to see if the entry was modified properly
    response = client.get(self_uri, options);

    try {
      assertEquals(200, response.getStatus());

      Document<Entry> entry_doc = response.getDocument();
      assertEquals("New title", entry_doc.getRoot().getTitle());
    } finally {
      response.release();
    }

    // delete the entry
    response = client.delete(edit_uri, options);

    try {
      assertEquals(204, response.getStatus());
    } finally {
      response.release();
    }

    // is it gone?
    response = client.get(self_uri, options);

    try {
      assertEquals(404, response.getStatus());
    } finally {
      response.release();
    }

    // YAY! We're a working APP client
   
    // Now let's try to do a media post
   
    // Post the media resource
    options = client.getDefaultRequestOptions();
    options.setContentType("text/plain");
    options.setHeader("Connection", "close");

    response = client.post(col_uri,
                           new ByteArrayInputStream("test".getBytes()),
                           options);

    try {
      assertEquals(201, response.getStatus());
      assertNotNull(response.getLocation());
      assertNotNull(response.getContentLocation());
   
      self_uri = response.getLocation().toString();
    } finally {
      response.release();
    }

    // was an entry created?
    options = client.getDefaultRequestOptions();
    options.setHeader("Connection", "close");
    response = client.get(self_uri, options);

    String edit_media, media;

    try {
      assertEquals(200, response.getStatus());
      Document<Entry> entry_doc = response.getDocument();

      // this isn't always true, but for our tests they are the same
      assertEquals(self_uri, entry_doc.getRoot().getId().toString());
   
      // get the right links from the entry
      edit_uri = entry_doc.getRoot().getEditLink().getHref().toString();
      edit_media = entry_doc.getRoot()
                            .getLink("edit-media")
                            .getHref().toString();
      media = entry_doc.getRoot().getContentElement().getSrc().toString();
   
      // edit the entry
      Document doc = response.getDocument();
      entry = (Entry) doc.getRoot().clone();
      entry.setTitle("New title");
    } finally {
      response.release();
    }

    // submit the changes
    options = client.getDefaultRequestOptions();
    options.setContentType("application/atom+xml");
    options.setHeader("Connection", "close");

    response = client.put(edit_uri, entry, options);

    try {
      assertEquals(204, response.getStatus());
    } finally {
      response.release();
    }

    // get the media resource
    response = client.get(media);

    try {
      assertEquals(200, response.getStatus());

      String mediavalue = read(response.getInputStream());
      assertEquals("test", mediavalue);
    } finally {
      response.release();
    }

    // edit the media resource
    options = client.getDefaultRequestOptions();
    options.setHeader("Connection", "close");
    options.setContentType("text/plain");

    response = client.put(edit_media,
                          new ByteArrayInputStream("TEST".getBytes()),
                          options);

    try {
      assertEquals(204, response.getStatus());
    } finally {
      response.release();
    }

    // was the resource changed?
    response = client.get(media, options);

    try {
      assertEquals(200, response.getStatus());

      String mediavalue = read(response.getInputStream());
      assertEquals("TEST", mediavalue);
    } finally {
      response.release();
    }

    // delete the entry
    response = client.delete(edit_uri, options);

    try {
      assertEquals(204, response.getStatus());
    } finally {
      response.release();
    }

    // is the entry gone?
    response = client.get(self_uri, options);

    try {
      assertEquals(404, response.getStatus());
    } finally {
      response.release();
    }

    // is the media resource gone?
    options.setNoCache(true); // need to force revalidation to check

    response = client.get(media, options);

    try {
      assertEquals(404, response.getStatus());
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

      return method;
    }
  }

  public static RequestOptions createDefaultRequestOptions() {
    RequestOptions options = new RequestOptions();
    options.setAcceptEncoding(
      "gzip;q=1.0",
      "deflate;q=1.0");
    options.setAccept(
      "application/atom+xml",
      "application/atomserv+xml",
      "application/xml;q=0.8",
      "text/xml;q=0.5",
      "*/*;q=0.1");
    options.setAcceptCharset(
      "utf-8", "*;q=0.5");
    return options;
  }
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testUnmodifiedGetIfMatch() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfMatch");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Match", eTag);

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            String thisETag = res.getHeader("ETag");
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testUnmodifiedGetIfNoneMatch() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfNoneMatch");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-None-Match", eTag);

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 304 - Feed not provided since it matches ETag.
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testUnmodifiedGetIfUnModified() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 200 - Feed provided since feed is unmodified since.
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testUnmodifiedGetIfModified() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Modified-Since", dateFormat.format( new Date( 0 ) ));

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 200 - Feed provided since feed is changed.
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

        Content content = abdera.getFactory().newContent();
        content.setContentType(Content.Type.TEXT);
        content.setValue(customerName);
        entry.setContentElement(content);

        RequestOptions opts = new RequestOptions();
        String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        IRI colUri = new IRI(providerURI).resolve("customer");
        ClientResponse res = client.post(colUri.toString(), entry, opts);

        // Feed request with predicates
        opts = new RequestOptions();
        contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-None-Match", eTag);

        res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 304 - Feed not provided since it matches ETag.
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testModifiedGetIfMatch() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfMatch");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Match", eTag);

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            String thisETag = res.getHeader("ETag");
View Full Code Here

Examples of org.apache.abdera.protocol.client.RequestOptions

    @Test
    public void testModifiedGetIfUnModified() throws Exception {
        //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfUnModified");
        // Feed request with predicates
        RequestOptions opts = new RequestOptions();
        final String contentType = "application/atom+xml";
        opts.setContentType(contentType);
        opts.setHeader( "If-Unmodified-Since", dateFormat.format( previousSecond(lastModified) ));

        ClientResponse res = client.get(providerURI, opts);
        Assert.assertNotNull(res);
        try {
            // Should return 412 - Feed not provided since feed is modified since.
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.