Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate WSDL URL is up and running or not from Java?

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.

like image 225
Sriks Avatar asked Oct 19 '25 10:10

Sriks


1 Answers

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

like image 74
Yair Zaslavsky Avatar answered Oct 21 '25 23:10

Yair Zaslavsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!