20

WSDLs often import other WSDLs and XML schema.

Given a URL to a WSDL, is there a tool that will download the WSDL and all other referenced WSDLs and schemas?

Ideally, this tool would be either Java or Perl friendly.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
zzztimbo
  • 2,293
  • 4
  • 28
  • 31

3 Answers3

16

soapUI has a WSDL content viewer, as the website describes

The Interface viewer allows relatively easy navigation and inspection of the entire contract for an imported WSDL, including all imported and included WSDL and XSD files and their contained types, definitions, etc.

http://www.soapui.org/userguide/interfaces/interfaceeditor.html

  • 14
    SoapUI also has the ability to export a WSDL to a local file. Right click on the project, and select "Export Definition". – Chase Seibert Sep 24 '09 at 15:16
5

The following perl script will do what you want:

#!/usr/bin/perl
#


use strict;
use warnings;

use LWP::Simple;


sub downloadfile {
        my ($url, $file) = @_;
        getstore($url, $file);
}

sub getLinesMatching {
        my ($file, $pattern) = @_;
        open my $fh,'<',$file or die "Could not open $file: $!";
        my @matching = grep /schemaLocation/,<$fh>;
        my $size = @matching;
        close $fh;
        @matching;
}

sub processFile {
        my ($url, $file) = @_;

        downloadfile $url, $file;

        my @lines = getLinesMatching $file,'schemaLocation';
        if (@lines > 0) {
                foreach my $line (@lines) {
                        $line =~ /schemaLocation=\"([^\"]*)/;
                        my ($url2) = $1;
                        print "$url2\n\n";
                        $url2 =~ /.*\/([^\/]*)/;
                        my ($file2) = $1;
                        print "$file2\n\n";
                        processFile ($url2, $file2);
                }
        }
}


my ($url) = @ARGV;
$url =~ /.*\/([^\/]*)/;
my ($base) = $1;
$base =~ s/\?/./;

print "Processing [$base] for [$url]\n\n";

processFile $url, $base;

In summary, it takes the passed in parameter as a URL to retrieve as the first file. It then scans that file for schemaLocation attributes, and downloads each of those files in a recursive manner until all schemas are located or cannot be found.

To invoke the script:

perl thisscript.perl wsdlURL

It will attempt to recursively work from the wsdl file through each imported xsd and create all the files in the current directory.

sweetfa
  • 5,457
  • 2
  • 48
  • 62
1

The Altova SchemaAgent tool can download, visualize and model a WSDL and multiple schemas. It's very nice when things get complex.

John Saunders
  • 160,644
  • 26
  • 247
  • 397