For building a RESTful web service application that will consume and produce JSON is there any benefit to using Apache CFX over Spring MVC using and #RestController?
I've done some research on both and was planning on using Spring MVC and #RestController. However I've done some reading on Apache CFX and it is an implementation of both JAX-RS and JAX-WS. Apache CFX also claims to be high performance so I'm not sure how it would compare to Spring MVC with #RestController.
Is there going to be a significant difference between the two?
Related
I read the documents of Ballerina https://ballerina.io/. I am interesting about Ballerina. Is there are any framework to build the web app using Ballerina?
At the moment there is no Web frameworks similar to ASP.NET MVC or Spring for Ballerina. However you can easily create single page web applications using Ballerina RESTful services. This is similar to ASP.net WebAPI or python with flask.
There you separate the Web pages which are written in HTML/JS.. from the backend APIs which you can write in Ballerina.
Please take a look at this https://ballerina.io/learn/by-guide/restful-service/
This question already has answers here:
Servlet vs RESTful
(3 answers)
Closed 6 years ago.
I have created many REST web services providing JSON before using PHP and NodeJS and I know the concept.
Now I want to re-implement those web services using Java instead. After doing some research for how to implement web services in Java, I found some standards or libraries like JAX-RS, Spring or Jersey. However I not know the difference between all of them.
I wonder why we do not make a simple servlet which will be called through HTTP request and returns the result in the JSON format. And if I wanted to use one of these standards, what would be the best choice to implement web services that accepts HTTP requests and returns JSON?
You can use a stone to drive a nail into the wall. For sure you can. But why would you do that if you have a hammer available? Using the proper tool will make your life a lot easier.
In a similar way, you can create REST applications using only the Servlet API. However, there are other APIs that are designed to create REST applications. So, why don't you use them?
JAX-RS and Jersey
JAX-RS, currently defined by the JSR 339, is the standard Java API for creating RESTful web services and it's built the top of the Servlet API.
It's important mention that JAX-RS is an specification. In order to use it, you will need an implementation, such as Jersey, which is the reference implementation.
A few resources that may be useful:
JAX-RS 2.0 specification
Jersey documentation
Spring Framework
The Spring Framework allows you to create RESTful web services and it can be easly integrated with other Spring projects.
A few resources that may be useful:
Spring Framework website
Spring Framework documentation
Guide to build a RESTful web service with Spring Framework.
Other resources you may consider useful
Why use a framework for RESTful services in Java instead of vanilla servlets
Why use JAX-RS / Jersey?
Spring 4 vs Jersey for REST web services
Difference between JAX-RS and Spring Rest
You can do it using Servlet API actually. But you won't get all the benefits of JAX-RS like url mapping, parameters injection, ... You would have to write all this "by hand".
By the way, the difference between JAX-RS and Jersey is that JAX-RS is a specification, a standard and Jersey is an implementation of that standard. There are other implementations as well (RestEASY for example). Spring also has a module for REST services.
I have developed RESTful web services in two ways:
used a class that extends javax.ws.rs.core.Application without defining a web.xml file, using Glassfish.
haven't used javax.ws.rs.core.Application but included a web.xml and a Jersey implementation, using Tomcat.
Is there a preferred way of building RESTful web services with JAX-RS?
Using the javax.ws.rs.core.Application class is the preferred way and also the only portable way of configuring resources and providers in a JAX-RS web service,
so if possible that would be the recommended way to set it up.
But that works well only in JAX-RS aware servlet containers or application servers, for JAX-RS non aware servers you need other ways for deployment and that most of the times means some proprietary servlet class of the JAX-RS implementation you are using.
To get more details on the subject, see for example the Jersey documentation, Deploying a RESTful Web Service (for Jersey v1.x) and Application Deployment and Runtime Environments (for Jersey v2.x).
I would be grateful if any one help me to understand the difference between axis2 web service and CXF web service.
The main differences between axis2 web service and CXF web service are as follows:
CXF has support for WS-Addressing, WS-Policy, WS-RM, WS-Security,
and WS-I BasicProfile. Axis2 supports each of these except for
WS-Policy, which will be supported in an upcoming version.
CXF was written with Spring in mind; Axis2 is not.
Axis2 supports a wider range of data bindings, including XMLBeans,
JiBX, JaxMe and JaxBRI as well as its own native data binding, ADB.
Note that support for JaxME and JaxBRI are still considered
experimental in Axis2 1.2. CXF currently supports only JAXB and
Aegis; support for XMLBeans, JiBX and Castor will come in CXF 2.1.
Axis2 supports multiple languages--there is a C/C++ version
available in addition to the Java version.
In comparing these frameworks, though, it's just as important to look at their approach to developing web services as it is to compare features. From a developer perspective, both frameworks behave very differently from one another. Axis2 has taken an approach that makes it in many ways resemble an application server in miniature. Axis2 comes packaged with a WAR that can be deployed on a servlet container such as Tomcat that is designed to make web services easier to manage and deploy on the fly. The Axis2 Web Administration module allows Axis2 to be configured dynamically while applications are running--new services can be uploaded, activated or deactivated and their parameters may be changed. The administration UI also allows modules to be enabled on one or more running services. The only downside to using the UI for these purposes is the fact that configuration changes made through it are not persistent--they go away when the servlet container is restarted.
Axis2 lends itself towards web services that stand alone, independent of other applications, and offers a wide variety of functionality, and a good model for adding more functionality as time goes on through its modular architecture. Some developers may find that a little too cumbersome or heavy-duty for their needs. These developers might prefer to look at Apache CXF.
CXF concentrates on developer ergonomics and embeddability. Most configuration is done via the API instead of cumbersome XML files, Spring integration is heavily emphasized, including support for Spring 2.0, and CXF's APIs and Spring configuration mirror one another fairly closely. CXF emphasizes code-first design, using simple APIs to make development of services from existing applications easier (and its embeddability helps too).
Whichever framework you choose, you'll have the benefit of an active and stable open source community. Each of these frameworks has corporate backing: Axis2 is backed by WSO2, and CXF by Iona. Both have lively developer communities. Axis2 has been around longer but CXF is catching up quickly. My recommendation is this: If multilanguage support is important, Axis2 is the clear choice. If you care about an implementation focused on Java with tight integration into projects like Spring, CXF is a better choice, particularly for embedding web services inside of other programs. If the new features in these projects are not important, and you're relatively happy with Axis1, you should consider staying on this and keep up with the latest maintenance releases until you have a business reason to migrate.
I have web application designed using spring 2.5.5 MVC, JBoss server. I want to expose my spring services (like add/update User, comments, documents, etc.) using WebService for EAI. Requirement is like any third-party application should be able to perform operations in my web application after authentication/authorization.
I have novice knowledge of SOAP (Axis2) and REST (Jersey), however i am not sure which will be best suited for my application.
Cheers
We are using Spring 3.0 actually. But former using Axis2 with Spring 2.5.x.
You might review our stack at http://incubator.apache.org/openmeetings the axis.
We simply integrated the regular Axis2 configuration into the web.xml and build a Facade to load the spring beans into the Axis enables Web-Service and forward the calls to the Spring enabled context that way.
Comparable to https://svn.apache.org/repos/asf/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/axis/services/FileWebServiceFacade.java
It is not the perfect solution, the Axis2 documentation also contains other ways to load the Spring context in the Web-Service enabled class, however it was never possible to make that work stable so we decided for this workaround.