001 /**
002 *
003 */
004 package de.jw.cloud42.webservice;
005
006
007 import org.apache.axiom.om.OMElement;
008 import org.apache.axis2.context.MessageContext;
009
010
011
012
013 import de.jw.cloud42.core.endpoint.Cloud42Endpoint;
014 import de.jw.cloud42.core.eventing.factory.SubscriptionProcessorFactory;
015 import de.jw.cloud42.core.eventing.subscriptionProcessor.GenericSubscriptionProcessor;
016 import de.jw.cloud42.core.eventing.subscriptionProcessor.SubscriptionProcessor;
017
018
019
020 /**
021 * Web service class for Cloud42 notification service. Provides methods to subscribe and unsubscribe to notification
022 * messages coming from AMI instances. Subscription/Unsubscription requests are send as SOAP messages.
023 *
024 * @author fbitzer
025 *
026 */
027 public class Cloud42NotificationService {
028
029 /**
030 * Subscribe to notification messages.
031 *
032 * @param subscriptionProcessor a fully qualified name of the class that handles the subscription request.
033 * This class is responsible for parsing the subscription message, to extract endpoint informations out of the
034 * subscriptionMessage part etc.
035 * @param topic the topic the subscriber wants to subscribe to.
036 * @param subscriptionMessage This part of the SOAP message contains endpoint information and is parsed by
037 * the subscriptionProcessor.
038 *
039 * @return a UUID to identify the subscription.
040 * @throws Exception
041 */
042 public String subscribe(String subscriptionProcessor, String topic, OMElement subscriptionMessage) throws Exception{
043
044
045 SubscriptionProcessorFactory f = new SubscriptionProcessorFactory();
046
047 SubscriptionProcessor p = f.createSubscriptionProcessor(subscriptionProcessor);
048
049 MessageContext msgContext = MessageContext.getCurrentMessageContext();
050
051
052 return p.subscribe(subscriptionMessage, topic);
053 }
054 /**
055 * Unsubscribe.
056 * @param subscriptionId UUID of subscription to cancel.
057 *
058 * @return true if successful (return value is necessary because of Exception handling)
059 *
060 * @throws Exception
061 *
062 */
063 public boolean unsubscribe(String subscriptionId) throws Exception {
064
065 SubscriptionProcessor p = new GenericSubscriptionProcessor();
066
067 p.unsubscribe(subscriptionId);
068
069 return true;
070 }
071
072 /**
073 * Get current address of Cloud42 message endpoint.
074 * @return the address of the Cloud42 message endpoint used for sending notifications from
075 * AMI instances to Cloud42.
076 */
077 public String getEndpointAddress(){
078 return Cloud42Endpoint.getInstance().getAddress();
079 }
080
081 /**
082 * Set address of Cloud42 message endpoint (the endpoint published by Cloud42 for retrieving and dsipatching
083 * event messages from AMI instances) and cause its restart.
084 *
085 * @param address HTTP Endpoint address such as <code>http://localhost:8084/messages</code>
086 */
087 public void setEndpointAddress(String address){
088 Cloud42Endpoint.getInstance().setAddress(address);
089 }
090 }