Class: VertxWeb::Route

Inherits:
Object
  • 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)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


20
21
22
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 20

def @@j_api_type.accept?(obj)
  obj.class == Route
end

+ (Object) j_api_type



29
30
31
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 29

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



32
33
34
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 32

def self.j_class
  Java::IoVertxExtWeb::Route.java_class
end

+ (Object) unwrap(obj)



26
27
28
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 26

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



23
24
25
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 23

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.

Overloads:

  • - (self) blockingHandler(requestHandler) { ... }

    Yields:

  • - (self) blockingHandler(requestHandler, ordered)

    Parameters:

    • requestHandler (Proc)
      the blocking request handler
    • ordered (true, false)
      if true handlers are executed in sequence, otherwise are run in parallel

Returns:

  • (self)


242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 242

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.

Parameters:

  • contentType (String)
    the content type

Returns:

  • (self)


310
311
312
313
314
315
316
317
318
319
320
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 310

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.

Returns:

  • (self)


205
206
207
208
209
210
211
212
213
214
215
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 205

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

Enable this route.

Returns:

  • (self)


191
192
193
194
195
196
197
198
199
200
201
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 191

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

Yields:

  • the request handler

Returns:

  • (self)


41
42
43
44
45
46
47
48
49
50
51
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 41

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

Returns:

  • (String)
    the path prefix (if any) for this route


218
219
220
221
222
223
224
225
226
227
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 218

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

Yields:

  • the request handler

Returns:

  • (self)


58
59
60
61
62
63
64
65
66
67
68
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 58

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.

Returns:

  • (self)


88
89
90
91
92
93
94
95
96
97
98
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 88

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

Parameters:

  • method (:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT, :PATCH, :OTHER)
    the HTTP method to add

Returns:

  • (self)


104
105
106
107
108
109
110
111
112
113
114
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 104

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

Returns:

  • (Set<:OPTIONS,:GET,:HEAD,:POST,:PUT,:DELETE,:TRACE,:CONNECT,:PATCH,:OTHER>)
    the http methods accepted by this route


117
118
119
120
121
122
123
124
125
126
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 117

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.

Parameters:

  • order (Fixnum)
    the order

Returns:

  • (self)


295
296
297
298
299
300
301
302
303
304
305
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 295

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.

Parameters:

  • path (String)
    the path prefix

Returns:

  • (self)


177
178
179
180
181
182
183
184
185
186
187
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 177

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.

Parameters:

  • path (String)
    the path regex

Returns:

  • (self)


74
75
76
77
78
79
80
81
82
83
84
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 74

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.

Parameters:

  • contentType (String)
    the content type

Returns:

  • (self)


260
261
262
263
264
265
266
267
268
269
270
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 260

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

- (self) remove

Remove this route from the router

Returns:

  • (self)


161
162
163
164
165
166
167
168
169
170
171
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 161

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"

Parameters:

  • groups (Array<String>)
    group names

Returns:

  • (self)


280
281
282
283
284
285
286
287
288
289
290
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 280

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) useNormalisedPath(useNormalisedPath)

If true then the normalised request path will be used when routing (e.g. removing duplicate /) Default is true

Parameters:

  • useNormalisedPath (true, false)
    use normalised path for routing?

Returns:

  • (self)


132
133
134
135
136
137
138
139
140
141
142
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 132

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.

Parameters:

  • hostnamePattern (String)
    the hostname pattern that should match Host header of the requests

Returns:

  • (self)


147
148
149
150
151
152
153
154
155
156
157
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/route.rb', line 147

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