jubilee 2.1.0.beta-java → 2.1.0.rc1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +13 -1
  3. data/README.md +65 -54
  4. data/Rakefile +23 -21
  5. data/examples/chatapp/Gemfile +1 -2
  6. data/examples/chatapp/Gemfile.lock +2 -2
  7. data/examples/chatapp/README.md +14 -2
  8. data/examples/chatapp/app.rb +1 -0
  9. data/examples/chatapp/config.json +4 -0
  10. data/examples/chatapp/config.ru +0 -2
  11. data/jars/annotations-1.3.2.jar +0 -0
  12. data/jars/lang-jruby-2.1.0-final.jar +0 -0
  13. data/jars/log4j-1.2.16.jar +0 -0
  14. data/jars/slf4j-api-1.6.2.jar +0 -0
  15. data/jars/vertx-core-2.1.2.jar +0 -0
  16. data/jars/{vertx-hazelcast-2.1.1.jar → vertx-hazelcast-2.1.2.jar} +0 -0
  17. data/jars/{vertx-platform-2.1.1.jar → vertx-platform-2.1.2.jar} +0 -0
  18. data/lib/container.rb +117 -0
  19. data/lib/{vertx → core}/buffer.rb +1 -1
  20. data/lib/core/datagram.rb +280 -0
  21. data/lib/core/dns.rb +143 -0
  22. data/lib/{vertx → core}/event_bus.rb +79 -8
  23. data/lib/core/file_system.rb +479 -0
  24. data/lib/{vertx → core}/http.rb +635 -5
  25. data/lib/core/net.rb +251 -0
  26. data/lib/core/network_support.rb +77 -0
  27. data/lib/core/parsetools.rb +105 -0
  28. data/lib/{vertx → core}/shared_data.rb +2 -2
  29. data/lib/core/sock_js.rb +116 -0
  30. data/lib/{vertx → core}/ssl_support.rb +21 -1
  31. data/lib/{vertx → core}/streams.rb +32 -21
  32. data/lib/{vertx → core}/tcp_support.rb +22 -36
  33. data/lib/core/timers.rb +73 -0
  34. data/lib/core/vertx_require.rb +25 -0
  35. data/lib/{vertx → core}/wrapped_handler.rb +0 -0
  36. data/lib/jubilee.rb +5 -8
  37. data/lib/jubilee/cli.rb +1 -1
  38. data/lib/jubilee/jubilee.jar +0 -0
  39. data/lib/jubilee/jubilee_require.rb +24 -0
  40. data/lib/jubilee/version.rb +1 -1
  41. data/lib/test_utils.rb +66 -0
  42. data/lib/vertx.rb +13 -10
  43. data/lib/vertx_tests.rb +8 -0
  44. data/pom.xml +351 -0
  45. data/src/main/assembly/mod.xml +21 -0
  46. data/{java/src → src/main/java}/jubilee/JubileeService.java +0 -0
  47. data/{java/src → src/main/java}/org/jruby/jubilee/Const.java +0 -0
  48. data/{java/src → src/main/java}/org/jruby/jubilee/JubileeVerticle.java +12 -2
  49. data/src/main/java/org/jruby/jubilee/JubileeVerticleFactory.java +258 -0
  50. data/{java/src → src/main/java}/org/jruby/jubilee/RackApplication.java +3 -1
  51. data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironment.java +2 -2
  52. data/{java/src → src/main/java}/org/jruby/jubilee/RackEnvironmentHash.java +0 -0
  53. data/{java/src → src/main/java}/org/jruby/jubilee/RackInput.java +0 -0
  54. data/{java/src → src/main/java}/org/jruby/jubilee/RackResponse.java +0 -0
  55. data/{java/src → src/main/java}/org/jruby/jubilee/RubyCallable.java +0 -0
  56. data/{java/src → src/main/java}/org/jruby/jubilee/RubyHttpServerResponse.java +0 -0
  57. data/{java/src → src/main/java}/org/jruby/jubilee/RubyNetSocket.java +0 -0
  58. data/{java/src → src/main/java}/org/jruby/jubilee/RubyPlatformManager.java +0 -0
  59. data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyIORackInput.java +0 -0
  60. data/{java/src → src/main/java}/org/jruby/jubilee/impl/RubyNullIO.java +0 -0
  61. data/{java/src → src/main/java}/org/jruby/jubilee/utils/RubyHelper.java +0 -0
  62. data/{java/src → src/main/java}/org/jruby/jubilee/vertx/JubileeVertx.java +0 -0
  63. data/{java → src/main}/resources/META-INF/services/org.vertx.java.core.spi.cluster.ClusterManagerFactory +0 -0
  64. data/src/main/resources/META-INF/services/org.vertx.java.deploy.impl.jruby.JubileeVerticleFactory +1 -0
  65. data/{java → src/main}/resources/default-cluster.xml +0 -0
  66. data/src/main/resources/mod.json +11 -0
  67. data/test/jubilee/test_upload.rb +3 -1
  68. data/vertx_classpath.txt +12 -0
  69. metadata +69 -47
  70. data/Guardfile +0 -24
  71. data/jars/vertx-core-2.1.1.jar +0 -0
  72. data/java/src/org/jruby/jubilee/RubyChannel.java +0 -89
  73. data/lib/vertx/README.md +0 -7
