| Summary: | HttpExchange.setURI(String) does nothing | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [RT] Jetty | Reporter: | Joakim Erdfelt <joakim.erdfelt> | ||||
| Component: | client | Assignee: | Michael Gorovoy <mgorovoy> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | major | ||||||
| Priority: | P3 | CC: | gregw, jetty-inbox, mgorovoy | ||||
| Version: | 7.4.5 | ||||||
| Target Milestone: | 7.5.x | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
The way this is currently implemented, calls to HttpExchange.setAddress(Address) and HttpExchange.setMethod(String) methods are needed along with a call to HttpExchange.setURI(String) method before the exchange can be sent. Alternatively, one can call this method after calling HttpEcxhange.reset() method in order to re-use the exchange for the same address with a different relative URI component. We could create a method HttpExchange.setURI(URI) that will allow setting address, method, and path+query+uri fields in HttpExchange based on what parts are present in the incoming URI, allowing it to be used instead of HttpExchange.setURL(String) method, as well as set the relative URI field only if the argument is a relative URI. We can also modify HttpExchange.setURI(String) it will work the same way as the new method. -Michael The following methods have been added: HttpExchange.setURL(URI) - sets Scheme, Address, and request URI HttpExchange.setURI(URI) - sets request URI, disregards Scheme and Address HttpExchange.setScheme(String) - convenience method HttpExchange.setURL(String) method has been modified to use HttpExchange.setURL(URI) method. The reason why setURI(String) had to be kept unchanged, and why setURI(URI) had been implemented to set the request URI only is due to the way Request-URI is defined in RFC 2616 sec5. Please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html for more information. Created attachment 202204 [details]
Proposed patch
HttpExchange.setURL(URI) is just too confusing. how about rename setURI(String) to setRequestURI(Strig) leave setURI(String) but deprecated it add setURI(URI) that does the same as setURL(string) add lots of javadoc to explain. (In reply to comment #2) Following discussion with Greg, implementation has been changed as follows: HttpExchange.setURI(String) has been deprecated and replaced by HttpExchange.setRequestURI(String). HttpExchange.setURI(URI) has been implemented to set scheme, address, and request URI from an absolute URI. HttpExchange.setURL(String) has been changed to delegate processing to HttpExchange.setURI(URI) in order to be able to ensure that the URL is absolute and not opaque. Pushed the changes as described above to master. *** Bug 353619 has been marked as a duplicate of this bug. *** |
The method HttpExchange.setURI(String) does nothing in so far as setting up the exchange for use. Example: URI baseServerURI = URI.create("https://jira.codehaus.org/") URI uri = baseServerURI.resolve("rest/api/2.0.alpha1/project/JETTY"); HttpClient client = new HttpClient(); client.start(); HttpExchange ex = new HttpExchange(); ex.setMethod(HttpMethods.GET); ex.setURI(uri.toASCIIString()); client.send(ex); ex.waitForDone(); This will result in the following ... java.net.UnknownHostException: Remote socket address cannot be null. at org.eclipse.jetty.client.HttpClient.getDestination(HttpClient.java:251) at org.eclipse.jetty.client.HttpClient.send(HttpClient.java:177) at experiment.JiraVersions.getProjectDetails(JiraVersions.java:121) This is because HttpExchange.setURI(String) does not perform the same role as HttpExchange.setURL(String). HttpExchange.setURI(String) should use the java.net.URI object and only use URI's that are absolute and opaque (with a possible test for supported scheme's)