2

这意味着我不会使用 SoapUI 或任何其他应用程序来测试 WSDL。

我正在查看wsdl4j,因为这可能是唯一的一个,除非我错过了 jdk 中可用的东西。

这是我尝试过的:

类: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();
        }

    }
}

类: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

4

1 回答 1

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

如果需要,您也可以检查内容类型。

于 2012-08-14T16:47:30.373 回答