Can I merge these two web applications to become one using GWT Servlet and RESTful API? - spring

I have started to write two web application projects
RESFful API for mobile clients using Spring REST API
GWT WebApp Server for web clients using Servlets
My problem is that both web applications are using the same database and that I think that instead of having two web applications I actually should have started this project using just one web application that handles the requests for web and mobile clients.
The problem I got now is that I don't have any idea how I could "merge" those two guys and whether I should stick to Spring REST API or if I should use RestyGWT.
GWT Server-Project using Servlets
RESTful Server using Spring
All projects (in the middle of a major refactoring mission)
Is there a way that would allow me to launch the web application as a whole and have access to the REST API from my mobile clients and to the Servlets from my web clients?

It depends on your business logic implementation. If you have it in a separate module/package, then it should be easy to merge your two applications.
You will have to rework the mappings in web.xml and how you pass the input/output data to the business logic methods from both the REST implementation and your servlet code.
Personally I will recommend a single approach such as only going with the REST based approach that you already have and migrate your servlet functionality to it.

Related

Plain Servlet vs Spring MVC

I have to create a web application, I need to use my back-end code for mobile apps also.
I know Servlet, I thought of doing this application with "REST API" + HIBERNATE for server side and Javascript(Angular JS ) in UI.
Some of my colleagues suggest to do this with Spring. I don't know anything about Spring. While reading about Spring I came to know that back-end logic and UI code can be in same place. It seems it is tightly coupled with back-end and front-end.
Some times back Jquery is more preferable JS framework but now everyone suggests Angular JS. This will be changed after some times. But logic I am going to write in back-end will be the same.
How can I choose the correct one?
I suggest to use:
Spring web MVC for backend https://spring.io/guides/gs/serving-web-content/, maybe with Spring Boot, and Hibernate for DAO layer. Here you can find a helpful example (without Spring Boot): http://websystique.com/springmvc/spring-mvc-4-and-spring-security-4-integration-example/
and for frontend certainly Angular 2, with TypeScript, instead of Angular js, and here reach the REST service exposed by backend.
These days it is easy to build a REST based back end with no libraries at all if you deploy to a Java EE 6/7 server such as WildFly, TomEE or Payara (amongst others).
You get JAX-RS and JSON-P (for rest), JPA for persistence, web sockets, asynchronous processing, transaction management and the rest of the Java EE stack for free.
Try a google search for Java EE thin war - there's lots of examples about

Spring REST API for web- and mobile-clients

This is my first question on StackOverflow and I hope someone can help me. :-)
I am planning to build a web-application (backend) with spring roo. For the backend I will use Spring and Hibernate/JPA. In the future I will implement a web client (JSF/Primefaces), a mobile client (Android) and a Windows App.
With spring roo it is easy to create a layered architecture with domain classes, repositories and services. This part is fun.
But now I am thinking about remoting and how to connect all the clients (web, mobile, windows) with my backend.
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource-oriented but how do you implement authentication with REST API?
At the moment I think a REST-API is a good idea. Because I am using spring it is easy to create a Spring MVC controller with REST support. But is this the correct way to implement a REST API for all the three devices? The web client e.g. should be implemented with JSF and Primefaces and I donĀ“t use spring MVC for the web layer.
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
I don't have too much experience with SOAP-WS, but I have a ton of experience with REST-APIs using JSON. There are many implementations for mobile, web and server side clients that are fairly simple to implement.
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource oriented but how to implement authentication with REST API?
If you are already using spring, I recommend securing your API with Spring Security. You can use spring security even if you don't end up going with Spring MVC for your API implementation. There are many ways to secure a rest API with spring security, but I the simplest is to send the basic auth header with every request to a secure URI
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
Spring MVC Controllers will work fine, but I would recommend going with RestEasy or Jersey. I find them to be more flexable.
I agree with #mad_fox. Additionally, i want to add another option regarding your question#2. If you dont want to use Spring security, you can write your own token based authentication mechanism using spring and basic java interceptors.
You can store the token in your browser local storage.

Spring MVC and Web Application separated

