Class: VertxWeb::RoutingContext
- Inherits:
-
Object
- Object
- VertxWeb::RoutingContext
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb
Overview
A new instance is created for each HTTP request that is received in the VertxWeb::Router#accept of the router.
The same instance is passed to any matching request or failure handlers during the routing of the request or failure.
The context provides access to the Vertx::HttpServerRequest and Vertx::HttpServerResponse and allows you to maintain arbitrary data that lives for the lifetime of the context. Contexts are discarded once they have been routed to the handler for the request.
The context also provides access to the Session, cookies and body for the request, given the correct handlers in the application.
Instance Method Summary (collapse)
-
- (Fixnum) add_body_end_handler { ... }
Add a handler that will be called just before the response body has been completely written.
-
- (self) add_cookie(cookie = nil)
Add a cookie.
-
- (Fixnum) add_headers_end_handler { ... }
Add a handler that will be called just before headers are written to the response.
-
- (void) clear_user
Clear the current user object in the context.
-
- (Fixnum) cookie_count
@return the number of cookies.
-
- (Set<::VertxWeb::Cookie>) cookies
@return a set of all the cookies.
-
- (::VertxWeb::Route) current_route
@return the current route this context is being routed through.
-
- (void) fail(statusCode = nil)
Fail the context with the specified status code.
-
- (true, false) failed?
@return true if the context is being routed to failure handlers.
-
- (Set<::VertxWeb::FileUpload>) file_uploads
@return a set of fileuploads (if any) for the request.
-
- (Object) get(key = nil)
Get some data from the context.
-
- (String) get_acceptable_content_type
If the route specifies produces matches, e.g.
-
- (::Vertx::Buffer) get_body
@return Get the entire HTTP request body as a Vertx::Buffer.
-
- (Hash{String => Object}) get_body_as_json
@return Get the entire HTTP request body as a => Object}.
-
- (String) get_body_as_string(encoding = nil)
Get the entire HTTP request body as a string, assuming the specified encoding.
-
- (::VertxWeb::Cookie) get_cookie(name = nil)
Get the cookie with the specified name.
-
- (String) mount_point
@return the mount point for this router.
-
- (void) next
Tell the router to route this context to the next matching route (if any).
-
- (String) normalised_path
Return the normalised path for the request.
-
- (self) put(key = nil, obj = nil)
Put some arbitrary data in the context.
-
- (true, false) remove_body_end_handler?(handlerID = nil)
Remove a body end handler.
-
- (::VertxWeb::Cookie) remove_cookie(name = nil)
Remove a cookie.
-
- (true, false) remove_headers_end_handler?(handlerID = nil)
Remove a headers end handler.
-
- (::Vertx::HttpServerRequest) request
@return the HTTP request object.
-
- (::Vertx::HttpServerResponse) response
@return the HTTP response object.
-
- (::VertxWeb::Session) session
Get the session.
-
- (void) set_acceptable_content_type(contentType = nil)
Set the acceptable content type.
-
- (void) set_body(body = nil)
Set the body.
-
- (void) set_session(session = nil)
Set the session.
-
- (void) set_user(user = nil)
Set the user.
-
- (Fixnum) status_code
If the context is being routed to failure handlers after a failure has been triggered by calling #fail then this will return that status code.
-
- (::VertxAuthCommon::User) user
Get the authenticated user (if any).
-
- (::Vertx::Vertx) vertx
@return the Vert.x instance associated to the initiating Router for this context.
Instance Method Details
- (Fixnum) add_body_end_handler { ... }
301 302 303 304 305 306 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 301 def add_body_end_handler if block_given? return @j_del.java_method(:addBodyEndHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) end raise ArgumentError, "Invalid arguments when calling add_body_end_handler()" end |
- (self) add_cookie(cookie = nil)
162 163 164 165 166 167 168 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 162 def (=nil) if .class.method_defined?(:j_del) && !block_given? @j_del.java_method(:addCookie, [Java::IoVertxExtWeb::Cookie.java_class]).call(.j_del) return self end raise ArgumentError, "Invalid arguments when calling add_cookie(cookie)" end |
- (Fixnum) add_headers_end_handler { ... }
282 283 284 285 286 287 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 282 def add_headers_end_handler if block_given? return @j_del.java_method(:addHeadersEndHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Future)) })) end raise ArgumentError, "Invalid arguments when calling add_headers_end_handler()" end |
- (void) clear_user
This method returns an undefined value.
Clear the current user object in the context. This usually is used for implementing a log out feature, since the current user is unbounded from the routing context.
354 355 356 357 358 359 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 354 def clear_user if !block_given? return @j_del.java_method(:clearUser, []).call() end raise ArgumentError, "Invalid arguments when calling clear_user()" end |
- (Fixnum) cookie_count
182 183 184 185 186 187 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 182 def if !block_given? return @j_del.java_method(:cookieCount, []).call() end raise ArgumentError, "Invalid arguments when calling cookie_count()" end |
- (Set<::VertxWeb::Cookie>) cookies
191 192 193 194 195 196 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 191 def if !block_given? return ::Vertx::Util::Utils.to_set(@j_del.java_method(:cookies, []).call()).map! { |elt| ::Vertx::Util::Utils.safe_create(elt,::VertxWeb::Cookie) } end raise ArgumentError, "Invalid arguments when calling cookies()" end |
- (::VertxWeb::Route) current_route
124 125 126 127 128 129 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 124 def current_route if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:currentRoute, []).call(),::VertxWeb::Route) end raise ArgumentError, "Invalid arguments when calling current_route()" end |
- (void) fail(statusCode = nil)
This method returns an undefined value.
Fail the context with the specified status code.This will cause the router to route the context to any matching failure handlers for the request. If no failure handlers match a default failure response will be sent.
79 80 81 82 83 84 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 79 def fail(statusCode=nil) if statusCode.class == Fixnum && !block_given? return @j_del.java_method(:fail, [Java::int.java_class]).call(statusCode) end raise ArgumentError, "Invalid arguments when calling fail(statusCode)" end |
- (true, false) failed?
318 319 320 321 322 323 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 318 def failed? if !block_given? return @j_del.java_method(:failed, []).call() end raise ArgumentError, "Invalid arguments when calling failed?()" end |
- (Set<::VertxWeb::FileUpload>) file_uploads
230 231 232 233 234 235 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 230 def file_uploads if !block_given? return ::Vertx::Util::Utils.to_set(@j_del.java_method(:fileUploads, []).call()).map! { |elt| ::Vertx::Util::Utils.safe_create(elt,::VertxWeb::FileUpload) } end raise ArgumentError, "Invalid arguments when calling file_uploads()" end |
- (Object) get(key = nil)
99 100 101 102 103 104 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 99 def get(key=nil) if key.class == String && !block_given? return ::Vertx::Util::Utils.from_object(@j_del.java_method(:get, [Java::java.lang.String.java_class]).call(key)) end raise ArgumentError, "Invalid arguments when calling get(key)" end |
- (String) get_acceptable_content_type
270 271 272 273 274 275 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 270 def get_acceptable_content_type if !block_given? return @j_del.java_method(:getAcceptableContentType, []).call() end raise ArgumentError, "Invalid arguments when calling get_acceptable_content_type()" end |
- (::Vertx::Buffer) get_body
221 222 223 224 225 226 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 221 def get_body if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:getBody, []).call(),::Vertx::Buffer) end raise ArgumentError, "Invalid arguments when calling get_body()" end |
- (Hash{String => Object}) get_body_as_json
212 213 214 215 216 217 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 212 def get_body_as_json if !block_given? return @j_del.java_method(:getBodyAsJson, []).call() != nil ? JSON.parse(@j_del.java_method(:getBodyAsJson, []).call().encode) : nil end raise ArgumentError, "Invalid arguments when calling get_body_as_json()" end |
- (String) get_body_as_string(encoding = nil)
201 202 203 204 205 206 207 208 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 201 def get_body_as_string(encoding=nil) if !block_given? && encoding == nil return @j_del.java_method(:getBodyAsString, []).call() elsif encoding.class == String && !block_given? return @j_del.java_method(:getBodyAsString, [Java::java.lang.String.java_class]).call(encoding) end raise ArgumentError, "Invalid arguments when calling get_body_as_string(encoding)" end |
- (::VertxWeb::Cookie) get_cookie(name = nil)
152 153 154 155 156 157 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 152 def (name=nil) if name.class == String && !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:getCookie, [Java::java.lang.String.java_class]).call(name),::VertxWeb::Cookie) end raise ArgumentError, "Invalid arguments when calling get_cookie(name)" end |
- (String) mount_point
116 117 118 119 120 121 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 116 def mount_point if !block_given? return @j_del.java_method(:mountPoint, []).call() end raise ArgumentError, "Invalid arguments when calling mount_point()" end |
- (void) next
This method returns an undefined value.
Tell the router to route this context to the next matching route (if any). This method, if called, does not need to be called during the execution of the handler, it can be called some arbitrary time later, if required.If next is not called for a handler then the handler should make sure it ends the response or no response will be sent.
67 68 69 70 71 72 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 67 def next if !block_given? return @j_del.java_method(:next, []).call() end raise ArgumentError, "Invalid arguments when calling next()" end |
- (String) normalised_path
The normalised path is where the URI path has been decoded, i.e. any unicode or other illegal URL characters that were encoded in the original URL with `%` will be returned to their original form. E.g. `%20` will revert to a space. Also `+` reverts to a space in a query.
The normalised path will also not contain any `..` character sequences to prevent resources being accessed outside of the permitted area.
It's recommended to always use the normalised path as opposed to Vertx::HttpServerRequest#path if accessing server resources requested by a client.
142 143 144 145 146 147 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 142 def normalised_path if !block_given? return @j_del.java_method(:normalisedPath, []).call() end raise ArgumentError, "Invalid arguments when calling normalised_path()" end |
- (self) put(key = nil, obj = nil)
89 90 91 92 93 94 95 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 89 def put(key=nil,obj=nil) if key.class == String && (obj.class == String || obj.class == Hash || obj.class == Array || obj.class == NilClass || obj.class == TrueClass || obj.class == FalseClass || obj.class == Fixnum || obj.class == Float) && !block_given? @j_del.java_method(:put, [Java::java.lang.String.java_class,Java::java.lang.Object.java_class]).call(key,::Vertx::Util::Utils.to_object(obj)) return self end raise ArgumentError, "Invalid arguments when calling put(key,obj)" end |
- (true, false) remove_body_end_handler?(handlerID = nil)
310 311 312 313 314 315 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 310 def remove_body_end_handler?(handlerID=nil) if handlerID.class == Fixnum && !block_given? return @j_del.java_method(:removeBodyEndHandler, [Java::int.java_class]).call(handlerID) end raise ArgumentError, "Invalid arguments when calling remove_body_end_handler?(handlerID)" end |
- (::VertxWeb::Cookie) remove_cookie(name = nil)
173 174 175 176 177 178 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 173 def (name=nil) if name.class == String && !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:removeCookie, [Java::java.lang.String.java_class]).call(name),::VertxWeb::Cookie) end raise ArgumentError, "Invalid arguments when calling remove_cookie(name)" end |
- (true, false) remove_headers_end_handler?(handlerID = nil)
291 292 293 294 295 296 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 291 def remove_headers_end_handler?(handlerID=nil) if handlerID.class == Fixnum && !block_given? return @j_del.java_method(:removeHeadersEndHandler, [Java::int.java_class]).call(handlerID) end raise ArgumentError, "Invalid arguments when calling remove_headers_end_handler?(handlerID)" end |
- (::Vertx::HttpServerRequest) request
40 41 42 43 44 45 46 47 48 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 40 def request if !block_given? if @cached_request != nil return @cached_request end return @cached_request = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:request, []).call(),::Vertx::HttpServerRequest) end raise ArgumentError, "Invalid arguments when calling request()" end |
- (::Vertx::HttpServerResponse) response
51 52 53 54 55 56 57 58 59 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 51 def response if !block_given? if @cached_response != nil return @cached_response end return @cached_response = ::Vertx::Util::Utils.safe_create(@j_del.java_method(:response, []).call(),::Vertx::HttpServerResponse) end raise ArgumentError, "Invalid arguments when calling response()" end |
- (::VertxWeb::Session) session
240 241 242 243 244 245 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 240 def session if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:session, []).call(),::VertxWeb::Session) end raise ArgumentError, "Invalid arguments when calling session()" end |
- (void) set_acceptable_content_type(contentType = nil)
This method returns an undefined value.
Set the acceptable content type. Used by
363 364 365 366 367 368 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 363 def set_acceptable_content_type(contentType=nil) if contentType.class == String && !block_given? return @j_del.java_method(:setAcceptableContentType, [Java::java.lang.String.java_class]).call(contentType) end raise ArgumentError, "Invalid arguments when calling set_acceptable_content_type(contentType)" end |
- (void) set_body(body = nil)
This method returns an undefined value.
Set the body. Used by the BodyHandler. You will not normally call this method.
327 328 329 330 331 332 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 327 def set_body(body=nil) if body.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:setBody, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(body.j_del) end raise ArgumentError, "Invalid arguments when calling set_body(body)" end |
- (void) set_session(session = nil)
This method returns an undefined value.
Set the session. Used by the SessionHandler. You will not normally call this method.
336 337 338 339 340 341 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 336 def set_session(session=nil) if session.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:setSession, [Java::IoVertxExtWeb::Session.java_class]).call(session.j_del) end raise ArgumentError, "Invalid arguments when calling set_session(session)" end |
- (void) set_user(user = nil)
This method returns an undefined value.
Set the user. Usually used by auth handlers to inject a User. You will not normally call this method.
345 346 347 348 349 350 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 345 def set_user(user=nil) if user.class.method_defined?(:j_del) && !block_given? return @j_del.java_method(:setUser, [Java::IoVertxExtAuth::User.java_class]).call(user.j_del) end raise ArgumentError, "Invalid arguments when calling set_user(user)" end |
- (Fixnum) status_code
258 259 260 261 262 263 264 265 266 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 258 def status_code if !block_given? if @cached_status_code != nil return @cached_status_code end return @cached_status_code = @j_del.java_method(:statusCode, []).call() end raise ArgumentError, "Invalid arguments when calling status_code()" end |
- (::VertxAuthCommon::User) user
248 249 250 251 252 253 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 248 def user if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:user, []).call(),::VertxAuthCommon::User) end raise ArgumentError, "Invalid arguments when calling user()" end |
- (::Vertx::Vertx) vertx
107 108 109 110 111 112 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-web/src/main/resources/vertx-web/routing_context.rb', line 107 def vertx if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:vertx, []).call(),::Vertx::Vertx) end raise ArgumentError, "Invalid arguments when calling vertx()" end |