Class: VertxWebClient::HttpRequestTemplate

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb

Overview

A template for configuring client-side HTTP requests.

Instances are created by an instance, via one of the methods createXXX corresponding to the specific HTTP methods.

The request template shall be configured prior making a request, the template is immutable and when a configuration method is called, a new template is returned allowing to expose the template and apply further customization.

After the request template has been configured, the methods

can be called.

The #bufferBody configures the template to buffer the entire HTTP response body and returns a HttpResponseTemplate for configuring the response body.

The send methods perform the actual request, they can be used multiple times to perform HTTP requests.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


40
41
42
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 40

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

+ (Object) j_api_type



49
50
51
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 49

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



52
53
54
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 52

def self.j_class
  Java::IoVertxWebclient::HttpRequestTemplate.java_class
end

+ (Object) unwrap(obj)



46
47
48
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 46

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

+ (Object) wrap(obj)



43
44
45
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 43

def @@j_api_type.wrap(obj)
  HttpRequestTemplate.new(obj)
end

Instance Method Details

- (::VertxWebClient::HttpResponseTemplate) buffer_body

Configure to buffer the body and returns a Buffer > for further configuration of the response or sending the request.

Returns:

Raises:

  • (ArgumentError)


156
157
158
159
160
161
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 156

def buffer_body
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:receiveBody, []).call(), ::VertxWebClient::HttpResponseTemplate, ::Vertx::Buffer.j_api_type)
  end
  raise ArgumentError, "Invalid arguments when calling buffer_body()"
end

- (::VertxWebClient::HttpRequestTemplate) host(value = nil)

Configure the template to use a new host value.

Parameters:

  • value (String) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)


76
77
78
79
80
81
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 76

def host(value=nil)
  if value.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:host, [Java::java.lang.String.java_class]).call(value),::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling host(#{value})"
end

- (::VertxWebClient::HttpRequestTemplate) method(value = nil)

Configure the template to use a new method value.

Parameters:

  • value (:OPTIONS, :GET, :HEAD, :POST, :PUT, :DELETE, :TRACE, :CONNECT, :PATCH, :OTHER) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)


58
59
60
61
62
63
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 58

def method(value=nil)
  if value.class == Symbol && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:method, [Java::IoVertxCoreHttp::HttpMethod.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(value)),::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling method(#{value})"
end

- (::VertxWebClient::HttpRequestTemplate) port(value = nil)

Configure the template to use a new port value.

Parameters:

  • value (Fixnum) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)


67
68
69
70
71
72
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 67

def port(value=nil)
  if value.class == Fixnum && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:port, [Java::int.java_class]).call(value),::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling port(#{value})"
end

- (::VertxWebClient::HttpRequestTemplate) put_header(name = nil, value = nil)

Configure the template to add a new HTTP header.

Parameters:

  • name (String) (defaults to: nil)
    the header name
  • value (String) (defaults to: nil)
    the header value

Returns:

Raises:

  • (ArgumentError)


95
96
97
98
99
100
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 95

def put_header(name=nil,value=nil)
  if name.class == String && value.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:putHeader, [Java::java.lang.String.java_class,Java::java.lang.String.java_class]).call(name,value),::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling put_header(#{name},#{value})"
end

- (::VertxWebClient::HttpRequestTemplate) request_uri(value = nil)

Configure the template to use a new request URI value.

Parameters:

  • value (String) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)


85
86
87
88
89
90
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 85

def request_uri(value=nil)
  if value.class == String && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:uri, [Java::java.lang.String.java_class]).call(value), ::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling request_uri(#{value})"
end

- (void) send { ... }

This method returns an undefined value.

Send a request, the handler will receive the response as an .

Yields:

Raises:

  • (ArgumentError)


147
148
149
150
151
152
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 147

def send
  if block_given?
    return @j_del.java_method(:send, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send()"
end

- (void) send_buffer(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body buffer.

Parameters:

Yields:

Raises:

  • (ArgumentError)


127
128
129
130
131
132
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 127

def send_buffer(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendBuffer, [Java::IoVertxCoreBuffer::Buffer.java_class, Java::IoVertxCore::Handler.java_class]).call(body.j_del, (Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result, ::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_buffer(#{body})"
end

- (void) send_json(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body object encoded as json and the content type set to application/json.

Parameters:

  • body (Object) (defaults to: nil)
    the body

Yields:

Raises:

  • (ArgumentError)


138
139
140
141
142
143
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 138

def send_json(body=nil)
  if ::Vertx::Util::unknown_type.accept?(body) && block_given?
    return @j_del.java_method(:sendJsonPOJO, [Java::java.lang.Object.java_class, Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_object(body), (Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result, ::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_json(#{body})"
end

- (void) send_stream(body = nil) { ... }

This method returns an undefined value.

Like #send but with an HTTP request body stream.

Parameters:

Yields:

Raises:

  • (ArgumentError)


117
118
119
120
121
122
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 117

def send_stream(body=nil)
  if body.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:sendStream, [Java::IoVertxCoreStreams::ReadStream.java_class,Java::IoVertxCore::Handler.java_class]).call(body.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxWebClient::HttpResponse, nil) : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling send_stream(#{body})"
end

- (::VertxWebClient::HttpRequestTemplate) timeout(value = nil)

Configures the amount of time in milliseconds after which if the request does not return any data within the timeout period an TimeoutException fails the request.

Setting zero or a negative value disables the timeout.

Parameters:

  • value (Fixnum) (defaults to: nil)
    The quantity of time in milliseconds.

Returns:

Raises:

  • (ArgumentError)


107
108
109
110
111
112
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-web-client/http_request_template.rb', line 107

def timeout(value=nil)
  if value.class == Fixnum && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:timeout, [Java::long.java_class]).call(value),::VertxWebClient::HttpRequestTemplate)
  end
  raise ArgumentError, "Invalid arguments when calling timeout(#{value})"
end