3
votes

I am new to Java web-services and am working on one currently, using Apache CXF. It will have both JAX-WS(SOAP) and JAX-RS(REST) support. It will be consumed by desktop and mobile applications. In learning Apache CXF, I have come across some showstoppers. Can anyone help me with the flow in terms of layers?

FYI: I have worked with the Google Maps API earlier. I developed a consuming application in .NET, and have a fair idea of web services (both SOAP and REST). I am having problems with these implementation details in Java.


About the service

Here is what I understand. Mule will run on a separate server, and since Mule already supports Apache CXF, it will be able to run both RESTful and SOAP services.

Quick question 1: What is the purpose of Apache CXF in Mule?

Quick question 2: I have seen some Apache CXF RESTful web services without Mule. Does it run in a servlet container in such a case? If yes, how is it different from deploying the web-service in Mule?

About Intgration

The consuming application will run in another server. It will will make SOAP or rest URL calls to the aforementioned web service. Based on the application type, a response will be sent to the consuming application.

Quick question 1: Is my service endpoint common for both REST and SOAP calls?

Quick question 2: Is it even possible to put a RESTful and SOAP web-service on a common endpoint? If not (which I guess is the case most probably), how is the consuming application to know what it is getting?


tl;dr? How does an Apache CXF web service withboth REST and SOAP definitions work when deployed in Mule ESB? What is the end-to-end flow through each layer?

2

2 Answers

2
votes

Quick question 1: What is the purpose of Apache CXF in Mule?

Mule uses CXF to implement both consuming and providing WebServices. There's nothing special about it. It is just a library that mule uses.

Quick question 2: I have seen some Apache CXF RESTful web services without Mule. Does it run in a servlet container in such a case? If yes, how is it different from deploying the web-service in Mule?

You can use CXF also in your own application that you will deploy for example into a tomcat. In that way it will, yes, run in a container. Well, it really don't have that much of a difference. Mule runs in a container itself too. :) Mule ofcourse contains a lot of other functions as well because it is an ESB. You should consider if you need all the features of an ESB or not. If you only need to deploy a couple of WebServices then I think that an ESB is an overkill for your needs.

Quick question 1: Is my service endpoint common for both REST and SOAP calls?

No it will not be. You need to create separate endpoints for both services.

Quick question 2: Is it even possible to put a RESTful and SOAP web-service on a common endpoint? If not (which I guess is the case most probably), how is the consuming application to know what it is getting?

Well, you could use the same inbound-endpoint but I think that you would shoot yourself in to a leg doing so. You could do the separation by the HTTP Request type. SOAP requests are POST requests while a simple REST call (assuming you are fetching data, not posting) would be a GET request.

1
votes

My first suggestion is (having done it before) to not use Mule for web service deployment. It can, of course since CXF provides the ability for Mule to consume and deploy web services. However, if you are not using the ESB features of Mule you would be better off deploying your services to an application server like Tomcat. Even if you are using the ESB for service mediation, message routing, data transformation, etc. you might still be better off deploying your services to an separate server. Even MuleSoft offers a version of Tomcat (Tcat) for this purpose.

In Mule, you create an endpoint configuration for your web service (and, yes I do believe you have to have multiple endpoints). With Tomcat (and other application servers) you create a war file of the web application and deploy it the server, typically. I use JAX-WS (SOAP) and JAX-RS (REST) annotations in my code along with JAXB for data binding. I Spring to configure the SOAP and REST endpoints in the web service configuration. I also use Maven to build, test, package, run and deploy the web service.

The client will need to know which web service it is using ahead of time in order for it to work. SOAP and REST request/responses look different. Typically, to consume a SOAP service, you will generate the client code using wsdl2java. You can also consume SOAP services by POSTing xml strings of the SOAP envelope to the SOAP endpoint. You can call a RESTful service in approximately the same way (without the SOAP envelope), but it could also be a GET or a PUT (not POST). It is possible to generate a WADL using CXF, which describes the RESTful service in a similar way. This can be used to generate client code using wadl2java.