我想通过 Java 代码检查 WSDL url 是否有效。这样我就可以使用另一个基于此的 url。
所以我正在检查这样的代码。
private boolean isValidWsdlURL(String wsdlUrl)
{
UrlValidator urlValidator = new UrlValidator();
if(urlValidator.isValid(wsdlUrl))
{
return true;
}
logger.info("WSDL URL is not valid...");
return false;
}
但它总是返回错误,尽管我有有效的 URL。 WSDL URL 例如: http://www.sample.com/MyWsdlService?wsdl
因为 URL 以 ?wsdl 结尾 如何查看代码?看起来我们只需要“http://www.sample.com”就可以让 UrlValidator 通过。
最佳答案
您正在尝试验证 WSDL URL?为什么不使用 java.net.URL 类?
并做类似的事情:
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?");
}
当我插入像 htt2p 而不是 http 这样的错误 URL 时,我得到了“错误 url”打印
关于java - 如何从 Java 验证 WSDL URL 是否已启动并正在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14836407/