Class: VertxApex::Router

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb

Overview

A router receives request from an Vertx::HttpServer and routes it to the first matching Route that it contains. A router can contain many routes.

Routers are also used for routing failures.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (::VertxApex::Router) router(vertx = nil)

Create a router

Parameters:

  • vertx (::Vertx::Vertx) (defaults to: nil)
    the Vert.x instance

Returns:

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 25

def self.router(vertx=nil)
  if vertx.class.method_defined?(:j_del) && !block_given?
    return ::VertxApex::Router.new(Java::IoVertxExtApex::Router.java_method(:router, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del))
  end
  raise ArgumentError, "Invalid arguments when calling router(vertx)"
end

Instance Method Details

- (void) accept(request = nil)

This method returns an undefined value.

This method is used to provide a request to the router. Usually you take request from the Vertx::HttpServer#request_handler and pass it to this method. The router then routes it to matching routes.

Parameters:

  • request (::Vertx::HttpServerRequest) (defaults to: nil)
    the request

Raises:

  • (ArgumentError)


36
37
38
39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 36

def accept(request=nil)
  if request.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:accept, [Java::IoVertxCoreHttp::HttpServerRequest.java_class]).call(request.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling accept(request)"
end

- (self) clear

Remove all the routes from this router

Returns:

  • (self)

Raises:

  • (ArgumentError)


205
206
207
208
209
210
211
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 205

def clear
  if !block_given?
    @j_del.java_method(:clear, []).call()
    return self
  end
  raise ArgumentError, "Invalid arguments when calling clear()"
end

- (::VertxApex::Route) delete(path = nil)

Add a route that matches a HTTP DELETE request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


178
179
180
181
182
183
184
185
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 178

def delete(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:delete, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:delete, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling delete(path)"
end

- (::VertxApex::Route) delete_with_regex(regex = nil)

Add a route that matches a HTTP DELETE request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


189
190
191
192
193
194
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 189

def delete_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:deleteWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling delete_with_regex(regex)"
end

- (self) exception_handler { ... }

Specify a handler for any unhandled exceptions on this router. The handler will be called for exceptions thrown from handlers. This does not affect the normal failure routing logic.

Yields:

  • the exception handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


227
228
229
230
231
232
233
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 227

def exception_handler
  if block_given?
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling exception_handler()"
end

- (::VertxApex::Route) get(path = nil)

Add a route that matches a HTTP GET request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


78
79
80
81
82
83
84
85
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 78

def get(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:get, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:get, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling get(path)"
end

- (Array<::VertxApex::Route>) get_routes

@return a list of all the routes on this router

Returns:

Raises:

  • (ArgumentError)


197
198
199
200
201
202
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 197

def get_routes
  if !block_given?
    return @j_del.java_method(:getRoutes, []).call().to_a.map { |elt| ::VertxApex::Route.new(elt) }
  end
  raise ArgumentError, "Invalid arguments when calling get_routes()"
end

- (::VertxApex::Route) get_with_regex(regex = nil)

Add a route that matches a HTTP GET request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


89
90
91
92
93
94
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 89

def get_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:getWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling get_with_regex(regex)"
end

- (void) handle_context(context = nil)

This method returns an undefined value.

Used to route a context to the router. Used for sub-routers. You wouldn't normally call this method directly.

Parameters:

Raises:

  • (ArgumentError)


237
238
239
240
241
242
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 237

def handle_context(context=nil)
  if context.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:handleContext, [Java::IoVertxExtApex::RoutingContext.java_class]).call(context.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling handle_context(context)"
end

- (void) handle_failure(context = nil)

This method returns an undefined value.

Used to route a failure to the router. Used for sub-routers. You wouldn't normally call this method directly.

Parameters:

Raises:

  • (ArgumentError)


246
247
248
249
250
251
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 246

def handle_failure(context=nil)
  if context.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:handleFailure, [Java::IoVertxExtApex::RoutingContext.java_class]).call(context.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling handle_failure(context)"
end

- (::VertxApex::Route) head(path = nil)

Add a route that matches a HTTP HEAD request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


98
99
100
101
102
103
104
105
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 98

def head(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:head, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:head, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling head(path)"
end

- (::VertxApex::Route) head_with_regex(regex = nil)

Add a route that matches a HTTP HEAD request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


109
110
111
112
113
114
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 109

def head_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:headWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling head_with_regex(regex)"
end

- (self) mount_sub_router(mountPoint = nil, subRouter = nil)

Mount a sub router on this router

Parameters:

  • mountPoint (String) (defaults to: nil)
    the mount point (path prefix) to mount it on
  • subRouter (::VertxApex::Router) (defaults to: nil)
    the router to mount as a sub router

Returns:

  • (self)

Raises:

  • (ArgumentError)


216
217
218
219
220
221
222
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 216

def mount_sub_router(mountPoint=nil,subRouter=nil)
  if mountPoint.class == String && subRouter.class.method_defined?(:j_del) && !block_given?
    @j_del.java_method(:mountSubRouter, [Java::java.lang.String.java_class,Java::IoVertxExtApex::Router.java_class]).call(mountPoint,subRouter.j_del)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling mount_sub_router(mountPoint,subRouter)"
end

- (::VertxApex::Route) options(path = nil)

Add a route that matches a HTTP OPTIONS request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


118
119
120
121
122
123
124
125
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 118

def options(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:options, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:options, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling options(path)"
end

- (::VertxApex::Route) options_with_regex(regex = nil)

Add a route that matches a HTTP OPTIONS request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


129
130
131
132
133
134
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 129

def options_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:optionsWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling options_with_regex(regex)"
end

- (::VertxApex::Route) post(path = nil)

Add a route that matches a HTTP POST request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


158
159
160
161
162
163
164
165
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 158

def post(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:post, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:post, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling post(path)"
end

- (::VertxApex::Route) post_with_regex(regex = nil)

Add a route that matches a HTTP POST request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


169
170
171
172
173
174
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 169

def post_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:postWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling post_with_regex(regex)"
end

- (::VertxApex::Route) put(path = nil)

Add a route that matches a HTTP PUT request and the specified path

Parameters:

  • path (String) (defaults to: nil)
    URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


138
139
140
141
142
143
144
145
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 138

def put(path=nil)
  if !block_given? && path == nil
    return ::VertxApex::Route.new(@j_del.java_method(:put, []).call())
  elsif path.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:put, [Java::java.lang.String.java_class]).call(path))
  end
  raise ArgumentError, "Invalid arguments when calling put(path)"
end

- (::VertxApex::Route) put_with_regex(regex = nil)

Add a route that matches a HTTP PUT request and the specified path regex

Parameters:

  • regex (String) (defaults to: nil)
    URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


149
150
151
152
153
154
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 149

def put_with_regex(regex=nil)
  if regex.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:putWithRegex, [Java::java.lang.String.java_class]).call(regex))
  end
  raise ArgumentError, "Invalid arguments when calling put_with_regex(regex)"
end

- (::VertxApex::Route) route - (::VertxApex::Route) route(path) - (::VertxApex::Route) route(method, path)

Add a route that matches the specified HTTP method and path

Overloads:

  • - (::VertxApex::Route) route(path)

    Parameters:

    • path (String)
      URI paths that begin with this path will match
  • - (::VertxApex::Route) route(method, path)

    Parameters:

    • method (:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT, :PATCH)
      the HTTP method to match
    • path (String)
      URI paths that begin with this path will match

Returns:

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 50

def route(param_1=nil,param_2=nil)
  if !block_given? && param_1 == nil && param_2 == nil
    return ::VertxApex::Route.new(@j_del.java_method(:route, []).call())
  elsif param_1.class == String && !block_given? && param_2 == nil
    return ::VertxApex::Route.new(@j_del.java_method(:route, [Java::java.lang.String.java_class]).call(param_1))
  elsif param_1.class == Symbol && param_2.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:route, [Java::IoVertxCoreHttp::HttpMethod.java_class,Java::java.lang.String.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(param_1),param_2))
  end
  raise ArgumentError, "Invalid arguments when calling route(param_1,param_2)"
end

- (::VertxApex::Route) routeWithRegex(regex) - (::VertxApex::Route) routeWithRegex(method, regex)

Add a route that matches the specified HTTP method and path regex

Overloads:

  • - (::VertxApex::Route) routeWithRegex(regex)

    Parameters:

    • regex (String)
      URI paths that begin with a match for this regex will match
  • - (::VertxApex::Route) routeWithRegex(method, regex)

    Parameters:

    • method (:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT, :PATCH)
      the HTTP method to match
    • regex (String)
      URI paths that begin with a match for this regex will match

Returns:

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
74
# File '/Users/julien/java/vertx-aggregator/modules/vertx-apex/src/main/resources/vertx-apex/router.rb', line 67

def route_with_regex(param_1=nil,param_2=nil)
  if param_1.class == String && !block_given? && param_2 == nil
    return ::VertxApex::Route.new(@j_del.java_method(:routeWithRegex, [Java::java.lang.String.java_class]).call(param_1))
  elsif param_1.class == Symbol && param_2.class == String && !block_given?
    return ::VertxApex::Route.new(@j_del.java_method(:routeWithRegex, [Java::IoVertxCoreHttp::HttpMethod.java_class,Java::java.lang.String.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(param_1),param_2))
  end
  raise ArgumentError, "Invalid arguments when calling route_with_regex(param_1,param_2)"
end