如何使用Java以编程方式测试WSDL的可用性 [英] How to test the availability of WSDL programmatically using Java

查看:148
本文介绍了如何使用Java以编程方式测试WSDL的可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

这是我试过的:

class:WSDLtestvip.java

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

    }
}

类: WsdlTester.java

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

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

推荐答案

建议:

    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.

这篇关于如何使用Java以编程方式测试WSDL的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