I have been Googling a lot lately, but I find myself coming up short on answers.
I have a complete Spring MVC application secured by Spring Security and with services exposing logic to controllers (controllers -> service -> repository -> POJO's).
Currently all my controllers, except the login controller, serve nothing but JSON/XML and I want it to stay this way. I do not want to render different views on each controller.
However, what I want to be able to, is to separate the web application from the backend because in time I want to be able to integration with my service using more platforms than just a web browser.
Currently I have the regular Spring MVC application:
Configuration
Domain(POJO's)
Repository
Service
Controller
Login is done using a Thymeleaf rendered view and Spring Security which does nothing more than filtering all urls under the application root. After this, it is just a bunch of static files being served as resources:
Spring Controllers send a "{ontrollerName}/layout" to serve the AngularJS HTML partial used for all data under that given Spring Controller.
What I want, is a way to separate everything in the /webapp directory from the rest of my project. I have looked into a few different solutions here such as using Apache Proxy where my Apache Http server hosts the client code which communicate with the backend using Ajax to rest controllers, and Tomcat hosting the backend. However, I hear that proxying like this is not safe. I could however be dead wrong here.
So, the questions I hope to receive answers to are:
1. Is it fine to just write a client that uses Apache http server's Proxy to provide access to Ajax on the server?
If not; How should I proceed? Is it any point in trying to extract the client side from the /webapp directory or is this just some stupid idea I created because it seemed cool to be able to deploy them without having to relay on each others?
Is there any best practices in regards to how I structure a project with separate modules? Think Gradle build scripts for multi modules.
Should I think in different terms and use an approach not based on Spring MVC at all? If so, please advice me.
I hope this was clear enough to make sense for you guys.
The solution was to use the simpler approach of a restful API that did authentication over OAuth 2.
Basically the two best alternatives are a hybrid solution (part restful API and part server side rendering of pages) or a full blown restful API where you implement all functionality in a static web client. This way there is no need for multi-module projects and packing things together in one package.

Is it worth to use Spring Integration instead of Spring MVC for web-based or mobile based application?

I am developing web application, also in my product we are also providing financial-non financial mobile services.
Going in details.
In my web application, there is nothing like maintaining flows step by step , simple all CRUD operations and currently we are using Spring MVC which fits to our requirement but for mobile based services, we are providing like message bus support to exchange piggy back information between client and server and we have custom code to implement the solution.
Also our mobile based services need to be exposed over different protocols like SOAP,REST along with need of decoupling of communication packets from services.
All above problems we solved using SPRING MVC only.
My Question is
Is it worth to use Spring Integration framework to replace custom code solution to implement message bus with Spring Integration and if so, what will be the flow for my web application?
If I am using Spring Integration for my web application, how it will render HTTP request to SI?
Is Spring Integration is right choice for any standalone web based application?
Spring Integration is modeled on the Enterprise Integration Patterns and can be best thought of as support Message Driven Architecture. Spring MVC's history and origins is in providing a solution for the MVC pattern akin to Struts, exposing Models and Controlling Views, supported by Services, primarily in a linear fashion. One of the cores of Spring MVC was allowing the dynamic population of a Model that would be accessed by a JSP page (View). All of these things being Web App orientated and ending their.
With the evolution of services (Web, RESTful), Spring MVC has filled a gap and continually expanded to support HTTP access to services, though this is an expansion of its duties, rather than first origins. Meanwhile, Spring Integration was designed with the view of handling Messages and a messages interaction with services, independent of the protocol that it was accessed on. To enable different protocols, different endpoints are available to expose the same service. For example, I can have my crud services built in a POJO, exposed through a Service Activator, and now available to a number of different protocols including REST via HTTP, WebServices, Twitter, XMPP chat services, RMI, TCP, etc. etc.
in short, Spring MVC == HTTP access, Spring Integration == Message access (from HTTP, File, DB, etc.)
to expose a service via HTTP in Spring Integration, use the HTTP endpoints. Typically in a Request/Response (say a Read from a database) you'll want to use the <int-http:inbound-gateway/> and it would look something like this;
<int-http:inbound-gateway request-channel="request.channel" reply-channel="reply.channel"
path="/myService" supported-methods="GET"/>
<int:channel id="request.channel"/>
<int:service-activator input-channel="request.channel" ref="myService"/>
<int:channel id="output.channel"/>
(a key point to remember to is the following...
<bean class="org.springframework.integration.http.inbound.UriPathHandlerMapping"/>
this helps map the path attribute of the inbound-gateway to the servletdispatcher)

spring mvc + desktop app = best protocol and gui framework

I wanna create spring app which will consists of 2 parts :
spring backend + spring mvc (server + web app)
desktop app which need to acces to backend
Whats best protocol to comunicate between spring and desktop app? Can i use SOAP for this? Can someone do quick overview of avaliable technologies (why not/yes)?
And whats best choice for desktop app GUI framework? or its better to use pure Swing / AWT.
I want to notice that i wanna use solutions which is most popular in software companies.
I appreciate every opinions.
The companies I work for aren't interested in Swing. Apps are web-based, not desktop. You're more likely to find mobile apps rather than Swing these days.
With that said, your instinct is a good one: separate the services, which are unlikely to change, from the UIs that come and go.
Start with Spring POJO, interface-based services and remote them any way you like.
An HTTP-based protocol will be more reusable by different clients.
Spring allows you to use HTTP remoting, SOAP or REST web services. If you write web services, learn how to write "contract first". Start with the .xsd for your XML messages.

Resources