Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
jimbo20814
Creator
Creator

Logic inside tRowJava

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)Smiley Wink 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;
}

Labels (2)
1 Solution

Accepted Solutions
David_Beaty
Specialist
Specialist

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;
}

 

View solution in original post

3 Replies
David_Beaty
Specialist
Specialist

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;
}

 

jimbo20814
Creator
Creator
Author

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"

Anonymous
Not applicable

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");