Naveen Bathina
Naveen Bathina

Reputation: 414

How to read wsdl from a url using java

I'm new to java. I want to read wsdl from java. I have sample northwind service http://services.odata.org/Northwind/Northwind.svc/$metadata

I want to read output xml for the above URL. I tried in different ways, It didn't work.

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

Method #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);
    }
}

Can anyone suggest me how to proceed on this.

Thanks,

Upvotes: 2

Views: 1633

Answers (1)

K139
K139

Reputation: 3679

Use org.apache.commons.io.IOUtils

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

Upvotes: 1

Related Questions