1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.message.control;
17
18 import org.fourthline.cling.model.action.ActionException;
19 import org.fourthline.cling.model.message.StreamRequestMessage;
20 import org.fourthline.cling.model.message.header.SoapActionHeader;
21 import org.fourthline.cling.model.message.header.UpnpHeader;
22 import org.fourthline.cling.model.meta.Action;
23 import org.fourthline.cling.model.meta.LocalService;
24 import org.fourthline.cling.model.meta.QueryStateVariableAction;
25 import org.fourthline.cling.model.types.ErrorCode;
26 import org.fourthline.cling.model.types.SoapActionType;
27
28
29
30
31 public class IncomingActionRequestMessage extends StreamRequestMessage implements ActionRequestMessage {
32
33 final private Action action;
34 final private String actionNamespace;
35
36 public IncomingActionRequestMessage(StreamRequestMessage source,
37 LocalService service) throws ActionException {
38 super(source);
39
40 SoapActionHeader soapActionHeader = getHeaders().getFirstHeader(UpnpHeader.Type.SOAPACTION, SoapActionHeader.class);
41 if (soapActionHeader == null) {
42 throw new ActionException(ErrorCode.INVALID_ACTION, "Missing SOAP action header");
43 }
44
45 SoapActionType actionType = soapActionHeader.getValue();
46
47 this.action = service.getAction(actionType.getActionName());
48 if (this.action == null) {
49 throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't implement action: " + actionType.getActionName());
50 }
51
52 if (!QueryStateVariableAction.ACTION_NAME.equals(actionType.getActionName())) {
53 if (!service.getServiceType().implementsVersion(actionType.getServiceType())) {
54 throw new ActionException(ErrorCode.INVALID_ACTION, "Service doesn't support the requested service version");
55 }
56 }
57
58 this.actionNamespace = actionType.getTypeString();
59 }
60
61 public Action getAction() {
62 return action;
63 }
64
65 public String getActionNamespace() {
66 return actionNamespace;
67 }
68
69 }