Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I'm fairly new to Talend (we're a licensed customer, Talend Big Data) so thanks in advance.
So in tRowJava, I want get the domain name from a string called url. So I have a input_row.url and an output_row.url
I found the below function but I can't seem to refer to it when I put in inside the body of the code. I've also tried pulling pieces out of the function (URI uri = new URI(url) and put in body of code but that doesn't seem to work either. Any suggestion on how I can achieve this? Thank you!
public String getHostName(String url) {
URI uri = new URI(url);
String hostname = uri.getHost();
// to provide faultproof result, check if not null then return only hostname, without www.
if (hostname != null) {
return hostname.startsWith("www.") ? hostname.substring(4) : hostname;
}
return hostname;
}
Hi,
You'll need to either refactor that code as a static class and call it as a static routine, or bring into into the tJavaRow, but as Java statements rather than a public class - something like:
URI uri = new URI(input_row.url); String hostname = uri.getHost(); if (hostname != null) { output_row.hostname = hostname.startsWith("www.") ? hostname.substring(4) : hostname; } output_row.hostname = hostname; }
Hi,
You'll need to either refactor that code as a static class and call it as a static routine, or bring into into the tJavaRow, but as Java statements rather than a public class - something like:
URI uri = new URI(input_row.url); String hostname = uri.getHost(); if (hostname != null) { output_row.hostname = hostname.startsWith("www.") ? hostname.substring(4) : hostname; } output_row.hostname = hostname; }
Thank you, I removed the code from class in just put inline inside main body. To keep simple, I hardcoded URL and just started with the first line (
URI uri = new URI("https://jimbo.com");
) and it returns "URI cannot be resolved to a type"
You need to import the java.net package to do this or use the following code...
java.net.URI uri = new java.net.URI("https://jimbo.com");