View Javadoc
1   /**
2    * This Source Code Form is subject to the terms of the Mozilla Public
3    * License, v. 2.0. If a copy of the MPL was not distributed with this
4    * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5    *
6    * If it is not possible or desirable to put the notice in a particular
7    * file, then You may include the notice in a location (such as a LICENSE
8    * file in a relevant directory) where a recipient would be likely to look
9    * for such a notice.
10  
11   * 
12   */
13   
14  /*  ---------------------------------------------------------------------------
15   *  U.S. Government, Department of the Army
16   *  Army Materiel Command
17   *  Research Development Engineering Command
18   *  Communications Electronics Research Development and Engineering Center
19   *  ---------------------------------------------------------------------------
20   */
21  
22  package org.miloss.fgsms.wsn.broker;
23  
24  
25  import java.util.GregorianCalendar;
26  import javax.annotation.Resource;
27  import javax.jws.Oneway;
28  import javax.jws.WebMethod;
29  import javax.jws.WebParam;
30  import javax.jws.WebResult;
31  import javax.jws.WebService;
32  import javax.jws.soap.SOAPBinding;
33  import javax.xml.bind.JAXBElement;
34  import javax.xml.datatype.DatatypeConfigurationException;
35  import javax.xml.datatype.DatatypeFactory;
36  import javax.xml.ws.WebServiceContext;
37  import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
38  import org.apache.log4j.Logger;
39  import org.oasis_open.docs.wsn.b_2.GetCurrentMessage;
40  import org.oasis_open.docs.wsn.b_2.GetCurrentMessageResponse;
41  import org.oasis_open.docs.wsn.b_2.InvalidFilterFaultType;
42  import org.oasis_open.docs.wsn.b_2.Notify;
43  import org.oasis_open.docs.wsn.b_2.Subscribe;
44  import org.oasis_open.docs.wsn.b_2.SubscribeCreationFailedFaultType;
45  import org.oasis_open.docs.wsn.b_2.SubscribeResponse;
46  import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
47  import org.oasis_open.docs.wsn.br_2.RegisterPublisher;
48  import org.oasis_open.docs.wsn.br_2.RegisterPublisherResponse;
49  import org.oasis_open.docs.wsn.brw_2.*;
50  import org.miloss.fgsms.wsn.WSNConstants;
51  
52  
53  
54  
55  /**
56   *
57   * @author Administrator
58   */
59  							    
60  @WebService(name = "NotificationBroker", targetNamespace = "http://docs.oasis-open.org/wsn/brw-2", serviceName = "NotificationService", portName = "NotificationPort"
61  ,wsdlLocation = "brw-2impl.wsdl")
62  @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
63  public class WSNotificationBroker implements org.oasis_open.docs.wsn.brw_2.NotificationBroker
64  {
65  
66     
67      private DatatypeFactory df = null;
68      @Resource
69      private WebServiceContext ctx;
70      final static Logger log = Logger.getLogger("WS-NotificationBroker");
71  
72      public WSNotificationBroker() throws DatatypeConfigurationException {
73          df = DatatypeFactory.newInstance();
74      }
75      
76      
77      /**
78       * 
79       * @param registerPublisherRequest
80       * @return
81       *     returns org.oasis_open.docs.wsn.br_2.RegisterPublisherResponse
82       * @throws PublisherRegistrationFailedFault
83       * @throws InvalidTopicExpressionFault
84       * @throws ResourceUnknownFault
85       * @throws TopicNotSupportedFault
86       * @throws UnacceptableInitialTerminationTimeFault
87       * @throws PublisherRegistrationRejectedFault
88       */
89      @WebMethod(operationName = "RegisterPublisher", action = "RegisterPublisher")
90      @WebResult(name = "RegisterPublisherResponse", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "RegisterPublisherResponse")
91      public RegisterPublisherResponse registerPublisher(
92          @WebParam(name = "RegisterPublisher", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "RegisterPublisherRequest")
93          RegisterPublisher registerPublisherRequest)
94          throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault, UnacceptableInitialTerminationTimeFault
95      {
96          return null;
97      }
98  
99      /**
100      * 
101      * @param subscribeRequest
102      * @return
103      *     returns org.oasis_open.docs.wsn.b_2.SubscribeResponse
104      * @throws ResourceUnknownFault
105      * @throws UnrecognizedPolicyRequestFault
106      * @throws InvalidTopicExpressionFault
107      * @throws InvalidFilterFault
108      * @throws InvalidProducerPropertiesExpressionFault
109      * @throws SubscribeCreationFailedFault
110      * @throws NotifyMessageNotSupportedFault
111      * @throws InvalidMessageContentExpressionFault
112      * @throws TopicExpressionDialectUnknownFault
113      * @throws UnsupportedPolicyRequestFault
114      * @throws TopicNotSupportedFault
115      * @throws UnacceptableInitialTerminationTimeFault
116      */
117     @WebMethod(operationName = "Subscribe", action = "Subscribe")
118     @WebResult(name = "SubscribeResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "SubscribeResponse")
119     public SubscribeResponse subscribe(
120             @WebParam(name = "Subscribe", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "SubscribeRequest") Subscribe subscribeRequest)
121             throws InvalidFilterFault, InvalidMessageContentExpressionFault, InvalidProducerPropertiesExpressionFault,
122             InvalidTopicExpressionFault, NotifyMessageNotSupportedFault, ResourceUnknownFault, SubscribeCreationFailedFault,
123             TopicExpressionDialectUnknownFault, TopicNotSupportedFault, UnacceptableInitialTerminationTimeFault,
124             UnrecognizedPolicyRequestFault, UnsupportedPolicyRequestFault {
125         //authorize client
126         //validate request
127         if (subscribeRequest.getFilter() == null || subscribeRequest.getFilter().getAny().isEmpty()) {
128             InvalidFilterFault iff = new InvalidFilterFault("at least one filter of WS-Topic must be specified", new InvalidFilterFaultType());
129             throw iff;
130         }
131         for (int i = 0; i < subscribeRequest.getFilter().getAny().size(); i++) {
132 
133             if (!(subscribeRequest.getFilter().getAny().get(i) instanceof JAXBElement)) {
134 
135                 InvalidFilterFault iff = new InvalidFilterFault("All filters must be of type " + WSNConstants.WST_TOPICEXPRESSION_SIMPLE, new InvalidFilterFaultType());
136                 throw iff;
137             } else {
138                 JAXBElement<TopicExpressionType> item = (JAXBElement<TopicExpressionType>) subscribeRequest.getFilter().getAny().get(i);
139                 org.oasis_open.docs.wsn.b_2.TopicExpressionType te = item.getValue();
140                 if (!te.getDialect().equalsIgnoreCase(WSNConstants.WST_TOPICEXPRESSION_SIMPLE)) {
141                     InvalidFilterFault iff = new InvalidFilterFault("Only TopicExpressions with the dialect of " + WSNConstants.WST_TOPICEXPRESSION_SIMPLE + " are supported.", new InvalidFilterFaultType());
142                     throw iff;
143                 }
144             }
145         }
146         W3CEndpointReferenceBuilder b = new W3CEndpointReferenceBuilder();
147         if (subscribeRequest.getConsumerReference() == null) {
148             SubscribeCreationFailedFault iff = new SubscribeCreationFailedFault("Invalid callback address.", new SubscribeCreationFailedFaultType());
149             throw iff;
150         }
151 
152 
153         SingletonBroker.getInstance();
154         String AddSubscription = SingletonBroker.AddSubscription(subscribeRequest);
155         SubscribeResponse res = new SubscribeResponse();
156 
157         b.address("SubscriptionId:" + AddSubscription);
158         res.setSubscriptionReference(b.build());
159         GregorianCalendar gcal = new GregorianCalendar();
160         gcal.setTimeInMillis(System.currentTimeMillis());
161         res.setCurrentTime(df.newXMLGregorianCalendar(gcal));
162         return res;
163     }
164 
165     /**
166      * 
167      * @param getCurrentMessageRequest
168      * @return
169      *     returns org.oasis_open.docs.wsn.b_2.GetCurrentMessageResponse
170      * @throws ResourceUnknownFault
171      * @throws InvalidTopicExpressionFault
172      * @throws MultipleTopicsSpecifiedFault
173      * @throws TopicExpressionDialectUnknownFault
174      * @throws TopicNotSupportedFault
175      * @throws NoCurrentMessageOnTopicFault
176      */
177     @WebMethod(operationName = "GetCurrentMessage", action = "GetCurrentMessage")
178     @WebResult(name = "GetCurrentMessageResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "GetCurrentMessageResponse")
179     public GetCurrentMessageResponse getCurrentMessage(
180             @WebParam(name = "GetCurrentMessage", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "GetCurrentMessageRequest") GetCurrentMessage getCurrentMessageRequest)
181             throws InvalidTopicExpressionFault, MultipleTopicsSpecifiedFault, NoCurrentMessageOnTopicFault, ResourceUnknownFault, TopicExpressionDialectUnknownFault, TopicNotSupportedFault {
182         //not sure what this is used for. i can only see it being using for pull points
183         
184         return null;
185     }
186 
187   
188     
189     
190 
191     /**
192      * 
193      * @param notify
194      */
195     @WebMethod(operationName = "Notify", action = "Notify")
196     @Oneway
197     public void notify(
198             @WebParam(name = "Notify", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "Notify") Notify notify) {
199         //authorize client
200 
201         //inbound notification
202         SingletonBroker.getInstance();
203         SingletonBroker.Dispatch(notify);
204 
205     }
206 
207     
208     
209     
210     
211     
212     //TODO modify the WSN spec to include,,,,
213     //we really need a GetMySubscriptions if supporting pause, resume and renew
214 
215     
216     
217 
218 
219 }