Class: VertxWeb::Route
- Inherits:
-
Object
show all
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb
Overview
A route is a holder for a set of criteria which determine whether an HTTP request or failure should be routed
to a handler.
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
-
- (self) blocking_handler(*args)
Specify a blocking request handler for the route.
-
- (self) consumes(contentType)
Add a content type consumed by this route.
-
- (self) disable
Disable this route.
-
- (self) enable
Enable this route.
-
- (self) failureHandler(failureHandler) { ... }
Append a failure handler to the route failure handlers list.
-
- (String) getPath
The path prefix (if any) for this route.
-
- (self) handler(requestHandler) { ... }
Append a request handler to the route handlers list.
-
- (self) last
Specify this is the last route for the router.
-
- (self) method(method)
Add an HTTP method for this route.
-
- (Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>) methods
The http methods accepted by this route.
-
- (self) order(order)
Specify the order for this route.
-
- (self) path(path)
Set the path prefix for this route.
-
- (self) pathRegex(path)
Set the path prefix as a regular expression.
-
- (self) produces(contentType)
Add a content type produced by this route.
-
- (true, false) isRegexPath
Returns true of the path is a regular expression, this includes expression paths.
-
- (self) remove
Remove this route from the router.
-
- (self) setRegexGroupsNames(groups)
When you add a new route with a regular expression, you can add named capture groups for parameters.
-
- (self) subRouter(subRouter)
Use a (sub)
Router as a handler.
-
- (self) useNormalisedPath(useNormalisedPath)
If true then the normalised request path will be used when routing (e.g. removing duplicate /) Default is true.
-
- (self) virtualHost(hostnamePattern)
Add a virtual host filter for this route.
Class Method Details
+ (Boolean) accept?(obj)
21
22
23
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 21
def @@j_api_type.accept?(obj)
obj.class == Route
end
|
+ (Object) j_api_type
30
31
32
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 30
def self.j_api_type
@@j_api_type
end
|
+ (Object) j_class
33
34
35
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 33
def self.j_class
Java::IoVertxExtWeb::Route.java_class
end
|
+ (Object) unwrap(obj)
27
28
29
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 27
def @@j_api_type.unwrap(obj)
obj.j_del
end
|
+ (Object) wrap(obj)
24
25
26
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 24
def @@j_api_type.wrap(obj)
Route.new(obj)
end
|
Instance Method Details
- (self) blockingHandler(requestHandler) { ... }
- (self) blockingHandler(requestHandler, ordered)
Specify a blocking request handler for the route.
This method works just like
#handler excepted that it will run the blocking handler on a worker thread
so that it won't block the event loop. Note that it's safe to call context.next() from the
blocking handler as it will be executed on the event loop context (and not on the worker thread.
If the blocking handler is ordered it means that any blocking handlers for the same context are never executed
concurrently but always in the order they were called. The default value of ordered is true. If you do not want this
behaviour and don't mind if your blocking handlers are executed in parallel you can set ordered to false.
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 279
def blocking_handler(*args)
if true && args[0] == nil && args[1] == nil
@j_del.java_method(:blockingHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) unless !block_given? }))
return self
elsif args[0].class == Proc && (args[1].class == TrueClass || args[1].class == FalseClass) && !block_given?
@j_del.java_method(:blockingHandler, [Java::IoVertxCore::Handler.java_class,Java::boolean.java_class]).call((Proc.new { |event| args[0].call(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) unless args[0] == nil }),args[1])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling blocking_handler(#{args[0]},#{args[1]})"
end
end
|
- (self) consumes(contentType)
Add a content type consumed by this route. Used for content based routing.
347
348
349
350
351
352
353
354
355
356
357
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 347
def consumes(*args)
if args[0].class == String && !block_given?
@j_del.java_method(:consumes, [Java::java.lang.String.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling consumes(#{args[0]})"
end
end
|
- (self) disable
Disable this route. While disabled the router will not route any requests or failures to it.
242
243
244
245
246
247
248
249
250
251
252
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 242
def disable
if !block_given?
@j_del.java_method(:disable, []).call()
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling disable()"
end
end
|
- (self) enable
228
229
230
231
232
233
234
235
236
237
238
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 228
def enable
if !block_given?
@j_del.java_method(:enable, []).call()
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling enable()"
end
end
|
- (self) failureHandler(failureHandler) { ... }
Append a failure handler to the route failure handlers list. The router routes failures to failurehandlers depending on whether the various
criteria such as method, path, etc match. When method, path, etc are the same for different routes, You should add multiple
failure handlers to the same route object rather than creating two different routes objects with one failure handler for route
42
43
44
45
46
47
48
49
50
51
52
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 42
def failure_handler
if true
@j_del.java_method(:failureHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) unless !block_given? }))
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling failure_handler()"
end
end
|
- (String) getPath
Returns the path prefix (if any) for this route
255
256
257
258
259
260
261
262
263
264
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 255
def get_path
if !block_given?
return @j_del.java_method(:getPath, []).call()
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling get_path()"
end
end
|
- (self) handler(requestHandler) { ... }
Append a request handler to the route handlers list. The router routes requests to handlers depending on whether the various
criteria such as method, path, etc match. When method, path, etc are the same for different routes, You should add multiple
handlers to the same route object rather than creating two different routes objects with one handler for route
59
60
61
62
63
64
65
66
67
68
69
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 59
def handler
if true
@j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxWeb::RoutingContext)) unless !block_given? }))
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling handler()"
end
end
|
- (self) last
Specify this is the last route for the router.
112
113
114
115
116
117
118
119
120
121
122
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 112
def last
if !block_given?
@j_del.java_method(:last, []).call()
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling last()"
end
end
|
- (self) method(method)
Add an HTTP method for this route. By default a route will match all HTTP methods. If any are specified then the route
will only match any of the specified methods
128
129
130
131
132
133
134
135
136
137
138
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 128
def method(*args)
if args[0].class == Symbol && !block_given?
@j_del.java_method(:method, [Java::IoVertxCoreHttp::HttpMethod.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(args[0].to_s))
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling method(#{args[0]})"
end
end
|
- (Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>) methods
Returns the http methods accepted by this route
141
142
143
144
145
146
147
148
149
150
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 141
def methods
if !block_given?
return ::Vertx::Util::Utils.to_set(@j_del.java_method(:methods, []).call()).map! { |elt| elt.name.intern }
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling methods()"
end
end
|
- (self) order(order)
Specify the order for this route. The router tests routes in that order.
332
333
334
335
336
337
338
339
340
341
342
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 332
def order(*args)
if args[0].class == Fixnum && !block_given?
@j_del.java_method(:order, [Java::int.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling order(#{args[0]})"
end
end
|
- (self) path(path)
Set the path prefix for this route. If set then this route will only match request URI paths which start with this
path prefix. Only a single path or path regex can be set for a route.
214
215
216
217
218
219
220
221
222
223
224
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 214
def path(*args)
if args[0].class == String && !block_given?
@j_del.java_method(:path, [Java::java.lang.String.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling path(#{args[0]})"
end
end
|
- (self) pathRegex(path)
Set the path prefix as a regular expression. If set then this route will only match request URI paths, the beginning
of which match the regex. Only a single path or path regex can be set for a route.
75
76
77
78
79
80
81
82
83
84
85
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 75
def path_regex(*args)
if args[0].class == String && !block_given?
@j_del.java_method(:pathRegex, [Java::java.lang.String.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling path_regex(#{args[0]})"
end
end
|
- (self) produces(contentType)
Add a content type produced by this route. Used for content based routing.
297
298
299
300
301
302
303
304
305
306
307
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 297
def produces(*args)
if args[0].class == String && !block_given?
@j_del.java_method(:produces, [Java::java.lang.String.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling produces(#{args[0]})"
end
end
|
- (true, false) isRegexPath
Returns true of the path is a regular expression, this includes expression paths.
170
171
172
173
174
175
176
177
178
179
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 170
def regex_path?
if !block_given?
return @j_del.java_method(:isRegexPath, []).call()
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling regex_path?()"
end
end
|
- (self) remove
Remove this route from the router
198
199
200
201
202
203
204
205
206
207
208
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 198
def remove
if !block_given?
@j_del.java_method(:remove, []).call()
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling remove()"
end
end
|
- (self) setRegexGroupsNames(groups)
When you add a new route with a regular expression, you can add named capture groups for parameters.
However, if you need more complex parameters names (like "param_name"), you can add parameters names with
this function. You have to name capture groups in regex with names: "p0", "p1", "p2", ...
For example: If you declare route with regex \/(?
[a-z]*)\/(?[a-z]*) and group names ["param_a", "param-b"]
for uri /hello/world you receive inside pathParams() the parameter param_a = "hello"
317
318
319
320
321
322
323
324
325
326
327
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 317
def set_regex_groups_names(*args)
if args[0].class == Array && !block_given?
@j_del.java_method(:setRegexGroupsNames, [Java::JavaUtil::List.java_class]).call(args[0].map { |element| element })
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling set_regex_groups_names(#{args[0]})"
end
end
|
- (self) subRouter(subRouter)
Use a (sub)
VertxWeb::Router as a handler. There are several requirements to be fulfilled for this
to be accepted.
- The route path must end with a wild card
- Parameters are allowed but full regex patterns not
- No other handler can be registered before or after this call (but they can on a new route object for the same path)
- Only 1 router per path object
98
99
100
101
102
103
104
105
106
107
108
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 98
def sub_router(*args)
if args[0].class.method_defined?(:j_del) && !block_given?
@j_del.java_method(:subRouter, [Java::IoVertxExtWeb::Router.java_class]).call(args[0].j_del)
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling sub_router(#{args[0]})"
end
end
|
- (self) useNormalisedPath(useNormalisedPath)
If true then the normalised request path will be used when routing (e.g. removing duplicate /)
Default is true
156
157
158
159
160
161
162
163
164
165
166
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 156
def use_normalised_path(*args)
if (args[0].class == TrueClass || args[0].class == FalseClass) && !block_given?
@j_del.java_method(:useNormalisedPath, [Java::boolean.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling use_normalised_path(#{args[0]})"
end
end
|
- (self) virtualHost(hostnamePattern)
Add a virtual host filter for this route.
184
185
186
187
188
189
190
191
192
193
194
|
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 184
def virtual_host(*args)
if args[0].class == String && !block_given?
@j_del.java_method(:virtualHost, [Java::java.lang.String.java_class]).call(args[0])
return self
end
if defined?(super)
super
else
raise ArgumentError, "Invalid arguments when calling virtual_host(#{args[0]})"
end
end
|