-
Notifications
You must be signed in to change notification settings - Fork 53
BROOKLYN-421: Adds DSL for $brooklyn:urlEncode(...) #551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Replaced the createAndStartApplication impl with that from AbstractYamlTest. (Before this change, I saw a NoSuchElementException because it failed to find the task for the start effector - I’m guessing there’s a race for when that task is created).
Graeme-Miller
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me as well, it would be good to have brooklyn-docs PR for this too. Thanks @aledsage!
|
|
|
@neykov agreed - I stayed well clear of The https://github.com/mikaelhg/urlbuilder library looks interesting and promising. Not sure how well it would handle the username:password use-case though, particularly given these bits are being passed in the DSL and constructed into a string using |
|
I guess yes - the colon is not escaped @aledsage. I'm thinking we would expose the builder in the DSL, not use it piecemeal to stitch together a URL in |
|
+1 to the idea of exposing the builder, which makes it unambiguous as to how to interpret each bit. I think if you do that then you can get away without the external library and just use java.net.URI,
I know I used it before to do character escaping, but don't remember the details, perhaps my use case was simpler. |
|
@geomacy It's not completely clear to me. If one of the query values contains a |
|
I think it only escapes illegal characters, not reserved ones, so This passes: |
|
I hesitate to suggest this but one "creative" use of URI could be to do the encoding along the lines of the above, e.g. |
|
I'm not really suggesting we do this by the way, just musing; it's too creative by half for me! I still stick with my point above agreeing that it's best to expose a URL builder DSL - by being explicit about each part it means you can interpret each value you are given very precisely. |
|
Actually I take it back - having looked more carefully at the spec for that j.n.URI constructor I think the above is a perfectly valid use. |
|
@geomacy minor correction - separator between username and password is Unfortunately the URI encoding doesn't work when the username and/or password has more complicated examples. It is impossible for URI to tell in all cases what part is what - e.g. what if my password was As a less contrived example: It doesn't get the username + password correct in the second parsed uri. It gives the output: |
|
@neykov I like your idea of something like: Or perhaps (IMO) in more "idiomatic yaml": I'd prefer the yaml we write to look like configuration rather than code (even if it is turned into method calls under the covers). @neykov Do you want to capture this discussion in an Apache Brooklyn jira "improvement"? |
|
@aledsage, yes my comment above just meant that on reflection it's not invalid to use URI() to escape illegal characters in that way, but it still doesn't give us all we need; +1 to your suggestion about the more "idiomatic yaml", I like that syntax. |
As stated in the comments within the code, the url encoding is based on "x-www-form-urlencoded". Therefore care must be taken if encoding username or password (e.g. in http://myuser:mypass@myhost"). It will not encode space correctly, and will not escape "*". The latter we can probably live with, but the former will be wrong.