@@ -12,12 +12,106 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- require 'vertx/streams'
16
- require 'vertx/ssl_support'
17
- require 'vertx/tcp_support'
18
- require 'vertx/wrapped_handler'
15
+ require 'core/streams'
16
+ require 'core/ssl_support'
17
+ require 'core/tcp_support'
18
+ require 'core/wrapped_handler'
19
19
 
20
20
  module Vertx
21
+
22
+ # An HTTP and WebSockets server
23
+ #
24
+ # @author {http://tfox.org Tim Fox}
25
+ class HttpServer
26
+
27
+ include SSLSupport, ServerSSLSupport, TCPSupport, ServerTCPSupport
28
+
29
+ # Letting the developer choose between compression? or compression while developing
30
+ #alias_method :compression?, :compression
31
+
32
+ # Create a new HttpServer.
33
+ # using an optional hash to configure the HttpServer on instantiation.
34
+ # @param [Hash] config an Hash of configurations.
35
+ def initialize(config = {})
36
+ @j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createHttpServer
37
+ self.compression = config[:compression] if config.has_key?(:compression)
38
+ self
39
+ end
40
+
41
+ # Set the HTTP request handler for the server.
42
+ # As HTTP requests arrive on the server a new {HttpServerRequest} instance will be created and passed to the handler.
43
+ # @param [Block] hndlr A block to be used as the handler
44
+ def request_handler(rm = nil, &hndlr)
45
+ if (rm && (rm.is_a? RouteMatcher))
46
+ @j_del.requestHandler { |j_del| rm.input(HttpServerRequest.new(j_del))}
47
+ else
48
+ @j_del.requestHandler { |j_del| hndlr.call(HttpServerRequest.new(j_del)) }
49
+ end
50
+ self
51
+ end
52
+
53
+ # Set the WebSocket handler for the server.
54
+ # As WebSocket requests arrive on the server and are accepted a new {WebSocket} instance will be created and
55
+ # passed to the handler.
56
+ # @param [Block] hndlr A block to be used as the handler
57
+ def websocket_handler(&hndlr)
58
+ @j_del.websocketHandler do |param|
59
+ hndlr.call(ServerWebSocket.new(param))
60
+ end
61
+ self
62
+ end
63
+
64
+ # Enables HTTP compression.
65
+ # exposes a = method to set or unset compression support.
66
+ # @param [Boolean] supported whether enable compression or not
67
+ def compression=(supported)
68
+ @j_del.setCompressionSupported(supported)
69
+ end
70
+
71
+ # Tests if compression is supported.
72
+ # @return [Boolean] true if compression is supported or false if it doesn't
73
+ def compression
74
+ @j_del.isCompressionSupported
75
+ end
76
+
77
+ # Letting the developer choose between compression? or compression while developing
78
+ alias_method :compression?, :compression
79
+
80
+ # Instruct the server to listen for incoming connections.
81
+ # @param [FixNum] port. The port to listen on.
82
+ # @param [FixNum] host. The host name or ip address to listen on.
83
+ # @param [Block] hndlr The handler will be called when the server is listening, or it failed to listen
84
+ def listen(port, host = "0.0.0.0", &hndlr)
85
+ @j_del.listen(port, host, ARWrappedHandler.new(hndlr) { |j_del| self })
86
+ end
87
+
88
+ # Close the server. The handler will be called when the close is complete.
89
+ def close(&hndlr)
90
+ if hndlr
91
+ @j_del.close(ARWrappedHandler.new(hndlr))
92
+ else
93
+ @j_del.close
94
+ end
95
+ end
96
+
97
+ # Gets the max WebSocket Frame size in bytes
98
+ # @return [int] Max WebSocket frame size
99
+ def max_websocket_frame_size
100
+ @j_del.getMaxWebSocketFrameSize
101
+ end
102
+
103
+ # Sets the maximum WebSocket frame size in bytes. Default is 65536 bytes.
104
+ # @param [int] size
105
+ def max_websocket_frame_size=(size)
106
+ @j_del.setMaxWebSocketFrameSize(size)
107
+ end
108
+
109
+ # @private
110
+ def _to_java_server
111
+ @j_del
112
+ end
113
+ end
114
+
21
115
  # An HTTP client.
