Both HTTBuilder and http-builder-ng use the java.net.URI class to store and manipulate URI information. java.net.URI has the following behavior:

1) If you set the full path using the single string constructor, URI keeps the %2B in the URI. 2) If you set the path using the constructors that take the uri parts, the path is url encoded
3) Extracting the path will always result in url decoding

Both libraries also always use the constructor that takes uri parts, meaning you will always get the encoding and decoding that may be causing you problems. The following groovy code shows the behavior:

def full = new URI('http://172.16.29.10/rest/TEST/c%2B%2B.doc')
def parts = new URI('http', '172.16.29.10', '/rest/TEST/c%2B%2B.doc', null)
println(full.toString())
println(full.path)
println(parts.toString())
println(parts.path)

On 11/20/2016 09:12 AM, Christian Lotz wrote:
OK ... then I guess that the REST service expects "+" to be enoded (%2B). Is there a way to "enforce" the encoding of the plus sign to "%2B" using the URIBuilder for uri.path? If I replace the plus sign and assign the string to uri.path it gets encoded again (%252B) by replacing the "%" with "%25" ...
Thanks in advance
*Gesendet:* Sonntag, 20. November 2016 um 15:39 Uhr
*Von:* "David Clark" <[email protected]>
*An:* [email protected]
*Betreff:* Re: HTTPBuilder & URIBuilder - plus sign will not encoded

Plus sign is legal in URI's so they don't need to get encoded to be legal:

http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid/1547940#1547940

This is complicated by the fact that they are url encoded when part of the query string, but that's not what you are doing here. It sounds to me like the problem is on the server or there some other part of your request that is incorrect.

If there is a problem inside HTTPBuilder, you are probably out of luck, that project has been dead for a while.

However, I have created a successor to HTTPBuilder called http-builder-ng that is active here:

https://github.com/dwclark/http-builder-ng

It is NOT a backwards compatible upgrade. When I was examining the original source code I found many threading issues, code duplication, it was imposible to use @TypeChecked/@CompileStatic, and found it hard to integrated different clients inside HTTPBuilder. The result of these frustrations was a ground up re-write. Bug reports/pull requests are encouraged.

On 11/20/2016 07:25 AM, Christian Lotz wrote:

    Hi all,
    I try to upload files via HTTPBuilder (Groovy Version: 2.4.7 JVM:
    1.8.0_40 Vendor: Oracle Corporation OS: Mac OS X). After a couple
    of test I realized, that filenames containing a plus sign ("+")
    can't be uploaded. The REST Service responds with HTTP/1.1 400 Bad
    Request. After some more debugging I think these filenames will
    not get encoded correctly:
    uri.path = "/rest/" + objectNamespace + "/" + objectFile.name

    groovyx.net.http.HTTPBuilder doRequest
    FINE: PUT http://172.16.29.10/rest/TEST/s*pace%20space.doc* -
    Filename: space\ space.doc - OK

    groovyx.net.http.HTTPBuilder doRequest
    FINE: PUT http://172.16.29.10/rest/TEST/*plus+plus.doc* -Filename
    plus+plus.doc - ERROR

    All other "special" characters like spaces, #, &, % or ? will
    get encoded correctly ...
    Does anybody know how to resolve this issue?
    Thanks in advance
    Paolo


Reply via email to