Package org.apache.abdera.protocol.client

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


   * additional use cases, such as using client certs for auth
   */
  public static void clientAuth() throws Exception {
   
    Abdera abdera = new Abdera();
    AbderaClient client = new AbderaClient(abdera);
   
    KeyStore keystore = null;
    ClientAuthSSLProtocolSocketFactory factory =
      new ClientAuthSSLProtocolSocketFactory(
        keystore,"keystorepassword");
   
    AbderaClient.registerFactory(factory, 443);

    // DO NOT register a trust manager after this point
   
    client.get("https://localhost:9080/foo");
  }
View Full Code Here


public class Main {

  public static void main(String[] args) throws Exception {
   
    Abdera abdera = new Abdera();
    AbderaClient abderaClient = new AbderaClient(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 =
      abderaClient.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 = abderaClient.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 = abderaClient.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
      abderaClient.put(editUri.toString(), doc.getRoot());
     
      // This is just to show that the entry has been modified
      doc = abderaClient.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 = abderaClient.get(entryUri.toString()).getDocument();
    editUri = getEditUri(doc.getRoot());
    if (editUri != null) {
      abderaClient.delete(editUri.toString());
      report("The Enry has been deleted", null);
    } else {
      report("The Entry cannot be deleted", null);
    }
  }
View Full Code Here

    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
    AbderaClient abderaClient = new AbderaClient(abdera);
   
    // Get and set the GoogleLogin authentication token
    GoogleLoginAuthCredentials creds =
      new GoogleLoginAuthCredentials(
        "username", "password","blogger");
    abderaClient.addCredentials(
      "http://beta.blogger.com",
      null, "GoogleLogin", creds);
   
    RequestOptions options = abderaClient.getDefaultRequestOptions();
    options.setUseChunked(false);
   
    // Post the entry
    Response response = abderaClient.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
    AbderaClient abderaClient = new AbderaClient(abdera);
    abderaClient.addCredentials(
    start, null, null,
    new UsernamePasswordCredentials(
      "username", "password"));
   
    // Get the service document and look up the collection uri
    Document<Service> service_doc = abderaClient.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 = abderaClient.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
    AbderaClient abderaClient = new AbderaClient(abdera);
    abderaClient.addCredentials(
    start, null, null,
    new UsernamePasswordCredentials(
      "username", "password"));
   
    // Get the service doc and locate the href of the collection
    Document<Service> service_doc = abderaClient.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 = abderaClient.getDefaultRequestOptions();
    options.setHeader("Title", "mypodcast.mp3");
   
    // Post the entry
    Response response = abderaClient.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
    AbderaClient abderaClient = new AbderaClient(abdera);
   
    // Get and set the GoogleLogin auth token
    GoogleLoginAuthCredentials creds =
      new GoogleLoginAuthCredentials(
        "username", "password","cl");
    abderaClient.addCredentials(
      "http://www.google.com/calendar",
      null, "GoogleLogin", creds);
   
    String uri = "http://www.google.com/calendar/feeds/default/private/full";
   
    RequestOptions options = abderaClient.getDefaultRequestOptions();
    options.setUseChunked(false);
   
    // Post the entry
    Response response = abderaClient.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 = abderaClient.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();
        AbderaClient abderaClient = new AbderaClient(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 = abderaClient.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 = abderaClient.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 = abderaClient.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
            abderaClient.put(editUri.toString(), doc.getRoot());

            // This is just to show that the entry has been modified
            doc = abderaClient.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 = abderaClient.get(entryUri.toString()).getDocument();
        editUri = getEditUri(doc.getRoot());
        if (editUri != null) {
            abderaClient.delete(editUri.toString());
            report("The Enry has been deleted", null);
        } else {
            report("The Entry cannot be deleted", null);
        }
    }
View Full Code Here

    public static void init() throws Exception {
        try {
            System.out.println(">>>FeedAggregatorTest.init");
            scaProviderDomain = SCADomain.newInstance("FeedAggregator.composite");
            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch (Throwable e) {
            System.out.println(e);
            e.printStackTrace();
        }
View Full Code Here

            return;
        }
        url = url.substring(1);

        Abdera abdera = getAbdera();
        AbderaClient client = new AbderaClient(abdera);

        RequestOptions options = client.getDefaultRequestOptions();
        if (request.getHeader("If-Match") != null)
            options.setIfMatch(request.getHeader("If-Match"));
        if (request.getHeader("If-None-Match") != null)
            options.setIfNoneMatch(request.getHeader("If-None-Match"));
        if (request.getHeader("If-Modified-Since") != null)
            options.setIfNoneMatch(request.getHeader("If-Modified-Since"));
        if (request.getHeader("If-Unmodified-Since") != null)
            options.setIfNoneMatch(request.getHeader("If-Unmodified-Since"));

        ClientResponse resp = client.get(url);
        switch (resp.getType()) {
            case SUCCESS:
                try {
                    Document doc = resp.getDocument();
                    response.setContentType("application/json");
View Full Code Here

        return getAuth(id, pwd, service);
    }

    protected String getAuth(String id, String pwd, String service) {
        try {
            AbderaClient abderaClient = new AbderaClient();
            Formatter f = new Formatter();
            f.format("Email=%s&Passwd=%s&service=%s&source=%s", URLEncoder.encode(id, "utf-8"), URLEncoder
                .encode(pwd, "utf-8"), (service != null) ? URLEncoder.encode(service, "utf-8") : "", URLEncoder
                .encode(Version.APP_NAME, "utf-8"));
            StringRequestEntity stringreq =
                new StringRequestEntity(f.toString(), "application/x-www-form-urlencoded", "utf-8");
            String uri = "https://www.google.com/accounts/ClientLogin";
            RequestOptions options = abderaClient.getDefaultRequestOptions();
            options.setContentType("application/x-www-form-urlencoded");
            ClientResponse response = abderaClient.post(uri, stringreq, options);
            InputStream in = response.getInputStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int n = -1;
            while ((n = in.read()) != -1) {
                out.write(n);
View Full Code Here

TOP

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

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.