I am trying to call SOAP APIs from a Java client to create a Service Provider in the Identity Server.
I have enabled admin services on the server and generated the stubs from the WSDL files located at /services/IdentityApplicationManagementService?wsdl
using Apache CXF codegen plugin as described here (note: docs are for 5.9.0 but should be pretty similar to my IDS version)
I can successfully call other endpoints such as list all available service providers as following:
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());
});
}
However when I am attempting to create a new service provider
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);
}
This is the request generated from this call
<?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>
I am getting the following error on the client Side:
<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>
The log on the client side reports the following:
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)
The server log on the Identity server (wso2carbon.log) reports the following:
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...
I am using WSO2 Identity Server version 5.8 and Java 8 on the client side.
I have not messed up with Axis2 or anyting related on the Identity Server, this is happening on a clean installation. It's either something that I am doing wrong (most possible) or a bug in the Axis2 library to my understanding but I am stuck. I can provide any other required files such as the WSDL if need be. Please advice.
Well as it turns out it was a mistake on my part, specifically on the convertToJAXBElement()
method.
I have misstyped the localpart of the QName
. Editing that to
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);
}
seems to have solved the issued.