22
116
  # A client maintains a pool of connections to a specific host, at a specific port. The HTTP connections can act
23
117
  # as pipelines for HTTP requests.
@@ -31,7 +125,7 @@ module Vertx
31
125
 
32
126
  # Create a new HttpClient
33
127
  def initialize(config = {})
34
- @j_del = org.jruby.jubilee.vertx.JubileeVertx.vertx().createHttpClient()
128
+ @j_del = org.vertx.java.platform.impl.JRubyVerticleFactory.vertx.createHttpClient
35
129
  self.compression = config[:try_compression] if config.has_key?(:try_compression)
36
130
  end
37
131
 
@@ -470,6 +564,277 @@ module Vertx
470
564
 
471
565
  end
472
566
 
567
+ # Encapsulates a server-side HTTP request.
568
+ #
569
+ # An instance of this class is created for each request that is handled by the server and is passed to the user via the
570
+ # handler specified using {HttpServer#request_handler}.
571
+ #
572
+ # Each instance of this class is associated with a corresponding {HttpServerResponse} instance via the field {#response}.
573
+ #
574
+ # @author {http://tfox.org Tim Fox}
575
+ class HttpServerRequest
576
+
577
+ include ReadStream
578
+
579
+ # @private
580
+ def initialize(j_del)
581
+ @j_del = j_del
582
+ @resp = HttpServerResponse.new(@j_del.response)
583
+ end
584
+
585
+ # @return [String] The Http version
586
+ def version
587
+ if !@vrsn
588
+ @vrsn = @j_del.version.toString
589
+ end
590
+ @vrsn
591
+ end
592
+
593
+ # @return [String] The HTTP method, one of HEAD, OPTIONS, GET, POST, PUT, DELETE, CONNECT, TRACE
594
+ def method
595
+ @j_del.method
596
+ end
597
+
598
+ # @return [String] The uri of the request. For example 'http://www.somedomain.com/somepath/somemorepath/somresource.foo?someparam=32&someotherparam=x'
599
+ def uri
600
+ @j_del.uri
601
+ end
602
+
603
+ # @return [String] The path part of the uri. For example /somepath/somemorepath/somresource.foo
604
+ def path
605
+ @j_del.path
606
+ end
607
+
608
+ # @return [String] The query part of the uri. For example someparam=32&someotherparam=x
609
+ def query
610
+ @j_del.query
611
+ end
612
+
613
+ # @return [MultiMap] The request parameters
614
+ def params
615
+ if !@params
616
+ @params = MultiMap.new(@j_del.params)
617
+ end
618
+ @params
619
+ end
620
+
621
+ # @return [HttpServerResponse] The response. Each instance of this class has an {HttpServerResponse} instance attached to it. This is used
622
+ # to send the response back to the client.
623
+ def response
624
+ @resp
625
+ end
626
+
627
+ # @return [MultiMap] The request headers
628
+ def headers
629
+ if !@headers
630
+ @headers = MultiMap.new(@j_del.headers)
631
+ end
632
+ @headers
633
+ end
634
+
635
+ # You must call this function with true before receiving the request body if you expect it to
636
+ # contain a multi-part form
637
+ def expect_multipart=(expect)
638
+ @j_del.expectMultiPart(expect)
639
+ self
640
+ end
641
+
642
+ # @return [MultiMap] Returns a map of all form attributes which was found in the request. Be aware that this
643
+ # message should only get
644
+ # called after the endHandler was notified as the map will be filled on-the-fly.
645
+ def form_attributes
646
+ if !@attrs
647
+ @attrs = MultiMap.new(@j_del.formAttributes)
648
+ end
649
+ @attrs
650
+ end
651
+
652
+ # Set the upload handler. The handler will get notified once a new file upload was received and so allow to
653
+ # get notified by the upload in progress.
654
+ def upload_handler(&hndlr)
655
+ @j_del.uploadHandler do |j_upload|
656
+ hndlr.call(HttpServerFileUpload.new(j_upload))
657
+ end
658
+ self
659
+ end
660
+
661
+ # Set a handler to receive the entire body in one go - do not use this for large bodies
662
+ def body_handler(&hndlr)
663
+ @j_del.bodyHandler(hndlr)
664
+ self
665
+ end
666
+
667
+ # Get the remote address
668
+ def remote_address
669
+ @j_del.remoteAddress
670
+ end
671
+
672
+ # Get the absolute URI
673
+ def absolute_uri
674
+ @j_del.absoluteURI
675
+ end
676
+
677
+ def _to_java_request
678
+ @j_del
679
+ end
680
+
681
+ end
682
+
683
+ # Encapsulates a server-side HTTP response.
684
+ #
685
+ # An instance of this class is created and associated to every instance of {HttpServerRequest} that is created.
686
+ #
687
+ # It allows the developer to control the HTTP response that is sent back to the client for the corresponding HTTP
688
+ # request. It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out
689
+ # to the response.
690
+ #
691
+ # @author {http://tfox.org Tim Fox}
692
+ class HttpServerResponse
693
+
694
+ include WriteStream
695
+
696
+ # @private
697
+ def initialize(j_del)
698
+ @j_del = j_del
699
+ end
700
+
701
+ def status_code=(val)
702
+ @j_del.setStatusCode(val)
703
+ end
704
+
705
+ # Get or set the status code
706
+ def status_code(val = nil)
707
+ if val
708
+ @j_del.setStatusCode(val)
709
+ self
710
+ else
711
+ @j_del.getStatusCode
712
+ end
713
+ end
714
+
715
+ # Set the status message
716
+ def status_message=(val)
717
+ @j_del.setStatusMessage(val)
718
+ end
719
+
720
+ # Get or set the status message
721
+ def status_message(val = nil)
722
+ if val
723
+ @j_del.setStatusMessage(val)
724
+ self
725
+ else
726
+ @j_del.getStatusMessage
727
+ end
728
+ end
729
+
730
+ # Sets whether this response uses HTTP chunked encoding or not.
731
+ # @param [Boolean] val. If val is true, this response will use HTTP chunked encoding, and each call to write to the body
732
+ # will correspond to a new HTTP chunk sent on the wire. If chunked encoding is used the HTTP header
733
+ # 'Transfer-Encoding' with a value of 'Chunked' will be automatically inserted in the response.
734
+ # If chunked is false, this response will not use HTTP chunked encoding, and therefore if any data is written the
735
+ # body of the response, the total size of that data must be set in the 'Content-Length' header before any
736
+ # data is written to the response body.
737
+ # An HTTP chunked response is typically used when you do not know the total size of the request body up front.
738
+ # @return [HttpServerResponse] self So multiple operations can be chained.
739
+ def chunked=(val)
740
+ @j_del.setChunked(val)
741
+ self
742
+ end
743
+
744
+ # Get or set chunked
745
+ def chunked(val = nil)
746
+ if val
747
+ @j_del.setChunked(val)
748
+ self
749
+ else
750
+ @j_del.getChunked
751
+ end
752
+ end
753
+
754
+ # @return [MultiMap] The response headers
755
+ def headers
756
+ if !@headers
757
+ @headers = MultiMap.new(@j_del.headers)
758
+ end
759
+ @headers
760
+ end
761
+
762
+ # Inserts a header into the response.
763
+ # @param [String] key The header key
764
+ # @param [Object] value The header value. to_s will be called on the value to determine the actual String value to insert.
765
+ # @return [HttpClientRequest] self So multiple operations can be chained.
766
+ def put_header(key, value)
767
+ @j_del.putHeader(key, value.to_s)
768
+ self
769
+ end
770
+
771
+ # Inserts a trailer into the response.
772
+ # @param [String] key The header key
773
+ # @param [Object] value The header value. to_s will be called on the value to determine the actual String value to insert.
774
+ # @return [HttpClientRequest] self So multiple operations can be chained.
775
+ def put_trailer(key, value)
776
+ @j_del.putTrailer(key, value.to_s)
777
+ self
778
+ end
779
+
780
+ # The response trailers
781
+ def trailers
782
+ if !@trailers
783
+ @trailers = MultiMap.new(@j_del.trailers)
784
+ end
785
+ @trailers
786
+ end
787
+
788
+ # Write a String to the response. The handler will be called when the String has actually been written to the wire.
789
+ # @param [String] str. The string to write
790
+ # @param [String] enc. Encoding to use.
791
+ # @return [HttpServerResponse] self So multiple operations can be chained.
792
+ def write_str(str, enc = "UTF-8")
793
+ @j_del.write(str, enc)
794
+ self
795
+ end
796
+
797
+ # Tell the kernel to stream a file directly from disk to the outgoing connection, bypassing user-space altogether
798
+ # (where supported by the underlying operating system. This is a very efficient way to serve files.
799
+ # @param [String] path. Path to file to send.
800
+ # @param [String] not_found_file Path to file containing 404 resource in case resource can't be found
801
+ # @return [HttpServerResponse] self So multiple operations can be chained.
802
+ def send_file(path, not_found_file = nil, &block)
803
+ if not_found_file.nil?
804
+ if block_given?
805
+ @j_del.sendFile(path, ARWrappedHandler.new(block))
806
+ else
807
+ @j_del.sendFile(path)
808
+ end
809
+ else
810
+ if block_given?
811
+ @j_del.sendFile(path, not_found_file, ARWrappendHandler.new(block))
812
+ else
813
+ @j_del.sendFile(path, not_found_file)
814
+ end
815
+ end
816
+ self
817
+ end
818
+
819
+ # Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called.
820
+ # Once the response has ended, it cannot be used any more, and if keep alive is true the underlying connection will
821
+ # be closed.
822
+ # @param [String,Buffer] data. Optional String or Buffer to write before ending the response
823
+ def end(data = nil)
824
+ if (data.is_a? String) || (data.is_a? Buffer)
825
+ @j_del.end(data)
826
+ else
827
+ @j_del.end
828
+ end
829
+ end
830
+
831
+ # Close the underlying TCP connection
832
+ def close
833
+ @j_del.close
834
+ end
835
+
836
+ end
837
+
473
838
  # Represents a WebSocket.
