How to test the availability of WSDL programmatically using Java

别等时光非礼了梦想. 提交于 2020-01-02 10:02:36

问题


This means i would NOT use SoapUI, or any other Application to test the WSDL.

i am looking at wsdl4j as this is potentially the only one out there, unless i am missing something available in jdk.

Here is what i tried:

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

    }

}

and it gives me false ALL the time How can i use the same for https


回答1:


Suggestion:

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

And you can check content-type too, if needed.



来源:https://stackoverflow.com/questions/11956750/how-to-test-the-availability-of-wsdl-programmatically-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!