I wanted to check WSDL url is valid or not from Java code. So that I can use another url based on that.
So I am checking the code like this.
private boolean isValidWsdlURL(String wsdlUrl)
{
UrlValidator urlValidator = new UrlValidator();
if(urlValidator.isValid(wsdlUrl))
{
return true;
}
logger.info("WSDL URL is not valid...");
return false;
}
But its alwys returning false though I have valid URL. WSDL URL Ex: http://www.sample.com/MyWsdlService?wsdl
Because URL ends with ?wsdl How to check the code? Looks we need only "http://www.sample.com" for UrlValidator to pass.
You're trying to validate a WSDL URL? Why not use the java.net.URL class ?
And do something like:
String urlStr = "http://www.example.com/helloService?wsdl";
URL url = null;
try {
url = new URL(urlStr);
URLConnection urlConnection = url.openConnection()
} catch (MalformedURLException ex) {
System.out.println("bad URL");
} catch (IOException ex) {
System.out.println("Failed opening connection. Perhaps WS is not up?");
}
When I inserted bad URLs like htt2p instead of http I got - "bad url" print
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With