如何使用java从url读取wsdl

时间:2016-06-15 17:13:20

标签: java http wsdl

我是java的新手。我想从java中读取wsdl。我有示例northwind service http://services.odata.org/Northwind/Northwind.svc/ $ metadata

我想读取上述URL的输出xml。我尝试过不同的方式,但没有用。

    URL oracle = new URL("http://services.odata.org/Northwind/Northwind.svc/$metadata");
    BufferedReader in = new BufferedReader(
    new InputStreamReader(oracle.openStream()));

    String inputLine;
    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);
    in.close();

方法#2

private static void readHttp() {
    Charset charset = Charset.forName("US-ASCII");
    Path file = Paths.get("http://services.odata.org/Northwind/Northwind.svc/$metadata");
    try (BufferedReader reader = Files.newBufferedReader(file, charset)) {
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    } catch (IOException x) {
        System.err.format("IOException: %s%n", x);
    }
}

任何人都可以建议我如何继续这样做。

谢谢,

1 个答案:

答案 0 :(得分:1)

使用org.apache.commons.io.IOUtils

IOUtils.toString(new URL("http://services.odata.org/Northwind/Northwind.svc/"));