2. SOA CCT Web Service Subscriptions Tutorial
Step 1: Updating the local hosts file
Step 3: Create Web Service Proxy classes using CXF’s wsdl2java tool
Step 4: Create Notification Consumer Service Stubs
Step 6: Subscribe via the User Service
Step 7: Subscribe via the Notification Producer Service
Step 8: Unsubscribe and Logout
Step 9: Putting it All Together
3. Running the Sample Application
2.
SOA CCT Web Service Subscriptions Tutorial
Description of Tutorial
This tutorial describes how to subscribe for SOA CCT Web Service Notifications via two different means. The first utilises the UserService to subscribe for notifications in the simplest manor. This notification will subscribe for all event types. The second utilises the NotificationProducer to subscribe for specific notifications. In the case of this tutorial it will just subscribe for Agent Property LOGIN_STATUS notifications. The main procedures in this tutorial are: Step 1: Updating the local hosts file. Step 3: Create Web Service Proxy classes using CXF’s wsdl2java tool. Step 4: Create Notification Consumer service stubs using wsdl2java. Step 6: Subscribe via the User Service. Step 7: Subscribe via the Notification Producer Service. Step 9: Putting it all together. This tutorial utilises the SessionService and the NotificationProducer service to demonstrate this functionality. Please download the source code here. Notes about this tutorial
The SOA Web Services must be installed and running on an available server. The tutorial uses eclipse as the IDE, Java 8 JRE & and CXF 2.2.5 to publish services. Common programming practices such as delegates, events, threading, and exceptions are left to the individual programmer and are not covered in this tutorial. Exception handling is not shown in the code samples for brevity. You must determine exactly where or how you want to implement the example code shown in these tutorials in your own application. To instigate events being received by the consumers, CCT Ref client can be used to login and logout agents as well as going ready/not ready. |
Step 1: Updating the local
hosts file
Open up the hosts file and map the host name of your server to an IP address. |
Step 4: Create Notification
Consumer Service Stubs
1. Open a command window 2. Cd to the project’s autogen.src directory 3. Run wsdl2java –client command supplying the url to the notification consumer wsdl wsdl2java -client http://<SERVER_IP_ADDRESS>:9090/NotificationConsumer.wsdl 4. Refresh project in eclipse to import generated files
|
Step 5: Login to CCT Server
[Refer to UserSubscribe.java in the source of the sample project] 1. Create a private attribute for the service classes required as shown below. Code sample: Declare service attributes
2. Instantiate the service classes as shown below. Code sample: Instantiating the Service Proxies
3. Set the User Credentials in a Login Request as shown below. Code sample: Create Request to Login to CCT Server
4. Invoke the Login Request & Retrieve Session Token. Code sample: Invoking SessionService – loginToCCTServer request
|
Step 6: Subscribe via the
User Service
[Refer to Consumer1Impl.java in the source of the sample project] 1. Add a class to implement the Notification Consumer Service interface as follows. Code sample: Service Implementer
2. Publish Consumer Endpoint where notifications will be received. Code sample: Publish the Notification Consumer
3. Subscribe using User Service. Code sample: Subscribe providing the consumerEndpoint from the above figure
|
Step 7: Subscribe via the
Notification Producer Service
[Refer to NotificationProducerSubscribe.java in the source of the sample project] 1. Publish the Notification Consumer. Code sample: In the example the Notification Producer uses the Consmer2Impl.java
2. Subscribe using the Notification Producer Service. Code sample: In this example the client registers for AGENT_PROPERTY – LOGIN STATUS notifications.
3. Initialise the Notification Producer Service Proxy. Code sample: Instantiating the Service Proxies
4. Using the notification producer service to subscribe for notifications. The subscription method takes a number of parameters. a) Define Endpoint Reference Type - This details the notification consumer service endpoint where notifications will be sent to. Code sample: Define a EndpointReferenceType
b) Define Subscription Policy - These attributes are set to true if session related notifications are required. Code sample: Define a Topic Expression
c) Define Topic Expression - This details the types of notifications that will be subscribed for. In the example below AgentProperty Events of type LOGIN_STATUS are registered for. Code sample: Define a Topic Expression
5. Call the Notification Producer subscribe method. Code sample: Notification Consumer Subscription
|
Step 8: Unsubscribe and
Logout
[Refer to NotificationProducerSubscribe.java and UserSubscribe.java in the source of the sample project] 1.Unsubscribe the User Service subscription.
Code sample: UserSubscribe.java Unsubscribe
2. Unsubscribe the Notification Producer Service subscription. Code sample: NotificationProducer.java Unsubscribe
3. Logout using the User Service. Code sample: UserSubscribe.java Logout
|
Step 9: Putting it All
Together
[Refer to TestNotifications.java in the source of the sample project] a) A simple test program is included that will. b) Login to the cct server. c) Subscribe the two different consumer endpoints. d) Wait for 30 seconds. e) At this point you can use CCT Ref Client to login / logout the agent, set ready not ready etc so events will be pushed to the consumers. f) Unsubscribe. g) Logout. Code sample: Test Program
|
3.
Running the Sample Application
1. Download the zip file. 2. Open Eclipse. 3. Import an existing project using File – Import option. 4. Once Project is imported & compiled, Right click on project & select Run As – Java Application. 5. Once Running – validate the Notification Consumer endpoint is running by using a webrowser. 6. When the output shows the users have subscribed, use the CCT Ref Client to inject some events.
|