46
46
*/
47
47
public class SockJsHttpRequestHandler implements HttpRequestHandler , BeanFactoryAware {
48
48
49
+ private final String prefix ;
50
+
49
51
private final SockJsService sockJsService ;
50
52
51
53
private final HandlerProvider <SockJsHandler > handlerProvider ;
52
54
53
55
private final UrlPathHelper urlPathHelper = new UrlPathHelper ();
54
56
55
57
56
- public SockJsHttpRequestHandler (SockJsService sockJsService , SockJsHandler sockJsHandler ) {
58
+ /**
59
+ * Class constructor with {@link SockJsHandler} instance ...
60
+ *
61
+ * @param prefix the path prefix for the SockJS service. All requests with a path
62
+ * that begins with the specified prefix will be handled by this service. In a
63
+ * Servlet container this is the path within the current servlet mapping.
64
+ */
65
+ public SockJsHttpRequestHandler (String prefix , SockJsService sockJsService , SockJsHandler sockJsHandler ) {
66
+
67
+ Assert .hasText (prefix , "prefix is required" );
57
68
Assert .notNull (sockJsService , "sockJsService is required" );
58
69
Assert .notNull (sockJsHandler , "sockJsHandler is required" );
70
+
71
+ this .prefix = prefix ;
59
72
this .sockJsService = sockJsService ;
60
73
this .sockJsService .registerSockJsHandlers (Collections .singleton (sockJsHandler ));
61
74
this .handlerProvider = new HandlerProvider <SockJsHandler >(sockJsHandler );
62
75
}
63
76
64
- public SockJsHttpRequestHandler (SockJsService sockJsService , Class <? extends SockJsHandler > sockJsHandlerClass ) {
77
+ /**
78
+ * Class constructor with {@link SockJsHandler} type (per request) ...
79
+ *
80
+ * @param prefix the path prefix for the SockJS service. All requests with a path
81
+ * that begins with the specified prefix will be handled by this service. In a
82
+ * Servlet container this is the path within the current servlet mapping.
83
+ */
84
+ public SockJsHttpRequestHandler (String prefix , SockJsService sockJsService ,
85
+ Class <? extends SockJsHandler > sockJsHandlerClass ) {
86
+
87
+ Assert .hasText (prefix , "prefix is required" );
65
88
Assert .notNull (sockJsService , "sockJsService is required" );
66
89
Assert .notNull (sockJsHandlerClass , "sockJsHandlerClass is required" );
90
+
91
+ this .prefix = prefix ;
67
92
this .sockJsService = sockJsService ;
68
93
this .handlerProvider = new HandlerProvider <SockJsHandler >(sockJsHandlerClass );
69
94
}
70
95
71
- public String getMappingPattern () {
72
- return this .sockJsService .getPrefix () + "/**" ;
96
+ public String getPrefix () {
97
+ return this .prefix ;
98
+ }
99
+
100
+ public String getPattern () {
101
+ return this .prefix + "/**" ;
73
102
}
74
103
75
104
@ Override
@@ -82,10 +111,9 @@ public void handleRequest(HttpServletRequest request, HttpServletResponse respon
82
111
throws ServletException , IOException {
83
112
84
113
String lookupPath = this .urlPathHelper .getLookupPathForRequest (request );
85
- String prefix = this .sockJsService .getPrefix ();
86
114
87
- Assert .isTrue (lookupPath .startsWith (prefix ),
88
- "Request path does not match the prefix of the SockJsService " + prefix );
115
+ Assert .isTrue (lookupPath .startsWith (this . prefix ),
116
+ "Request path does not match the prefix of the SockJsService " + this . prefix );
89
117
90
118
String sockJsPath = lookupPath .substring (prefix .length ());
91
119
0 commit comments