Split a URL into protocol, domain, port and uri using regular expressions

Posted on by Kim

// Split URL into protocol, domain, port and URI
Pattern pattern = ~/(https?:\/\/)([^:^\/]*)(:\d*)?(.*)?/
Matcher matcher = pattern.matcher url

String protocol = matcher.group 1
String domain = matcher.group 2
String port = matcher.group 3
String uri = matcher.group 4

Encode url (Change spaces etc.)

Posted on by Kim

URL url = new URL(urlStr)
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef())
url = uri.toURL()

With problems with handlers

Posted on by Kim


protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception