下载所有导入/包含的WSDL和模式的简单工具

zzz*_*mbo 19 import wsdl web-services

WSDL经常导入其他WSDL和XML模式.

给定WSDL的URL,是否有一个工具可以下载WSDL和所有其他引用的WSDL和模式?

理想情况下,此工具可以是Java或Perl友好的.

小智 14

soapUI有一个WSDL内容查看器,如网站所述

Interface查看器允许相对容易地导航和检查导入的WSDL的整个合同,包括所有导入和包含的WSDL和XSD文件及其包含的类型,定义等.

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

  • SoapUI还能够将WSDL导出到本地文件.右键单击项目,然后选择"导出定义". (13认同)

swe*_*tfa 6

以下 perl 脚本将执行您想要的操作:

#!/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;
Run Code Online (Sandbox Code Playgroud)

总之,它将传入的参数作为 URL 来检索作为第一个文件。然后,它扫描该文件的 schemaLocation 属性,并以递归方式下载每个文件,直到找到或找不到所有架构。

调用脚本:

perl thisscript.perl wsdlURL

它将尝试从 wsdl 文件通过每个导入的 xsd 递归工作,并在当前目录中创建所有文件。