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

时间:2019-10-16 08:26:30

标签: java soap wso2 jax-ws wso2is

我试图从Java客户端调用SOAP API,以在Identity Server中创建服务提供者。

我已在服务器上启用了管理服务,并使用here中所述的Apache CXF codegen插件从位于/services/IdentityApplicationManagementService?wsdl的WSDL文件中生成了存根(注意:文档适用于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。请指教。

1 个答案:

答案 0 :(得分:0)

事实证明,这对我来说是一个错误,特别是在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);
}

似乎已经解决了问题。