Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpsamolisov2010-09-21 06:35:59 +0000
committerpsamolisov2010-09-21 06:35:59 +0000
commit214dc6efca7f773d49f45b0194354df63466f633 (patch)
tree5880816d9dcdc31d48bf9a1837be0ffd26603b02 /examples
parent3cc51c721ba3b1d66e61e0dee25024819fd9116b (diff)
downloadorg.eclipse.ecf-214dc6efca7f773d49f45b0194354df63466f633.tar.gz
org.eclipse.ecf-214dc6efca7f773d49f45b0194354df63466f633.tar.xz
org.eclipse.ecf-214dc6efca7f773d49f45b0194354df63466f633.zip
RESOLVED - bug 313047: [remoteservices][rest] create example for rest provider based upon Atom/RSS
https://bugs.eclipse.org/bugs/show_bug.cgi?id=313047
Diffstat (limited to 'examples')
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.classpath7
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.project28
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/META-INF/MANIFEST.MF23
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/about.html28
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/build.properties4
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/plugin.properties10
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/src/org/eclipse/ecf/remoteservices/rest/rss/Activator.java219
7 files changed, 319 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.classpath b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.classpath
new file mode 100644
index 000000000..ad32c83a7
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.project b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.project
new file mode 100644
index 000000000..7c6a28b93
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ecf.examples.remoteservices.rest.rss</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..7d8ef7711
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %plugin.name
+Bundle-SymbolicName: org.eclipse.ecf.examples.remoteservices.rest.rss
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.ecf.remoteservices.rest.rss.Activator
+Bundle-Vendor: %plugin.provider
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: com.sun.syndication.feed.synd;version="0.9.0",
+ org.eclipse.ecf.core;version="3.0.0",
+ org.eclipse.ecf.core.identity;version="3.0.0",
+ org.eclipse.ecf.remoteservice,
+ org.eclipse.ecf.remoteservice.client,
+ org.eclipse.ecf.remoteservice.events,
+ org.eclipse.ecf.remoteservice.rest,
+ org.eclipse.ecf.remoteservice.rest.client,
+ org.eclipse.ecf.remoteservice.rest.identity,
+ org.eclipse.ecf.remoteservice.rest.synd,
+ org.eclipse.equinox.concurrent.future;version="1.0.0",
+ org.osgi.framework;version="1.3.0",
+ org.osgi.util.tracker
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.equinox.common;bundle-version="3.6.0"
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/about.html b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/about.html
new file mode 100644
index 000000000..4c79781a5
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 25, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/build.properties b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/plugin.properties b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/plugin.properties
new file mode 100644
index 000000000..ddcbe9e86
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/plugin.properties
@@ -0,0 +1,10 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Pavel Samolisov and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Pavel Samolisov - initial API and implementation
+ ******************************************************************************/
+plugin.provider=Eclipse.org - ECF
+plugin.name=RSS/Atom support example for ECF REST remoteservices
diff --git a/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/src/org/eclipse/ecf/remoteservices/rest/rss/Activator.java b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/src/org/eclipse/ecf/remoteservices/rest/rss/Activator.java
new file mode 100644
index 000000000..028ae3a59
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.remoteservices.rest.rss/src/org/eclipse/ecf/remoteservices/rest/rss/Activator.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Pavel Samolisov and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: Pavel Samolisov - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.remoteservices.rest.rss;
+
+import java.util.Dictionary;
+
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerManager;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.remoteservice.IRemoteCallListener;
+import org.eclipse.ecf.remoteservice.IRemoteService;
+import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
+import org.eclipse.ecf.remoteservice.client.IRemoteCallable;
+import org.eclipse.ecf.remoteservice.client.IRemoteServiceClientContainerAdapter;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallEvent;
+import org.eclipse.ecf.remoteservice.rest.IRestCall;
+import org.eclipse.ecf.remoteservice.rest.RestCallFactory;
+import org.eclipse.ecf.remoteservice.rest.RestCallableFactory;
+import org.eclipse.ecf.remoteservice.rest.client.HttpGetRequestType;
+import org.eclipse.ecf.remoteservice.rest.identity.RestNamespace;
+import org.eclipse.ecf.remoteservice.rest.synd.SyndFeedResponseDeserializer;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndPerson;
+
+public class Activator implements BundleActivator {
+
+ private static final String REST_CONTAINER_TYPE = "ecf.rest.client";
+
+ private static final String RSS_URL = "http://planeteclipse.org";
+
+ private static final String RSS_PATH = "/planet/rss20.xml";
+
+ private static final RestNamespace REST_NAMESPACE = new RestNamespace(RestNamespace.NAME, null);
+
+ private static BundleContext context;
+
+ private IContainer container;
+
+ private ServiceTracker containerManagerServiceTracker;
+
+ private IRemoteServiceRegistration registration;
+
+ private IRemoteServiceClientContainerAdapter adapter;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+
+ Activator.context = bundleContext;
+
+ IContainerManager containerManager = getContainerManagerService();
+
+ container = containerManager.getContainerFactory().createContainer(REST_CONTAINER_TYPE,
+ getRestID(RSS_URL));
+
+ adapter = getRestClientContainerAdapter();
+
+ adapter.setResponseDeserializer(new SyndFeedResponseDeserializer());
+
+ IRemoteService restClientService = adapter.getRemoteService(registerCall().getReference());
+
+ asyncCall(restClientService);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+
+ if (registration != null)
+ registration.unregister();
+
+ if (container != null)
+ container.disconnect();
+
+ if (containerManagerServiceTracker != null)
+ containerManagerServiceTracker.close();
+ }
+
+ private void asyncCall(IRemoteService restClientService)
+ {
+ System.out.println("async calling...");
+ restClientService.callAsync(getRestCall(), createRemoteCallListener());
+ System.out.println("async called...");
+ }
+
+ private IRemoteServiceRegistration registerCall()
+ {
+ IRemoteCallable callable = RestCallableFactory.createCallable(RSS_PATH, RSS_PATH, null,
+ new HttpGetRequestType());
+
+ registration = registerCallable(callable, null);
+
+ return registration;
+ }
+
+ private void printFeedContent(SyndFeed feed)
+ {
+ System.out.println("Author: " + feed.getAuthor());
+ System.out.println("Authors:");
+ if (feed.getAuthors() != null)
+ {
+ for (Object author : feed.getAuthors())
+ {
+ System.out.println(((SyndPerson) author).getName());
+ System.out.println(((SyndPerson) author).getEmail());
+ System.out.println(((SyndPerson) author).getUri());
+ System.out.println();
+ }
+ }
+ System.out.println("Title: " + feed.getTitle());
+ System.out.println("Title Ex: " + feed.getTitleEx());
+ System.out.println("Description: " + feed.getDescription());
+ System.out.println("Description Ex: " + feed.getDescriptionEx());
+ System.out.println("Date" + feed.getPublishedDate());
+ System.out.println("Type: " + feed.getFeedType());
+ System.out.println("Encoding: " + feed.getEncoding());
+ System.out.println("(C) " + feed.getCopyright());
+ System.out.println();
+
+ for (Object object : feed.getEntries())
+ {
+ SyndEntry entry = (SyndEntry) object;
+ System.out.println(entry.getTitle() + " - " + entry.getAuthor());
+ System.out.println(entry.getLink());
+ for (Object contobj : entry.getContents())
+ {
+ SyndContent content = (SyndContent) contobj;
+ System.out.println(content.getType());
+ System.out.println(content.getValue());
+ }
+
+ SyndContent content = entry.getDescription();
+ if (content != null)
+ System.out.println(content.getValue());
+
+ System.out.println(entry.getPublishedDate());
+ System.out.println();
+ }
+ }
+
+ private IRemoteCallListener createRemoteCallListener()
+ {
+ return new IRemoteCallListener()
+ {
+ @Override
+ public void handleEvent(IRemoteCallEvent event)
+ {
+ if (event instanceof IRemoteCallCompleteEvent)
+ {
+ IRemoteCallCompleteEvent cce = (IRemoteCallCompleteEvent) event;
+ if (!cce.hadException())
+ {
+ System.out.println("Remote call completed successfully!");
+ SyndFeed feed = (SyndFeed) cce.getResponse();
+ printFeedContent(feed);
+ }
+ else
+ {
+ System.out.println("Remote call completed with exception: " + cce.getException());
+ }
+ }
+ }
+ };
+ }
+
+ private ID getRestID(String uri)
+ {
+ return IDFactory.getDefault().createID(REST_NAMESPACE, uri);
+ }
+
+ private IRemoteServiceClientContainerAdapter getRestClientContainerAdapter()
+ {
+ return (IRemoteServiceClientContainerAdapter) container.getAdapter(IRemoteServiceClientContainerAdapter.class);
+ }
+
+ private IRemoteServiceRegistration registerCallable(IRemoteCallable callable, Dictionary<String, String> properties)
+ {
+ return adapter.registerCallables(new IRemoteCallable[]{callable}, properties);
+ }
+
+ private IRestCall getRestCall()
+ {
+ return RestCallFactory.createRestCall(RSS_PATH);
+ }
+
+ private IContainerManager getContainerManagerService()
+ {
+ if (containerManagerServiceTracker == null)
+ {
+ containerManagerServiceTracker = new ServiceTracker(context, IContainerManager.class.getName(), null);
+ containerManagerServiceTracker.open();
+ }
+
+ return (IContainerManager) containerManagerServiceTracker.getService();
+ }
+}

Back to the top