jruby-httpclient 0.2.0-java → 0.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -11,6 +11,7 @@ GEM
11
11
 
12
12
  PLATFORMS
13
13
  java
14
+ ruby
14
15
 
15
16
  DEPENDENCIES
16
17
  bundler (~> 1.0.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jruby-httpclient}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
  s.platform = Gem::Platform.new([nil, "java", nil])
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
@@ -19,7 +19,6 @@ module HTTP
19
19
  @response_handler = BasicResponseHandler.new
20
20
  end
21
21
 
22
- @uri_builder = URIBuilder.new(nil, nil, nil, "")
23
22
  @encoding = options[:encoding] || "UTF-8"
24
23
 
25
24
  # Set options from the rest of the options-hash
@@ -50,24 +49,11 @@ module HTTP
50
49
  def execute(request)
51
50
  client = DefaultHttpClient.new(params)
52
51
 
53
- request.make_native_request(client, @uri_builder, @encoding, @response_handler)
52
+ request.make_native_request(client, @encoding, @response_handler)
54
53
  rescue SocketTimeoutException
55
54
  raise Timeout::Error, "timed out after #{so_timeout} ms"
56
55
  ensure
57
56
  client.connection_manager.shutdown
58
57
  end
59
58
  end
60
-
61
- class URIBuilder
62
- def initialize(protocol, host, port, base_path)
63
- @protocol = protocol
64
- @host = host
65
- @port = port
66
- @base_path = base_path
67
- end
68
-
69
- def create_uri(path, query_string = nil)
70
- URIUtils.create_uri(@protocol, @host, @port, "#{@base_path}#{path}", query_string, nil)
71
- end
72
- end
73
59
  end
@@ -2,8 +2,8 @@ module HTTP
2
2
  class Request
3
3
  def self.create_type(&native_request_factory)
4
4
  Class.new do
5
- def initialize(path, params = {})
6
- @path = path
5
+ def initialize(uri, params = {})
6
+ @uri = uri
7
7
  @params = params
8
8
  @headers = {}
9
9
  end
@@ -25,8 +25,8 @@ module HTTP
25
25
  @password = password
26
26
  end
27
27
 
28
- def make_native_request(client, uri_builder, encoding, handler=nil)
29
- request = create_native_request(uri_builder, encoding)
28
+ def make_native_request(client, encoding, handler=nil)
29
+ request = create_native_request(encoding)
30
30
  request.entity = StringEntity.new(@body) unless @body.nil?
31
31
 
32
32
  unless @username.nil?
@@ -40,10 +40,18 @@ module HTTP
40
40
  end
41
41
  end
42
42
 
43
+ def parse_uri
44
+ uri = URI.parse(@uri)
45
+ [uri.scheme, uri.host, uri.port, uri.path]
46
+ rescue URI::InvalidURIError
47
+ [nil, nil, nil, @uri]
48
+ end
49
+
43
50
  private
44
- define_method(:create_native_request) do |uri_builder, encoding|
51
+ define_method(:create_native_request) do |encoding|
45
52
  params = @params.collect { |key, value| BasicNameValuePair.new(key.to_s, value.to_s) }
46
- request = native_request_factory.call(uri_builder, @path, params, encoding)
53
+ scheme, host, port, path = parse_uri
54
+ request = native_request_factory.call(scheme, host, port, path, params, encoding)
47
55
 
48
56
  @headers.each { |name, value| request.add_header(name.to_s, value.to_s) }
49
57
 
@@ -53,24 +61,23 @@ module HTTP
53
61
  end
54
62
  end
55
63
 
56
- Post = Request.create_type do |uri_builder, path, params, encoding|
57
- post = HttpPost.new(uri_builder.create_uri(path))
64
+ Post = Request.create_type do |scheme, host, port, path, params, encoding|
65
+ post = HttpPost.new(URIUtils.create_uri(scheme, host, port, path, nil, nil))
58
66
  post.entity = UrlEncodedFormEntity.new(params, encoding)
59
67
  post
60
68
  end
61
69
 
62
- Get = Request.create_type do |uri_builder, path, params, encoding|
70
+ Get = Request.create_type do |scheme, host, port, path, params, encoding|
63
71
  query_string = URLEncodedUtils.format(params, encoding)
64
- get = HttpGet.new(uri_builder.create_uri(path, query_string))
65
- get
72
+ HttpGet.new(URIUtils.create_uri(scheme, host, port, path, query_string, nil))
66
73
  end
67
74
 
68
- Delete = Request.create_type do |uri_builder, path|
69
- HttpDelete.new(uri_builder.create_uri(path))
75
+ Delete = Request.create_type do |scheme, host, port, path|
76
+ HttpDelete.new(URIUtils.create_uri(scheme, host, port, path, nil, nil))
70
77
  end
71
78
 
72
- Put = Request.create_type do |uri_builder, path|
73
- HttpPut.new(uri_builder.create_uri(path))
79
+ Put = Request.create_type do |scheme, host, port, path|
80
+ HttpPut.new(URIUtils.create_uri(scheme, host, port, path, nil, nil))
74
81
  end
75
82
 
76
83
  private
@@ -82,7 +89,6 @@ module HTTP
82
89
  URIUtils = org.apache.http.client.utils.URIUtils
83
90
  URLEncodedUtils = org.apache.http.client.utils.URLEncodedUtils
84
91
  UrlEncodedFormEntity = org.apache.http.client.entity.UrlEncodedFormEntity
85
- BasicResponseHandler = org.apache.http.impl.client.BasicResponseHandler
86
92
  AuthScope = org.apache.http.auth.AuthScope
87
93
  UsernamePasswordCredentials = org.apache.http.auth.UsernamePasswordCredentials
88
94
  StringEntity = org.apache.http.entity.StringEntity
@@ -25,6 +25,30 @@ class TestBasicClientOperations < Test::Unit::TestCase
25
25
  assert_equal("put", result)
26
26
  end
27
27
 
28
+ def test_can_get_full_url
29
+ result = @client.get("http://localhost:8080/echo", :content => "hello")
30
+
31
+ assert_equal("hello", result)
32
+ end
33
+
34
+ def test_can_post_full_url
35
+ result = @client.post("http://localhost:8080/echo", :content => "hello")
36
+
37
+ assert_equal("hello", result)
38
+ end
39
+
40
+ def test_can_delete_full_url
41
+ result = @client.delete("http://localhost:8080/echo")
42
+
43
+ assert_equal("delete", result)
44
+ end
45
+
46
+ def test_can_put_full_url
47
+ result = @client.put("http://localhost:8080/echo")
48
+
49
+ assert_equal("put", result)
50
+ end
51
+
28
52
  def setup
29
53
  @client = HTTP::Client.new(:default_host => "http://localhost:8080")
30
54
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: jruby-httpclient
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: java
7
7
  authors:
8
8
  - Adam Esterline