java - 尝试在 WSO2 Identity Server 中创建 ServiceProvider 时出现 ArrayIndexOutOfBoundsException

标签 java soap wso2 jax-ws wso2-identity-server

我正在尝试从 Java 客户端调用 SOAP API 以在 Identity Server 中创建服务提供程序。

我已在服务器上启用管理服务,并使用 Apache CXF codegen 插件从位于 /services/IdentityApplicationManagementService?wsdl 的 WSDL 文件生成 stub ,如所述 here (注意:文档适用于 5.9.0,但应该与我的 IDS 版本非常相似)

我可以成功调用其他端点,例如列出所有可用的服务提供商,如下所示:

public static void listAllApplications() throws IdentityApplicationManagementServiceIdentityApplicationManagementException {
    IdentityApplicationManagementService service = new IdentityApplicationManagementService();
    IdentityApplicationManagementServicePortType port = service.getIdentityApplicationManagementServiceHttpsSoap12Endpoint();
    Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, "username");
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, "password");
    List<ApplicationBasicInfo> allApplicationBasicInfo = port.getAllApplicationBasicInfo();
    allApplicationBasicInfo.forEach((info) -> {
        System.out.println(info.getApplicationName().getValue());
    });
} 

但是当我尝试创建新的服务提供商时

public static void createApplication() throws IdentityApplicationManagementServiceIdentityApplicationManagementException {
    CreateApplication serviceProviderRequest = new axis2.apache.org.xsd.ObjectFactory().createCreateApplication();
    org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory applicationObjectFactory
            = new org.wso2.carbon.identity.application.common.model.xsd.ObjectFactory();
    ServiceProvider serviceProvider = applicationObjectFactory.createServiceProvider();
    serviceProvider.setApplicationName(applicationObjectFactory.createApplicationBasicInfoApplicationName("SOAP"));
    serviceProvider.setDescription(applicationObjectFactory.createApplicationBasicInfoDescription("Java"));
    serviceProviderRequest.setServiceProvider(convertToJAXBElement(serviceProvider));
    IdentityApplicationManagementService service = new IdentityApplicationManagementService();
    IdentityApplicationManagementServicePortType port = service.getIdentityApplicationManagementServiceHttpsSoap12Endpoint();
    Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
    requestContext.put(BindingProvider.USERNAME_PROPERTY, "username");
    requestContext.put(BindingProvider.PASSWORD_PROPERTY, "password");
    port.createApplication(serviceProviderRequest);
}


public static JAXBElement<ServiceProvider> convertToJAXBElement(ServiceProvider provider) {
    if (null == provider) {
        return null;
    }
    QName name = new QName("http://script.model.common.application.identity.carbon.wso2.org/xsd", "ServiceProvider");
    return new JAXBElement(name, ServiceProvider.class, provider);
}

这是此调用生成的请求

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
   <S:Body>
      <ns4:createApplication xmlns:ns4="http://org.apache.axis2/xsd" xmlns="http://model.common.application.identity.carbon.wso2.org/xsd" xmlns:ns2="http://script.model.common.application.identity.carbon.wso2.org/xsd" xmlns:ns3="http://common.application.identity.carbon.wso2.org/xsd">
         <ns2:ServiceProvider>
            <applicationName>SOAP</applicationName>
            <description>Java</description>
         </ns2:ServiceProvider>
      </ns4:createApplication>
   </S:Body>
</S:Envelope>

我在客户端收到以下错误:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
   <soapenv:Body>
      <soapenv:Fault>
         <soapenv:Code>
            <soapenv:Value>soapenv:Receiver</soapenv:Value>
         </soapenv:Code>
         <soapenv:Reason>
            <soapenv:Text xml:lang="en-US">1</soapenv:Text>
         </soapenv:Reason>
         <soapenv:Detail/>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

客户端的日志报告如下:

Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: 1 Please see the server log to find more detail regarding exact cause of the failure.
    at com.sun.xml.internal.ws.fault.SOAP12Fault.getProtocolException(SOAP12Fault.java:214)
    at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
    at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238)
    at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
    at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
    at com.sun.proxy.$Proxy37.createApplication(Unknown Source)
    at myApp.Main.createApplication(Main.java:60)
    at myApp.Main.main(Main.java:32)

身份服务器上的服务器日志 (wso2carbon.log) 报告以下内容:

TID: [3] [] [2019-10-16 11:17:47,158] username [3] [IS] INFO {org.wso2.carbon.core.services.util.CarbonAuthenticationUtil} -  'username [3]' logged in at [2019-10-16 11:17:47,158+0300]
TID: [3] [] [2019-10-16 11:17:47,161] username [3] [IS]ERROR {org.apache.axis2.rpc.receivers.RPCMessageReceiver} -  1
java.lang.ArrayIndexOutOfBoundsException: 1
        at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:662)
        at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153)
        at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:206)
        at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
        at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:173)
        at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:148)
        at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:238)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 
    // Ommitted...

我在客户端使用 WSO2 Identity Server 版本 5.8 和 Java 8。

我没有搞乱 Axis2 或 Identity Server 上的任何相关内容,这是在全新安装中发生的。据我了解,这要么是我做错了(最有可能),要么是 Axis2 库中的错误,但我陷入了困境。如果需要,我可以提供任何其他所需的文件,例如 WSDL。请指教。

最佳答案

事实证明这是我的一个错误,特别是在 convertToJAXBElement() 方法上。

我输错了 QName 的本地部分。将其编辑为

public static JAXBElement<ServiceProvider> convertToJAXBElement(ServiceProvider provider) {
    if (null == provider) {
        return null;
    }
    QName name = new QName("http://script.model.common.application.identity.carbon.wso2.org/xsd", "serviceProvider"); // Note the localpart
    return new JAXBElement(name, ServiceProvider.class, provider);
}

似乎已经解决了问题。

关于java - 尝试在 WSO2 Identity Server 中创建 ServiceProvider 时出现 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58408905/

相关文章:

java - prolog 错误中出现意外的 EOF

wso2 - 从后端服务传递到 API 管理器或 BAM 的计费详细信息

xml - 如何在不知道元素名称的情况下获取 xslt 中节点的命名空间 uri?

mysql - 升级 1.6.0 到 1.7.0 后 WSO2 AM 错误

java - Eclipse 自动部署不包括 native 库

java - 检查链接的 URL 状态代码时,无法将 HttpResponseCode 错误解析为类型

java - 从 Windows 中的 Java 程序运行命令提示符

java - Windows 上的 Java SE6 客户端通过 NTLM 进行 HTTP "Negotiate"身份验证

python - 有没有人将 soap.py 或 suds 与 python-ntlm 结合使用?

javascript - 是否可以使用 jQuery xml 处理程序解析 SOAP 响应?