Search code examples
javatypescriptweb-serviceswsdl

Interfacing a hybrid/web client application with existing remote web services described by a set of WSDL


The issue in short

I have to integrate a mobile hybrid application that will probably be based on Ionic, and will have to (indirectly) consume a number of SOAP web services. I'd like the mobile app Typescript client to be aware of the beans defined by the XSD and WSDL files describing the web services.

Some additional explanations

In the following explanations I will refer to the following objects within the solution:

  • the mobile app Typescript client [A]
  • the mobile-dedicated server-side Java application [B]
  • the remote SOAP web services that expose the business functions [C]

The following constraints are in force:

  • the mobile app client [A] will communicate through REST calls with a dedicated server-side application [B]
  • the dedicated server-side application [B] will be developed in Java the dedicated server-side application [B] will take care of consuming the existing web services [C], hence acting as an integration layer between the Typescript app client [A] and the SOAP web services [C]
  • the SOAP web services [C] are described by a number of WSDL files, supported by some XSD files, the backend team is unwilling to rewrite their documentation to anything other than WSDL and XSD

Let's say that some requests and responses used by the web services [C] involve the following Java object

public class MyElement {
    private ElementColor color;
}

where ElementColor is a Java enum such as

public enum ElementColor {
    RED,
    GREEN,
    BLUE,
}

These Java objects are defined in the WSDL and XSD files, hence we can build a JAR file, import it within the server-side application [B], and therefore our server-side application [B] will be aware of the possible values that the "color" property can assume within the MyElement class. All good.

My issue is that the Typescript mobile client [A] does not import the JAR file (obviously), hence when a client-side developer will have to write a request or parse a response that involves the MyElement object he will either

  • treat the "color" field like a String (but then he could write any value to it, not just the valid "RED", "GREEN", and "BLUE" values)
  • define a Typescript enum mimicking the ElementColor Java enum.

The second option is cleaner, but still not strongly tied to the actual models defined in the WSDL and XSD files, i.e. the client-side developer could still add a "YELLOW" value in his Typescript enum and send it to the backend.

I would like to automatically import/inherit within my Typescript codebase the models defined by the WSDL and XSD files, or the Typescript mappings of the Java classes generated from those same WSDL and XSD files. Mind that it is not enough to retrieve these objects at runtime (I could write a service that dumps them) because the client-side developer would still not be able to see them when developing.

Thank you in advance for your help.


Solution

  • So far the best approach I found to tackle this issue is leveraging something like this typescript generator plugin, which converts Java classes in Typescript classes.

    I already had in place a Maven pom using cxf codegen plugin in order to turn WSDL and XSD files into Java code, I just had to add the typescript generator plugin execution to the process, so that the Java files are converted to Typescript files in turn. I can then import the Typescript definition files in my hybrid app project.