This is an automated email from the ASF dual-hosted git repository.

billblough pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-savan.git

commit 62d891399f90e1c0b0a131b9c82e1b49481cc6c1
Author: Hemapani Srinath Perera <hemap...@apache.org>
AuthorDate: Sat Jun 9 15:11:30 2007 +0000

    add A sample
---
 .../org/apache/savan/atom/AtomEventingClient.java  |  13 ++
 .../org/apache/axis2/savan/atom/AtomSample.java    |  69 ++++++++
 .../java/org/apache/axis2/savan/atom/AtomTest.java | 193 ++++++++++-----------
 3 files changed, 176 insertions(+), 99 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java 
b/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java
index ca81043..daa6877 100644
--- a/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java
+++ b/modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java
@@ -18,6 +18,8 @@ import org.apache.axis2.addressing.AddressingConstants;
 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 @@ public class AtomEventingClient {
 
        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;
        }
diff --git 
a/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java 
b/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java
new file mode 100644
index 0000000..cb6507f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomSample.java
@@ -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;
+       }
+}
diff --git 
a/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java 
b/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java
index 995b547..11ab4a9 100644
--- a/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java
+++ b/modules/core/src/test/java/org/apache/axis2/savan/atom/AtomTest.java
@@ -20,7 +20,6 @@ package org.apache.axis2.savan.atom;
 
 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.OMElement;
 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.axis2.engine.AxisConfiguration;
 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 @@ public class AtomTest extends UtilServerBasedTestCase  {
        }
     
     
-    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();

Reply via email to