Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
958 views
in Technique[技术] by (71.8m points)

web services - SSL client certificate in Maven

I use the "maven-jaxb22-plugin" to generate classes so I can call a web service written in .Net. Usually it works fine but this time, I can only access the WSDL using a client certificate through HTTPS (not available through HTTP).

I was able to make it work with SoapUI. I added the client certificate into a JKS keystore and added it to the SoapUI preferences. Then I created a new project by specifying the URL which looks like this: https://server.com/Service?wsdl. SoapUI generated the request template. I was easily able to query the web service and get a response. So this prove that the WSDL is available and the web service is working.

Now, in my pom file, I am using this plugin:

<build>
    <finalName>MyService</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
        </plugin>           
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb22-plugin</artifactId>
            <version>0.8.3</version>
            <configuration>
                <extension>true</extension>
                <removeOldOutput>true</removeOldOutput>
                <schemaLanguage>WSDL</schemaLanguage>
                <verbose>true</verbose>
                <schemaIncludes>
                    <includeSchema>https://server.com/Service?wsdl</includeSchema>
                </schemaIncludes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>  
    </plugins>
</build>

How can I tell Maven where my client certificate is?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could use the Maven properties plugin or use a JVM property to provide the trust store location.

In your POM build/plugins section, add a new plugin entry, where the keystore would be YourKeyStore.jks for this example:

..
<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <goals>
              <goal>set-system-properties</goal>
            </goals>
            <configuration>
              <properties>
                <property>
                  <name>javax.net.ssl.trustStore</name>
                  <value>${basedir}/src/test/jmeter/jmeterTrustedKeystore.jks</value>
                </property>
                <property>
                  <name>javax.net.ssl.keyStorePassword</name>
                  <value>changeit</value>
                </property>
              </properties>
            </configuration>
          </execution>
        </executions>
</plugin>
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...