这意味着我不会使用SoapUI或任何其他应用程序来测试WSDL。
我正在查看wsdl4j因为这可能是唯一一个,除非我错过了jdk中可用的内容。
这是我试过的:
class:WSDLtestvip.java
import java.net.HttpURLConnection;
import java.net.URL;
public class WSDLtestvip {
public boolean isWSDLAvailable(String wsdlAddr) {
HttpURLConnection c = null;
try {
URL u = new URL(wsdlAddr);
c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("HEAD");
c.getInputStream();
return c.getResponseCode() == 200;
} catch (Exception e) {
return false;
} finally {
if (c != null)
c.disconnect();
}
}
}
class:WsdlTester.java
public class WsdlTester {
public static void main(String[] args) {
WSDLtestvip wstvip = new WSDLtestvip();
boolean result = wstvip
.isWSDLAvailable("https://a.b.c/aaa?wsdl");
System.out.println(result);
}
}
它一直给我假 我如何使用相同的https
答案 0 :(得分:4)
建议:
private boolean isWSDLAvailable(String wsdlAddr) {
HttpURLConnection c = null;
try {
URL u = new URL(wsdlAddr);
c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("HEAD");
c.getInputStream();
return c.getResponseCode() == 200;
} catch (Exception e) {
return false;
} finally {
if (c != null) c.disconnect();
}
}
如果需要,您也可以检查内容类型。