Apache CXF + Mule ESB, SOAP + RESTful web service. How to do it?

I am new to Java web services and am currently working on this using Apache CXF. It will have JAX-WS (SOAP) and JAX-RS (REST) โ€‹โ€‹support. It will be consumed by desktop and mobile applications. While researching Apache CXF, I came across some showstopers. Can anyone help me with flow in terms of layers?

FYI . I have previously worked with the Google Maps API. I developed a consuming application in .NET and honestly represent web services (both SOAP and REST). I am having problems with these implementation details in Java.


About the service

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

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

Quick question 2 . I have seen several Apache CXF RESTful web services without Mule. Is this done in a servlet container in such a case? If so, how is this different from deploying a web service in Mule?

About integration

The consuming application will run on a different server. It will call SOAP or the rest of the urls for the above web service. Based on the application type, a response will be sent to the consumer application.

Quick question 1 . Is my service endpoint shared between REST and SOAP calls?

Quick question 2 . Is it possible to host a RESTful and SOAP web service on a common endpoint? If not (most likely it does), how is the consumer application supposed to know what it is getting?


TL, dr ? How does Apache CXF web service with REST and SOAP definitions work when deployed to Mule ESB? What is the end-to-end flow through each layer?

+3


source to share


2 answers


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

Mule uses CXF to implement both consuming and providing WebServices. This is nothing special. It's just a library the mule uses.

Quick Question 2: I've seen some Apache CXF RESTful web services without Mule. Is this done in a servlet container in such a case? If so, how is this different from deploying a web service in Mule?

You can use CXF also in your own application to be deployed to tomcat for example. This way it will run in a container. Well, he really doesn't have that much of a difference. The mule also works in a container. :) The mule of the course contains many other functions, because it is an ESB. You should consider whether you need all of the ESB features or not. If you only need to deploy a couple of WebServices, then I think the ESB is overkill for your needs.



Quick question 1: Is my service endpoint shared between REST and SOAP calls?

No, this will not happen. You need to create separate endpoints for both services.

Quick question 2: Is it possible to host a RESTful and SOAP web service on a common endpoint? If not (most likely it does), how is the consumer application supposed to know what it is getting?

Well, you can use the same inbound-endpoint, but I think you were shooting in the leg. You can do split by HTTP request type. SOAP requests are POST requests, while a simple REST call (assuming you are fetching data and not wiring) will be a GET request.

+2


source


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

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



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

+1


source







All Articles