1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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
80
81
82
83
84
85
86
87
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
126
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
168
169
170
171
172
173
174
175
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
183
184 return null;
185 }
186
187
188
189
190
191
192
193
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
200
201
202 SingletonBroker.getInstance();
203 SingletonBroker.Dispatch(notify);
204
205 }
206
207
208
209
210
211
212
213
214
215
216
217
218
219 }