1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.message;
17
18 import java.net.URI;
19 import java.net.URL;
20 import java.net.URISyntaxException;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.Locale;
24
25
26
27
28
29
30 public class UpnpRequest extends UpnpOperation {
31
32 public static enum Method {
33
34 GET("GET"),
35 POST("POST"),
36 NOTIFY("NOTIFY"),
37 MSEARCH("M-SEARCH"),
38 SUBSCRIBE("SUBSCRIBE"),
39 UNSUBSCRIBE("UNSUBSCRIBE"),
40 UNKNOWN("UNKNOWN");
41
42 private static Map<String, Method> byName = new HashMap<String, Method>() {{
43 for (Method m : Method.values()) {
44 put(m.getHttpName(), m);
45 }
46 }};
47
48 private String httpName;
49
50 Method(String httpName) {
51 this.httpName = httpName;
52 }
53
54 public String getHttpName() {
55 return httpName;
56 }
57
58 public static Method getByHttpName(String httpName) {
59 if (httpName == null) return UNKNOWN;
60 Method m = byName.get(httpName.toUpperCase(Locale.ROOT));
61 return m != null ? m : UNKNOWN;
62 }
63 }
64
65 private Method method;
66 private URI uri;
67
68 public UpnpRequest(Method method) {
69 this.method = method;
70 }
71
72 public UpnpRequest(Method method, URI uri) {
73 this.method = method;
74 this.uri = uri;
75 }
76
77 public UpnpRequest(Method method, URL url) {
78 this.method = method;
79 try {
80 if (url != null) {
81 this.uri = url.toURI();
82 }
83 } catch (URISyntaxException e) {
84 throw new IllegalArgumentException(e);
85 }
86 }
87
88 public Method getMethod() {
89 return method;
90 }
91
92 public String getHttpMethodName() {
93 return method.getHttpName();
94 }
95
96 public URI getURI() {
97 return uri;
98 }
99
100 public void setUri(URI uri) {
101 this.uri = uri;
102 }
103
104 @Override
105 public String toString() {
106 return getHttpMethodName() + (getURI() != null ? " " + getURI() : "");
107 }
108 }