Permalink
Browse files

Fixs

  • Loading branch information...
1 parent b6ed689 commit 80d9e13d9b27c828f0337a5d90e82e0e155f566b @chamerling chamerling committed Nov 16, 2012
@@ -30,14 +30,12 @@
import org.ow2.play.platform.api.APIException;
import org.ow2.play.platform.api.bean.Subscription;
import org.ow2.play.platform.api.bean.SubscriptionResult;
-import org.ow2.play.platform.client.api.ClientException;
import org.ow2.play.service.registry.api.Constants;
import org.ow2.play.service.registry.api.Registry;
import org.ow2.play.service.registry.api.RegistryException;
import org.petalslink.dsb.cxf.CXFHelper;
import com.google.common.collect.Lists;
-import com.google.common.eventbus.Subscribe;
import com.sun.istack.logging.Logger;
/**
@@ -30,7 +30,9 @@
<property name="url" value="http://localhost:8080/registry/RegistryService"/>
</bean>
- <bean id="api" class="org.ow2.play.platform.api.service.API"/>
+ <bean id="api" class="org.ow2.play.platform.api.service.API">
+ <property name="registry" ref="serviceregistry"/>
+ </bean>
<bean id="api-subscriptionservice" class="org.ow2.play.platform.api.service.SubscriptionService">
<property name="registry" ref="serviceregistry"/>
@@ -37,7 +37,8 @@
/**
*
* @return
+ * @throws ClientException
*/
- SubscriptionService getSubscriptionManager();
+ SubscriptionService getSubscriptionManager() throws ClientException;
}
@@ -96,12 +96,19 @@ public void connect(String apiEndpoint, String authtoken)
* org.ow2.play.platform.client.api.PlatformClient#getSubscriptionManager()
*/
@Override
- public synchronized SubscriptionService getSubscriptionManager() {
+ public synchronized SubscriptionService getSubscriptionManager() throws ClientException {
+ checkConnected();
if (subscriptionManager == null) {
subscriptionManager = new SubscriptionServiceImpl();
}
return subscriptionManager;
}
+
+ private void checkConnected() throws ClientException {
+ if (apiEndpoint == null) {
+ throw new ClientException("Please connect first");
+ }
+ }
class SubscriptionServiceImpl implements SubscriptionService {
@@ -1,5 +1,10 @@
package org.ow2.play;
+import org.ow2.play.platform.api.bean.Subscription;
+import org.ow2.play.platform.api.bean.SubscriptionResult;
+import org.ow2.play.platform.api.bean.Topic;
+import org.ow2.play.platform.client.ws.PlatformClient;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -35,4 +40,49 @@ public void testApp()
{
assertTrue( true );
}
+
+ public void testMe() throws Exception {
+ PlatformClient client = new PlatformClient();
+ client.connect("http://localhost:8080/play/api/v1/", null);
+
+ Subscription subscription = new Subscription();
+ subscription.subscriber = "http://localhost:3001/";
+ Topic topic = new Topic();
+ topic.name = "FacebookStatusFeed";
+ topic.ns = "http://streams.event-processing.org/ids/";
+ topic.prefix = "s";
+
+ subscription.topic = topic;
+ SubscriptionResult result = client.getSubscriptionManager().subscribe(subscription);
+ System.out.println("" + result.subscriptionID);
+ }
+
+ public void testUnsubscribe() throws Exception {
+ PlatformClient client = new PlatformClient();
+ client.connect("http://localhost:8080/play/api/v1/", null);
+
+ boolean result = client.getSubscriptionManager().unsubscribe("4d7ddc57-f426-454c-a738-625a7621a852");;
+ System.out.println(result);
+ }
+
+
+ public void testSubscribeThenUnsubscribe() throws Exception {
+ PlatformClient client = new PlatformClient();
+ client.connect("http://localhost:8080/play/api/v1/", null);
+
+ Subscription subscription = new Subscription();
+ subscription.subscriber = "http://localhost:3001/";
+ Topic topic = new Topic();
+ topic.name = "FacebookStatusFeed";
+ topic.ns = "http://streams.event-processing.org/ids/";
+ topic.prefix = "s";
+
+ subscription.topic = topic;
+ SubscriptionResult result = client.getSubscriptionManager().subscribe(subscription);
+ System.out.println("Got subscription : " + result.subscriptionID);
+
+ Thread.sleep(20000L);
+
+ client.getSubscriptionManager().unsubscribe(result.subscriptionID);
+ }
}

0 comments on commit 80d9e13

Please sign in to comment.