gpt4 book ai didi

java - WSO2 Web服务空指针异常

转载 作者:行者123 更新时间:2023-12-01 20:56:48 25 4
gpt4 key购买 nike

我正在使用下面给出的命令为 WSO2 Web 服务生成 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 来调用客户端时,出现以下异常:

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)

我正在使用 wso2 身份服务器 - 5.2.0 版本。 IT 也在 JAVA 1.8.0_112 上运行。我调用客户端的代码是 -

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"));
}

}

我的 RemoteUserStoreManagerService 类是 -

package org.wso2.carbon.um.ws.service;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.9-b130926.1035
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "RemoteUserStoreManagerService", targetNamespace = "http://service.ws.um.carbon.wso2.org", wsdlLocation = "https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl")
public class RemoteUserStoreManagerService
extends Service
{

private final static URL REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION;
private final static WebServiceException REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION;
private final static QName REMOTEUSERSTOREMANAGERSERVICE_QNAME = new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerService");

static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION = url;
REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION = e;
}

public RemoteUserStoreManagerService() {
super(__getWsdlLocation(), REMOTEUSERSTOREMANAGERSERVICE_QNAME);
}

public RemoteUserStoreManagerService(WebServiceFeature... features) {
super(__getWsdlLocation(), REMOTEUSERSTOREMANAGERSERVICE_QNAME, features);
}

public RemoteUserStoreManagerService(URL wsdlLocation) {
super(wsdlLocation, REMOTEUSERSTOREMANAGERSERVICE_QNAME);
}

public RemoteUserStoreManagerService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, REMOTEUSERSTOREMANAGERSERVICE_QNAME, features);
}

public RemoteUserStoreManagerService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}

public RemoteUserStoreManagerService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}

/**
*
* @return
* returns RemoteUserStoreManagerServicePortType
*/
@WebEndpoint(name = "RemoteUserStoreManagerServiceHttpSoap11Endpoint")
public RemoteUserStoreManagerServicePortType getRemoteUserStoreManagerServiceHttpSoap11Endpoint() {
return super.getPort(new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerServiceHttpsSoap11Endpoint"), RemoteUserStoreManagerServicePortType.class);
}

/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns RemoteUserStoreManagerServicePortType
*/
@WebEndpoint(name = "RemoteUserStoreManagerServiceHttpSoap11Endpoint")
public RemoteUserStoreManagerServicePortType getRemoteUserStoreManagerServiceHttpSoap11Endpoint(WebServiceFeature... features) {
return super.getPort(new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerServiceHttpSoap11Endpoint"), RemoteUserStoreManagerServicePortType.class, features);
}

private static URL __getWsdlLocation() {
if (REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION!= null) {
throw REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION;
}
return REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION;
}

}

最佳答案

尝试使用此代码删除 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

关于java - WSO2 Web服务空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com