CertificateException:找不到匹配主机名的名称Maven

时间:2012-12-28 16:48:01

标签: web-services maven maven-2 wsdl

我有一个需要在Maven项目中使用的HTTPS WSDL URL(https://hostname/MyApp/MyApp.svc?wsdl)。 WSDL上的证书已过期,并发布到hostname.company.com。

我在Maven pom.xml中有以下代码

<dependencies>
    <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <scope>compile</scope>
        <version>2.1.3</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.10</version>
            <executions>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>                          
                        <wsdlUrls>
                            <wsdlUrl>https://hostname/MyApp/MyApp.svc?wsdl</wsdlUrl>
                        </wsdlUrls>                           
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

当我进行清理和构建时,我收到以下错误

[jaxws:wsimport]
Processing: https://hostname/MyApp/MyApp.svc?wsdl
jaxws:wsimport args: [-s, C:\WorkspaceNetBeans\Maven\WSTest\target\generated-sources\jaxws-wsimport, -d, C:\WorkspaceNetBeans\Maven\WSTest\target\classes, https://hostname/MyApp/MyApp.svc?wsdl]
parsing WSDL...

java.security.cert.CertificateException: No name matching hostname found

Failed to read the WSDL document: https://hostname/MyApp/MyApp.svc?wsdl, because 1) could not find the document; /2) the document could not be read; 3) the root element of the document is not <wsdl:definitions>. 

failed.noservice=Could not find wsdl:service in the provided WSDL(s): 

 At least one WSDL with at least one service definition needs to be provided.

    Failed to parse the WSDL.

我使用keytool实用程序将证书添加到密钥库。我还需要做什么?

2 个答案:

答案 0 :(得分:1)

您可以从Web浏览器本地下载wsdl,然后在该本地文件上运行wsimport以生成Java模型。

答案 1 :(得分:0)

您有可能的选择:

1)将服务器的证书导入Trust Store,同时确保服务器证书中显示的CN名称与您使用的主机名相同。这个链接可能会有所帮助:http://bluefoot.info/howtos/how-to-avoid-java-security-cert-certificateexception-no-name-matching-localhost-found/

2)使用像Netbeans或eclipse这样的工具,可以忽略(我怀疑它)服务器的SSL方面。

3)创建解析所有相关XSD引用的WSDL的本地版本并使用该WSDL。