我使用下面给出的命令为WSO2 webservice生成wso2客户端
wsimport -keep -verbose https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl
我使用JAVA 1.8.0_112生成了此客户端。当我试图通过使用生成的方法构造函数(URL url)指定WSDL LOCATION来调用客户端时,我得到以下异常:
@people = People.all
我使用的是wso2身份服务器 - 5.2.0版本。 IT也在JAVA 1.8.0_112上运行。我调用客户端的代码是 -
Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.ws.model.JavaMethodImpl.freeze(JavaMethodImpl.java:379)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.freeze(AbstractSEIModelImpl.java:105)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:320)
at com.sun.xml.internal.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:85)
at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:59)
at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:43)
at com.sun.xml.internal.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:105)
at com.sun.xml.internal.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:875)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:892)
at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:855)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:435)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:404)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:386)
at javax.xml.ws.Service.getPort(Service.java:119)
at org.wso2.carbon.um.ws.service.RemoteUserStoreManagerService.getRemoteUserStoreManagerServiceHttpSoap11Endpoint(RemoteUserStoreManagerService.java:72)
at org.wso2.carbon.test.TestUserLogin.main(TestUserLogin.java:15)
我的RemoteUserStoreManagerService类是 -
package org.wso2.carbon.test;
import java.net.MalformedURLException;
import java.net.URL;
import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerService;
import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerServicePortType;
import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerServiceUserStoreException_Exception;
public class TestUserLogin {
public static void main(String args[]) throws MalformedURLException, RemoteUserStoreManagerServiceUserStoreException_Exception {
RemoteUserStoreManagerService rus =
new RemoteUserStoreManagerService(new URL("https://ril15066yjb152:9443/services/RemoteUserStoreManagerService?wsdl"));
RemoteUserStoreManagerServicePortType rusm = rus.getRemoteUserStoreManagerServiceHttpSoap11Endpoint();
System.out.println(rusm.authenticate("admin", "admin"));
}
}
答案 0 :(得分:3)
尝试使用此代码删除NPE:
RemoteUserStoreManagerService rus =
new RemoteUserStoreManagerService();
RemoteUserStoreManagerServicePortType rusm = rus.getRemoteUserStoreManagerServiceHttpsSoap11Endpoint();
((BindingProvider) rusm).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
org.apache.cxf.endpoint.Client client = ClientProxy
.getClient(rusm);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getAuthorization().setUserName("admin");
http.getAuthorization().setPassword("admin");
System.out.println("User authenticate? " + rusm.authenticate("admin", "admin"));
List<String> listUsers = rusm.listUsers("*", 100);
for (String user : listUsers) {
System.out.println("User: " + user);
}
更新1: 您还需要在服务部分中使用此端口更新WSDL:
<wsdl:port name="RemoteUserStoreManagerServiceHttpsSoap11Endpoint" binding="ns:RemoteUserStoreManagerServiceSoap11Binding">
<soap:address location="https://localhost:9443/services/RemoteUserStoreManagerService.RemoteUserStoreManagerServiceHttpsSoap11Endpoint/"/>
</wsdl:port>
更新2:在验证用户身份验证之前添加了http基本身份验证。检查上面的代码。
我的客户回复:
User authenticate? true
User: WSO2.ORG/admin
User: WSO2.ORG/isildurmac