1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.protocol.async;
17
18 import org.fourthline.cling.UpnpService;
19 import org.fourthline.cling.model.ValidationError;
20 import org.fourthline.cling.model.ValidationException;
21 import org.fourthline.cling.model.message.IncomingDatagramMessage;
22 import org.fourthline.cling.model.message.UpnpRequest;
23 import org.fourthline.cling.model.message.discovery.IncomingNotificationRequest;
24 import org.fourthline.cling.model.meta.RemoteDevice;
25 import org.fourthline.cling.model.meta.RemoteDeviceIdentity;
26 import org.fourthline.cling.model.types.UDN;
27 import org.fourthline.cling.protocol.ReceivingAsync;
28 import org.fourthline.cling.protocol.RetrieveRemoteDescriptors;
29 import org.fourthline.cling.transport.RouterException;
30
31 import java.util.logging.Logger;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public class ReceivingNotification extends ReceivingAsync<IncomingNotificationRequest> {
73
74 final private static Logger log = Logger.getLogger(ReceivingNotification.class.getName());
75
76 public ReceivingNotification(UpnpService upnpService, IncomingDatagramMessage<UpnpRequest> inputMessage) {
77 super(upnpService, new IncomingNotificationRequest(inputMessage));
78 }
79
80 protected void execute() throws RouterException {
81
82 UDN udn = getInputMessage().getUDN();
83 if (udn == null) {
84 log.fine("Ignoring notification message without UDN: " + getInputMessage());
85 return;
86 }
87
88 RemoteDeviceIdentity rdIdentity = new RemoteDeviceIdentity(getInputMessage());
89 log.fine("Received device notification: " + rdIdentity);
90
91 RemoteDevice rd;
92 try {
93 rd = new RemoteDevice(rdIdentity);
94 } catch (ValidationException ex) {
95 log.warning("Validation errors of device during discovery: " + rdIdentity);
96 for (ValidationError validationError : ex.getErrors()) {
97 log.warning(validationError.toString());
98 }
99 return;
100 }
101
102 if (getInputMessage().isAliveMessage()) {
103
104 log.fine("Received device ALIVE advertisement, descriptor location is: " + rdIdentity.getDescriptorURL());
105
106 if (rdIdentity.getDescriptorURL() == null) {
107 log.finer("Ignoring message without location URL header: " + getInputMessage());
108 return;
109 }
110
111 if (rdIdentity.getMaxAgeSeconds() == null) {
112 log.finer("Ignoring message without max-age header: " + getInputMessage());
113 return;
114 }
115
116 if (getUpnpService().getRegistry().update(rdIdentity)) {
117 log.finer("Remote device was already known: " + udn);
118 return;
119 }
120
121
122
123 getUpnpService().getConfiguration().getAsyncProtocolExecutor().execute(
124 new RetrieveRemoteDescriptors(getUpnpService(), rd)
125 );
126
127 } else if (getInputMessage().isByeByeMessage()) {
128
129 log.fine("Received device BYEBYE advertisement");
130 boolean removed = getUpnpService().getRegistry().removeDevice(rd);
131 if (removed) {
132 log.fine("Removed remote device from registry: " + rd);
133 }
134
135 } else {
136 log.finer("Ignoring unknown notification message: " + getInputMessage());
137 }
138
139 }
140
141
142 }