You are viewing a plain text version of this content. The canonical link for it is here.
Posted to savan-dev@ws.apache.org by he...@apache.org on 2007/06/09 17:11:31 UTC
svn commit: r545758 - in /webservices/savan/trunk/java/modules/core/src:
main/java/org/apache/savan/atom/AtomEventingClient.java
test/java/org/apache/axis2/savan/atom/AtomSample.java
test/java/org/apache/axis2/savan/atom/AtomTest.java
Author: hemapani
Date: Sat Jun 9 08:11:30 2007
New Revision: 545758
URL: http://svn.apache.org/viewvc?view=rev&rev=545758
Log:
add A sample
Added:
webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java
Modified:
webservices/savan/trunk/java/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java
webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java
Modified: webservices/savan/trunk/java/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java
URL: http://svn.apache.org/viewvc/webservices/savan/trunk/java/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java?view=diff&rev=545758&r1=545757&r2=545758
==============================================================================
--- webservices/savan/trunk/java/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java (original)
+++ webservices/savan/trunk/java/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java Sat Jun 9 08:11:30 2007
@@ -18,6 +18,8 @@
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -46,6 +48,17 @@
private EndpointReference feedEpr;
+ public AtomEventingClient(String serviceUrl,String clientRepository) throws AxisFault{
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepository,clientRepository+"/conf/axis2.xml");
+ serviceClient = new ServiceClient (configContext,null); //TODO give a repo
+
+ Options options = new Options ();
+ serviceClient.setOptions(options);
+ serviceClient.engageModule(new QName ("addressing"));
+ options.setTo(new EndpointReference (serviceUrl));
+ }
+
+
public AtomEventingClient(ServiceClient serviceClient) {
this.serviceClient = serviceClient;
}
Added: webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java
URL: http://svn.apache.org/viewvc/webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java?view=auto&rev=545758
==============================================================================
--- webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java (added)
+++ webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java Sat Jun 9 08:11:30 2007
@@ -0,0 +1,69 @@
+package org.apache.axis2.savan.atom;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.savan.atom.AtomEventingClient;
+
+import com.wso2.eventing.atom.CreateFeedResponseDocument.CreateFeedResponse;
+
+public class AtomSample {
+
+
+ /**
+ * To run the sample
+ * <ol>
+ * <li>Install Axis2 with addressing Module</li>
+ * <li>Install some service, engage Savan with that service</li>
+ * <li>Set up Axis2 client repository in client machine with addressing module</li>
+ * <li>Run the sample with http://serviceHost:servicePort/services/<Service-Name>
+ * and <client-repostiory-location></li>
+ * </ol>
+ * @param args
+ */
+
+ public static void main(String[] args){
+ if(args.length != 2){
+ System.out.println("Usage: serviceUrl clientRepository");
+ }else{
+
+ try {
+ String serviceUrl = args[0];
+ AtomEventingClient atomEventingClient = new AtomEventingClient(serviceUrl,args[1]);
+ CreateFeedResponse createFeedResponse = atomEventingClient.createFeed("test Title","Srinath Perera");
+ System.out.println("Created Feed "+createFeedResponse.getFeedUrl() + " Sucessfully");
+
+ //publish to service using SOAP
+ atomEventingClient.publishWithSOAP(serviceUrl, getDummyMethodRequestElement (1), null);
+
+ //publish service using REST
+ atomEventingClient.publishWithREST(serviceUrl, getDummyMethodRequestElement (2), null);
+
+ //Get the feed using http GET
+ OMElement feedAsXml = atomEventingClient.fetchFeed(createFeedResponse.getFeedUrl());
+ feedAsXml.serialize(System.out,new OMOutputFormat());
+
+ System.out.println("Fetch Feed using HTTP Get, copy and paste url " + createFeedResponse.getFeedUrl() + " in browser to retirve the feed ");
+ System.out.println("Press any key to delete the feed");
+ System.in.read();
+ atomEventingClient.deleteFeed();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static final String applicationNamespaceName = "http://tempuri.org/";
+ private static final String dummyMethod = "dummyMethod";
+
+ private static OMElement getDummyMethodRequestElement(int i) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace namespace = fac.createOMNamespace(applicationNamespaceName,"ns1");
+ OMElement de = fac.createOMElement(dummyMethod, namespace);
+ de.setText(String.valueOf(i));
+ return de;
+ }
+}
Modified: webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java
URL: http://svn.apache.org/viewvc/webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java?view=diff&rev=545758&r1=545757&r2=545758
==============================================================================
--- webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java (original)
+++ webservices/savan/trunk/java/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java Sat Jun 9 08:11:30 2007
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import javax.xml.namespace.QName;
@@ -29,7 +28,6 @@
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
@@ -42,10 +40,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.savan.atom.AtomEventingClient;
-import org.apache.savan.eventing.EventingConstants;
import org.apache.savan.eventing.client.EventingClient;
-import org.apache.savan.eventing.client.EventingClientBean;
-import org.apache.savan.eventing.client.SubscriptionStatus;
import com.wso2.eventing.atom.CreateFeedResponseDocument.CreateFeedResponse;
@@ -184,103 +179,103 @@
}
- private void initClient () throws AxisFault {
-
-// String CLIENT_REPO = null;
-// String AXIS2_XML = null;
+// private void initClient () throws AxisFault {
+//
+//// String CLIENT_REPO = null;
+//// String AXIS2_XML = null;
+////
+//// if (repo!=null) {
+//// CLIENT_REPO = repo;
+//// AXIS2_XML = repo + File.separator + "axis2.xml";
+//// } else {
+////// throw new AxisFault ("Please specify the client repository as a program argument.Use '-h' for help.");
+//// }
+//
+// ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(AXIS2_REPO,AXIS2_REPO+"/conf/axis2.xml");
+// serviceClient = new ServiceClient (configContext,null); //TODO give a repo
+//
+// options = new Options ();
+// serviceClient.setOptions(options);
+// serviceClient.engageModule(new QName ("addressing"));
+//
+// eventingClient = new EventingClient (serviceClient);
+//
+// String toAddress = "http://" + serverIP + ":" + port + toAddressPart;
//
-// if (repo!=null) {
-// CLIENT_REPO = repo;
-// AXIS2_XML = repo + File.separator + "axis2.xml";
-// } else {
-//// throw new AxisFault ("Please specify the client repository as a program argument.Use '-h' for help.");
+// //String toAddress = "http://" + serverIP + ":" + port + "/axis2/services/RMSampleService";
+// options.setTo(new EndpointReference (toAddress));
+// }
+//
+// private void performAction (int action) throws Exception {
+//
+// switch (action) {
+// case 1:
+// doSubscribe(SUBSCRIBER_1_ID);
+// break;
+// case 2:
+// doSubscribe(SUBSCRIBER_2_ID);
+// break;
+// case 3:
+// doSubscribe(SUBSCRIBER_1_ID);
+// doSubscribe(SUBSCRIBER_2_ID);
+// break;
+// case 4:
+// doUnsubscribe(SUBSCRIBER_1_ID);
+// break;
+// case 5:
+// doUnsubscribe(SUBSCRIBER_2_ID);
+// break;
+// case 6:
+// doUnsubscribe(SUBSCRIBER_1_ID);
+// doUnsubscribe(SUBSCRIBER_2_ID);
+// break;
+// case 7:
+// doGetStatus(SUBSCRIBER_1_ID);
+// break;
+// case 8:
+// doGetStatus(SUBSCRIBER_2_ID);
+// break;
+// case 9:
+// System.exit(0);
+// break;
+// default:
+// break;
// }
-
- ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(AXIS2_REPO,AXIS2_REPO+"/conf/axis2.xml");
- serviceClient = new ServiceClient (configContext,null); //TODO give a repo
-
- options = new Options ();
- serviceClient.setOptions(options);
- serviceClient.engageModule(new QName ("addressing"));
-
- eventingClient = new EventingClient (serviceClient);
-
- String toAddress = "http://" + serverIP + ":" + port + toAddressPart;
-
- //String toAddress = "http://" + serverIP + ":" + port + "/axis2/services/RMSampleService";
- options.setTo(new EndpointReference (toAddress));
- }
-
- private void performAction (int action) throws Exception {
-
- switch (action) {
- case 1:
- doSubscribe(SUBSCRIBER_1_ID);
- break;
- case 2:
- doSubscribe(SUBSCRIBER_2_ID);
- break;
- case 3:
- doSubscribe(SUBSCRIBER_1_ID);
- doSubscribe(SUBSCRIBER_2_ID);
- break;
- case 4:
- doUnsubscribe(SUBSCRIBER_1_ID);
- break;
- case 5:
- doUnsubscribe(SUBSCRIBER_2_ID);
- break;
- case 6:
- doUnsubscribe(SUBSCRIBER_1_ID);
- doUnsubscribe(SUBSCRIBER_2_ID);
- break;
- case 7:
- doGetStatus(SUBSCRIBER_1_ID);
- break;
- case 8:
- doGetStatus(SUBSCRIBER_2_ID);
- break;
- case 9:
- System.exit(0);
- break;
- default:
- break;
- }
- }
-
- private void doSubscribe (String ID) throws Exception {
- EventingClientBean bean = new EventingClientBean ();
-
- String subscribingAddress = null;
- if (SUBSCRIBER_1_ID.equals(ID)) {
- subscribingAddress = "http://" + serverIP + ":" + port + listner1AddressPart;
- } else if (SUBSCRIBER_2_ID.equals(ID)) {
- subscribingAddress = "http://" + serverIP + ":" + port + listner2AddressPart;
- }
-
- bean.setDeliveryEPR(new EndpointReference (subscribingAddress));
-
- //uncomment following to set an expiration time of 10 minutes.
-// Date date = new Date ();
-// date.setMinutes(date.getMinutes()+10);
-// bean.setExpirationTime(date);
-
- eventingClient.subscribe(bean,ID);
- Thread.sleep(1000); //TODO remove if not sequired
- }
-
- private void doUnsubscribe (String ID) throws Exception {
- eventingClient.unsubscribe(ID);
- Thread.sleep(1000); //TODO remove if not sequired
- }
+// }
- private void doGetStatus (String ID) throws Exception {
- SubscriptionStatus status = eventingClient.getSubscriptionStatus(ID);
- Thread.sleep(1000); //TODO remove if not sequired
-
- String statusValue = status.getExpirationValue();
- System.out.println("Status of the subscriber '" + ID +"' is" + statusValue);
- }
+// private void doSubscribe (String ID) throws Exception {
+// EventingClientBean bean = new EventingClientBean ();
+//
+// String subscribingAddress = null;
+// if (SUBSCRIBER_1_ID.equals(ID)) {
+// subscribingAddress = "http://" + serverIP + ":" + port + listner1AddressPart;
+// } else if (SUBSCRIBER_2_ID.equals(ID)) {
+// subscribingAddress = "http://" + serverIP + ":" + port + listner2AddressPart;
+// }
+//
+// bean.setDeliveryEPR(new EndpointReference (subscribingAddress));
+//
+// //uncomment following to set an expiration time of 10 minutes.
+//// Date date = new Date ();
+//// date.setMinutes(date.getMinutes()+10);
+//// bean.setExpirationTime(date);
+//
+// eventingClient.subscribe(bean,ID);
+// Thread.sleep(1000); //TODO remove if not sequired
+// }
+//
+// private void doUnsubscribe (String ID) throws Exception {
+// eventingClient.unsubscribe(ID);
+// Thread.sleep(1000); //TODO remove if not sequired
+// }
+//
+// private void doGetStatus (String ID) throws Exception {
+// SubscriptionStatus status = eventingClient.getSubscriptionStatus(ID);
+// Thread.sleep(1000); //TODO remove if not sequired
+//
+// String statusValue = status.getExpirationValue();
+// System.out.println("Status of the subscriber '" + ID +"' is" + statusValue);
+// }
private OMElement getDummyMethodRequestElement(int i) {
OMFactory fac = OMAbstractFactory.getOMFactory();