Package org.apache.abdera.protocol.client

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


    entry.addAuthor("James");
    entry.setTitle("Posting to Blogger");
    entry.setContentAsXhtml("<p>This is an example post to the new blogger beta</p>");
   
    // Initialize the client
    Client client = new CommonsClient(abdera);
   
    // Get and set the GoogleLogin authentication token
    GoogleLoginAuthCredentials creds =
      new GoogleLoginAuthCredentials(
        "username", "password","blogger");
    client.addCredentials(
      "http://beta.blogger.com",
      null, "GoogleLogin", creds);
   
    RequestOptions options = client.getDefaultRequestOptions();
    options.setUseChunked(false);
   
    // Post the entry
    Response response = client.post(
      "http://beta.blogger.com/feeds/7352231422284704069/posts/full",
      entry, options);
   
    // Check the response.
    if (response.getStatus() == 201)
View Full Code Here


    entry.addAuthor("James");
    entry.setTitle("Posting to Roller");
    entry.setContentAsHtml("<p>This is an example post to Roller</p>");
   
    // Initialize the client and set the authentication credentials
    Client client = new CommonsClient(abdera);
    client.addCredentials(
    start, null, null,
    new UsernamePasswordCredentials(
      "username", "password"));
   
    // Get the service document and look up the collection uri
    Document<Service> service_doc = client.get(start).getDocument();
    Service service = service_doc.getRoot();
    Collection collection = service.getWorkspaces().get(0).getCollections().get(0);
    String uri = collection.getHref().toString();
     
    // Post the entry to the collection
    Response response = client.post(uri, entry);
   
    // Check the result
    if (response.getStatus() == 201)
      System.out.println("Success!");
    else
View Full Code Here

    // Prepare the media resource to be sent
    FileInputStream fis = new FileInputStream("mypodcast.mp3");
    InputStreamRequestEntity re = new InputStreamRequestEntity(fis, "audio/mp3");
   
    // Initialize the client and set the auth credentials
    Client client = new CommonsClient(abdera);
    client.addCredentials(
    start, null, null,
    new UsernamePasswordCredentials(
      "username", "password"));
   
    // Get the service doc and locate the href of the collection
    Document<Service> service_doc = client.get(start).getDocument();
    Service service = service_doc.getRoot();
    Collection collection = service.getWorkspaces().get(0).getCollections().get(1);
    String uri = collection.getHref().toString();
     
    // Set the filename.  Note: the Title header was used by older drafts
    // of the Atom Publishing Protocol and should no longer be used.  The
    // current Roller APP implementation still currently requires it.
    RequestOptions options = client.getDefaultRequestOptions();
    options.setHeader("Title", "mypodcast.mp3");
   
    // Post the entry
    Response response = client.post(uri, re, options);
   
    // Check the response
    if (response.getStatus() == 201)
      System.out.println("Success!");
    else
View Full Code Here

          "when"));
    el.setAttributeValue("startTime", AtomDate.valueOf(new Date()).toString());
    el.setAttributeValue("endTime", AtomDate.valueOf(new Date()).toString());
   
    // Prepare the client
    Client client = new CommonsClient(abdera);
   
    // Get and set the GoogleLogin auth token
    GoogleLoginAuthCredentials creds =
      new GoogleLoginAuthCredentials(
        "username", "password","cl");
    client.addCredentials(
      "http://www.google.com/calendar",
      null, "GoogleLogin", creds);
   
    String uri = "http://www.google.com/calendar/feeds/default/private/full";
   
    RequestOptions options = client.getDefaultRequestOptions();
    options.setUseChunked(false);
   
    // Post the entry
    Response response = client.post(uri, entry, options);
   
    // Google Calendar might return a 302 response with a new POST URI.
    // If it does, get the new URI and post again
    if (response.getStatus() == 302) {
      uri = response.getLocation().toString();
      response = client.post(uri, entry, options);
    }
   
    // Check the response
    if (response.getStatus() == 201)
      System.out.println("Success!");
View Full Code Here

public class Main {

  public static void main(String[] args) throws Exception {
   
    Abdera abdera = new Abdera();
    Client client = new CommonsClient(abdera);
    Factory factory = abdera.getFactory();
   
    // Perform introspection.  This is an optional step.  If you already
    // know the URI of the APP collection to POST to, you can skip it.
    Document<Service> introspection =
      client.get(
        args[0]).getDocument();
    Service service =
      introspection.getRoot();
    Collection collection =
      service.getCollection(
        args[1],
        args[2]);
    report("The Collection Element", collection.toString());
   
    // Create the entry to post to the collection
    Entry entry = factory.newEntry();
    entry.setId("tag:example.org,2006:foo");
    entry.setTitle("This is the title");
    entry.setUpdated(new Date());
    entry.addAuthor("James");
    entry.setContent("This is the content");
    report("The Entry to Post", entry.toString());
   
    // Post the entry. Be sure to grab the resolved HREF of the collection
    Document<Entry> doc = client.post(
      collection.getResolvedHref().toString(),
      entry).getDocument();
   
    // In some implementations (such as Google's GData API, the entry URI is
    // distinct from it's edit URI.  To be safe, we should assume it may be
    // different
    IRI entryUri = doc.getBaseUri();
    report("The Created Entry", doc.getRoot().toString());
   
    // Grab the Edit URI from the entry.  The entry MAY have more than one
    // edit link.  We need to make sure we grab the right one.
    IRI editUri = getEditUri(doc.getRoot());
   
    // If there is an Edit Link, we can edit the entry
    if (editUri != null) {
      // Before we can edit, we need to grab an "editable" representation
      doc = client.get(editUri.toString()).getDocument();   
     
      // Change whatever you want in the retrieved entry
      doc.getRoot().getTitleElement().setValue("This is the changed title");
     
      // Put it back to the server
      client.put(editUri.toString(), doc.getRoot());
     
      // This is just to show that the entry has been modified
      doc = client.get(entryUri.toString()).getDocument();
      report("The Modified Entry", doc.getRoot().toString());
    } else {
      // Otherwise, the entry cannot be modified (no suitable edit link was found)
      report("The Entry cannot be modified", null);
    }

    // Delete the entry.  Again, we need to make sure that we have the current
    // edit link for the entry
    doc = client.get(entryUri.toString()).getDocument();
    editUri = getEditUri(doc.getRoot());
    if (editUri != null) {
      client.delete(editUri.toString());
      report("The Enry has been deleted", null);
    } else {
      report("The Entry cannot be deleted", null);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.Client

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.