474
839
  #
475
840
  # Instances of this class are created by an {HttpClient} instance when a client succeeds in a WebSocket handshake with a server.
@@ -540,6 +905,221 @@ module Vertx
540
905
 
541
906
  end
542
907
 
908
+ # Instances of this class are created when a WebSocket is accepted on the server.
909
+ # It extends {WebSocket} and adds methods to reject the WebSocket and to get path and headers
910
+ class ServerWebSocket < WebSocket
911
+
912
+ # @private
913
+ def initialize(j_ws)
914
+ super(j_ws)
915
+ @j_del = j_ws
916
+ end
917
+
918
+ # Reject the WebSocket
919
+ # This can be called in the WebSocket connect handler on the server side and
920
+ # will cause the WebSocket connection attempt to be rejected, returning a
921
+ # 404 to the client.
922
+ def reject
923
+ @j_del.reject
924
+ end
925
+
926
+ # Return the headers of the handshake request
927
+ # @return [MultiMap] The handshake headers
928
+ def headers
929
+ if !@headers
930
+ @headers = MultiMap.new(@j_del.headers)
931
+ end
932
+ @headers
933
+ end
934
+
935
+ # The path the WebSocket connect was attempted at.
936
+ def path
937
+ @j_del.path
938
+ end
939
+ end
940
+
941
+ # This class allows you to do route requests based on the HTTP verb and the request URI, in a manner similar
942
+ # to <a href="http://www.sinatrarb.com/">Sinatra</a> or <a href="http://expressjs.com/">Express</a>.
943
+ #
944
+ # RouteMatcher also lets you extract parameters from the request URI either a simple pattern or using
945
+ # regular expressions for more complex matches. Any parameters extracted will be added to the requests parameters
946
+ # which will be available to you in your request handler.
947
+ #
948
+ # It's particularly useful when writing REST-ful web applications.
949
+ #
950
+ # To use a simple pattern to extract parameters simply prefix the parameter name in the pattern with a ':' (colon).
951
+ #
952
+ # Different handlers can be specified for each of the HTTP verbs, GET, POST, PUT, DELETE etc.
953
+ #
954
+ # For more complex matches regular expressions can be used in the pattern. When regular expressions are used, the extracted
955
+ # parameters do not have a name, so they are put into the HTTP request with names of param0, param1, param2 etc.
956
+ #
957
+ # Multiple matches can be specified for each HTTP verb. In the case there are more than one matching patterns for
958
+ # a particular request, the first matching one will be used.
959
+ #
960
+ # @author {http://tfox.org Tim Fox}
961
+ class RouteMatcher
962
+ def initialize
963
+ @j_del = org.vertx.java.core.http.RouteMatcher.new
964
+ end
965
+
966
+ # This method is called to provide the matcher with data.
967
+ # @param [HttpServerRequest] request. Input request to the parser.
968
+ def input(request)
969
+ @j_del.handle(request._to_java_request)
970
+ end
971
+
972
+ # Specify a handler that will be called for a matching HTTP GET
973
+ # @param [String] The simple pattern
974
+ # @param [Block] hndlr A block to be used as the handler
975
+ def get(pattern, &hndlr)
976
+ @j_del.get(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
977
+ end
978
+
979
+ # Specify a handler that will be called for a matching HTTP PUT
980
+ # @param [String] The simple pattern
981
+ # @param [Block] hndlr A block to be used as the handler
982
+ def put(pattern, &hndlr)
983
+ @j_del.put(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
984
+ end
985
+
986
+ # Specify a handler that will be called for a matching HTTP POST
987
+ # @param [String] The simple pattern
988
+ # @param [Block] hndlr A block to be used as the handler
989
+ def post(pattern, &hndlr)
990
+ @j_del.post(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
991
+ end
992
+
993
+ # Specify a handler that will be called for a matching HTTP DELETE
994
+ # @param [String] The simple pattern
995
+ # @param [Block] hndlr A block to be used as the handler
996
+ def delete(pattern, &hndlr)
997
+ @j_del.delete(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
998
+ end
999
+
1000
+ # Specify a handler that will be called for a matching HTTP OPTIONS
1001
+ # @param [String] The simple pattern
1002
+ # @param [Block] hndlr A block to be used as the handler
1003
+ def options(pattern, &hndlr)
1004
+ @j_del.options(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1005
+ end
1006
+
1007
+ # Specify a handler that will be called for a matching HTTP HEAD
1008
+ # @param [String] The simple pattern
1009
+ # @param [Block] hndlr A block to be used as the handler
1010
+ def head(pattern, &hndlr)
1011
+ @j_del.head(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1012
+ end
1013
+
1014
+ # Specify a handler that will be called for a matching HTTP TRACE
1015
+ # @param [String] The simple pattern
1016
+ # @param [Block] hndlr A block to be used as the handler
1017
+ def trace(pattern, &hndlr)
1018
+ @j_del.trace(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1019
+ end
1020
+
1021
+ # Specify a handler that will be called for a matching HTTP PATCH
1022
+ # @param [String] The simple pattern
1023
+ # @param [Block] hndlr A block to be used as the handler
1024
+ def patch(pattern, &hndlr)
1025
+ @j_del.patch(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1026
+ end
1027
+
1028
+ # Specify a handler that will be called for a matching HTTP CONNECT
1029
+ # @param [String] The simple pattern
1030
+ # @param [Block] hndlr A block to be used as the handler
1031
+ def connect(pattern, &hndlr)
1032
+ @j_del.connect(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1033
+ end
1034
+
1035
+ # Specify a handler that will be called for any matching HTTP request
1036
+ # @param [String] The simple pattern
1037
+ # @param [Block] hndlr A block to be used as the handler
1038
+ def all(pattern, &hndlr)
1039
+ @j_del.all(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1040
+ end
1041
+
1042
+ # Specify a handler that will be called for a matching HTTP GET
1043
+ # @param [String] A regular expression for a pattern
1044
+ # @param [Block] hndlr A block to be used as the handler
1045
+ def get_re(pattern, &hndlr)
1046
+
1047
+ @j_del.getWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1048
+ end
1049
+
1050
+ # Specify a handler that will be called for a matching HTTP PUT
1051
+ # @param [String] A regular expression for a pattern
1052
+ # @param [Block] hndlr A block to be used as the handler
1053
+ def put_re(pattern, &hndlr)
1054
+ @j_del.putWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1055
+ end
1056
+
1057
+ # Specify a handler that will be called for a matching HTTP POST
1058
+ # @param [String] A regular expression for a pattern
1059
+ # @param [Block] hndlr A block to be used as the handler
1060
+ def post_re(pattern, &hndlr)
1061
+ @j_del.postWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1062
+ end
1063
+
1064
+ # Specify a handler that will be called for a matching HTTP DELETE
1065
+ # @param [String] A regular expression for a pattern
1066
+ # @param [Block] hndlr A block to be used as the handler
1067
+ def delete_re(pattern, &hndlr)
1068
+ @j_del.deleteWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1069
+ end
1070
+
1071
+ # Specify a handler that will be called for a matching HTTP OPTIONS
1072
+ # @param [String] A regular expression for a pattern
1073
+ # @param [Block] hndlr A block to be used as the handler
1074
+ def options_re(pattern, &hndlr)
1075
+ @j_del.optionsWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1076
+ end
1077
+
1078
+ # Specify a handler that will be called for a matching HTTP HEAD
1079
+ # @param [String] A regular expression for a pattern
1080
+ # @param [Block] hndlr A block to be used as the handler
1081
+ def head_re(pattern, &hndlr)
1082
+ @j_del.headWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1083
+ end
1084
+
1085
+ # Specify a handler that will be called for a matching HTTP TRACE
1086
+ # @param [String] A regular expression for a pattern
1087
+ # @param [Block] hndlr A block to be used as the handler
1088
+ def trace_re(pattern, proc = nil, &hndlr)
1089
+ @j_del.traceWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1090
+ end
1091
+
1092
+ # Specify a handler that will be called for a matching HTTP PATCH
1093
+ # @param [String] A regular expression for a pattern
1094
+ # @param [Block] hndlr A block to be used as the handler
1095
+ def patch_re(pattern, &hndlr)
1096
+ @j_del.patchWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1097
+ end
1098
+
1099
+ # Specify a handler that will be called for a matching HTTP CONNECT
1100
+ # @param [String] A regular expression for a pattern
1101
+ # @param [Block] hndlr A block to be used as the handler
1102
+ def connect_re(pattern, &hndlr)
1103
+ @j_del.connectWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1104
+ end
1105
+
1106
+ # Specify a handler that will be called for any matching HTTP request
1107
+ # @param [String] A regular expression for a pattern
1108
+ # @param [Block] hndlr A block to be used as the handler
1109
+ def all_re(pattern, &hndlr)
1110
+ @j_del.allWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1111
+ end
1112
+
1113
+ # Specify a handler that will be called when nothing matches
1114
+ # Default behaviour is to return a 404
1115
+ # @param [Block] hndlr A block to be used as the handler
1116
+ def no_match(&hndlr)
1117
+ @j_del.noMatch { |j_req| hndlr.call(HttpServerRequest.new(j_req)) }
1118
+ end
1119
+
1120
+ end
1121
+
1122
+
543
1123
  # A map which can hold multiple values for one name / key
544
1124
  #
545
1125
  # @author Norman Maurer
@@ -674,4 +1254,54 @@ module Vertx
674
1254
  @j_map
675
1255
  end
676
1256
  end
1257
+
1258
+ # An Upload which was found in the HttpServerMultipartRequest while handling it.
1259
+ #
1260
+ # @author Norman Maurer
1261
+ #
1262
+ class HttpServerFileUpload
1263
+
1264
+ include ReadStream
1265
+
1266
+ # @private
1267
+ def initialize(j_del)
1268
+ @j_del = j_del
1269
+ end
1270
+
1271
+ # Stream the content of this upload to the given filename.
1272
+ def stream_to_file_system(filename)
1273
+ @j_del.streamToFileSystem(filename)
1274
+ self
1275
+ end
1276
+
1277
+ # Returns the filename of the attribute
1278
+ def filename
1279
+ @j_del.filename()
1280
+ end
1281
+
1282
+ # Returns the name of the attribute
1283
+ def name
1284
+ @j_del.name()
1285
+ end
1286
+
1287
+ # Returns the contentType for the upload
1288
+ def content_type
1289
+ @j_del.contentType()
1290
+ end
1291
+
1292
+ #Returns the contentTransferEncoding for the upload
1293
+ def content_transfer_encoding
1294
+ @j_del.contentTransferEncoding()
1295
+ end
1296
+
1297
+ # Returns the charset for the upload
1298
+ def charset
1299
+ @j_del.charset().toString()
1300
+ end
1301
+
1302
+ #Returns the size of the upload (in bytes)
1303
+ def size
1304
+ @j_del.size()
1305
+ end
1306
+ end
677
1307
  end