我有一个 Maven 项目,并成功连接到使用 WSO2 创建的不安全 Web 服务。启用安全性后,如何传递凭据(即用户名和密码)来连接到服务?
首先,我可以通过在Java代码中引入用户名和密码来快速完成吗?
我是否必须像我在一些文章中看到的那样生成证书,或者是否有其他方法可以完成此操作?
我的 pom.xml
具有以下条目
<execution>
<id>getTestService</id>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<unpackClasses>true</unpackClasses>
<databindingName>xmlbeans</databindingName>
<packageName>com.test.esb</packageName>
<wsdlFile>http://test:8080/services/getTestService?wsdl</wsdlFile>
<syncMode>sync</syncMode>
</configuration>
</execution>
在我的 Java 类中,我使用以下代码调用该服务。
final TestServiceStub testStub = new TestServiceStub();
final TestServiceDocument testDoc =
TestServiceDocument.Factory.newInstance();
final TestService testReq = TestService.Factory.newInstance();
...
testDoc.setTestService(testReq);
testStub.TestService(testDoc);
最佳答案
不确定这是否涵盖您的场景,但是this博客文章详细介绍了如何使用 Java 访问用户名 token 安全服务。您需要在信任存储中拥有服务器的证书,并且需要向 stub 提供用户名和密码。
关于Java,使用用户名和密码访问安全的 WSO2 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31331702/