Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Both REST and SOAP Web Services for a single application

We've build an application using Spring and deployed it with Tomcat. We have a working REST interface, however one of our clients only has a SOAP client.

My understanding is that a SOAP web service and a REST web service cannot coexist on the same port or application.

What are my options for accepting a SOAP request with as little development as possible. Should I accept a soap packet via the rest interface and parse the XML? Or can I setup a SOAP interface communicate with my REST interface and respond back?

I'm using Gradle as my build tool. It would be nice to have the solution as part of a single WAR file

like image 989
Max Avatar asked Dec 06 '13 02:12

Max


2 Answers

In my experience, you can mix SOAP and REST in the same application if you're very careful about XML namespaces for JAXB. However, I wouldn't recommend it since updating one means risking the other's stability. Here is what I recommend...

  1. Setup a multi-project build in gradle
  2. Create three projects, one for the business logic, one for the REST interface, and one for the SOAP interface
  3. Modify the REST/SOAP interface to use common business logic project
  4. Deploy as two separate WARs

Should I accept a soap packet via the rest interface and parse the XML?

SOAP is a protocol and not just a format so this probably won't work with most (any?) frameworks.

Or can I setup a SOAP interface communicate with my REST interface and respond back?

You probably could at the expense of performance and/or maintainability.

like image 162
Andrew White Avatar answered Sep 19 '22 14:09

Andrew White


We have a project that has similar requirements. We still have to support SOAP and we're going forward with ReST.

There is no reason that the two will conflict. Since you're using spring, you can even have the same domain objects as a response that gets marshalled to XML and JSON as your preference.

What you have to do is create different URI for the two. e.g someService/** for the SOAP and some-rest for the ReST implementations. You can have a service layer to handle shared logic (mostly the code needed on the end point and the rest controller is to fetch the required data from the service layer and sending it to be marshalled)

Just add some entry to your web.xml file to indicate the rest path and the endpoint paths...

like image 27
Amanuel Nega Avatar answered Sep 17 '22 14:09

Amanuel Nega