001    /**
002     * 
003     */
004    package de.jw.cloud42.core.eventing.subscriptionProcessor;
005    
006    import java.util.logging.Logger;
007    
008    import javax.xml.namespace.QName;
009    
010    import org.apache.axiom.om.OMElement;
011    import org.apache.axiom.soap.SOAPBody;
012    import org.apache.axis2.AxisFault;
013    import org.apache.axis2.addressing.EndpointReference;
014    import org.apache.axis2.addressing.EndpointReferenceHelper;
015    
016    
017    
018    import de.jw.cloud42.core.eventing.EventingConstants;
019    import de.jw.cloud42.core.eventing.EventingException;
020    import de.jw.cloud42.core.eventing.subscription.SOAPSubscription;
021    import de.jw.cloud42.core.eventing.subscription.Subscription;
022    
023    /**
024     * SubscriptionProcessor class for a subscriber that receives notifications as SOAP messages over HTTP.
025     * 
026     * @author fbitzer
027     * 
028     */
029    public class SOAPSubscriptionProcessor extends GenericSubscriptionProcessor {
030    
031            /**
032             * Parses the subscription message and identifies the endpoint to send notifications to.
033             * Endpoint information is given according to WS-Eventing specification.
034             * 
035             */
036            @Override
037            public Subscription getSubscriberFromMessage(OMElement message) throws EventingException {
038    
039                    SOAPSubscription subscriber = new SOAPSubscription();
040                    
041                    
042                    
043                    //parse message
044                                    
045                    OMElement subscribeElement = message.getFirstChildWithName(new QName(
046                                    EventingConstants.EVENTING_NAMESPACE,
047                                    EventingConstants.ElementNames.Subscribe));
048                    if (subscribeElement == null)
049                            throw new EventingException("'Subscribe' element is not present");
050    
051                    OMElement deliveryElement = subscribeElement
052                                    .getFirstChildWithName(new QName(
053                                                    EventingConstants.EVENTING_NAMESPACE,
054                                                    EventingConstants.ElementNames.Delivery));
055                    if (deliveryElement == null)
056                            throw new EventingException("Delivery element is not present");
057    
058                    OMElement notifyToElement = deliveryElement
059                                    .getFirstChildWithName(new QName(
060                                                    EventingConstants.EVENTING_NAMESPACE,
061                                                    EventingConstants.ElementNames.NotifyTo));
062                    if (notifyToElement == null)
063                            throw new EventingException("NotifyTo element is null");
064    
065                    EndpointReference notifyToEPr = null;
066    
067                    try {
068                            notifyToEPr = EndpointReferenceHelper.fromOM(notifyToElement);
069                    } catch (AxisFault af) {
070                            throw new EventingException(af);
071                    }
072    
073                            
074                    subscriber.setToEndpoint(notifyToEPr);
075                    
076                    
077            
078            Logger.getAnonymousLogger().info("Subscription received. Subscribed Endpoint: "
079                                    + notifyToEPr.getAddress());
080            
081                    
082                    return subscriber;
083            }
084    
085    }