GWT client and spring server with rest APIs - java

I am a GWT user and what I appreciate of it is the opportunity to develop web interfaces in Java.
Currently, a team is developing the server side of a web application that offers rest Apis and that is based on Spring.
My idea was to use GWT to create the client side application and, rather than invoking some gwt rest apis, I want to invoke, from such client, the rest apis exposed by the spring-based server.
My questions are: does this sound reasonable? Can i just code and cross compile a gwt client invoking the external rest Apps or do I still need GWT server handing off the requests to the spring-based server? What's a potential deployment scenario? Thanks.

You don't need GWT server capabilities at all (gwt-server.jar). You only need a web server to host your compiled GWT app like nginx.
What works for me is coding simple REST calls (Spring MVC) from the server and GWT using GWTP Rest support.
Jackson and GwtJackson are used in both sides to serialize/deserialize DTO's.
To avoid SOP problems use a reverse proxy or implement CORS.

Related

Developing app with web and Android client with Java

I'm going to start developing a new simple "X management" kind app, like contact management or events management. What I want to know is which tools would be the best to achieve it in the way I want.
My app needs to be a web app running on a server that has a mysql database to save and retrieve some simple information. This app must have a web client but I want it to be able to be extended to work with an Android app client.
Things I've thought:
I've worked on Java with facelets and JPA travels management app running on a GlassFish server on localhost with a JSF web view, so maybe my web client and the full app could be done with this.
I've worked with web services such as SOAP and REST with Jaxb and xml schemes to retrieve information parsing some webs into xml or json to show on a client .net app. So I've thought I can add to my app, like last topic we talked about, a REST web service layer to easily work as I want, or at least I think it would be easy. If I do this the Android app could share the same app core code but using the REST service.
My question is what could be the best way to do an app with 2 client side in different platforms that could share some code to be easy to extend it moreover to a desktop app. I've talked about these 2 options because I'm a students of computers at university and those are the tools I know, but I can easy learn more. I've also think about just a REST service and create a web and an Android client to work on same service or something like that.
This post is getting long, so here is the summary: What technologies and tools do you think are the best choice to create an java web app that needs to have web and Android client? Also what server, like tomcat, GlassFish or another, should I use? And what about persistence layer? JPA with mysql is the best I know to work with.
Thanks a lot.
P.D: I work with eclipse
From my point of view:
You can use java jersey and java spring both ( java spring as Dependency injection) for creating RESTful Web service. So, In server side you will create endpoint and you can access data from any platform through those endpoint.
Server can be anyone. It's up to you. I always try to use tomcat but tomcat is not a full JavaEE container it's only a servlet container. So if you want to use full JavaEE version then you should use Glassfish.
And yes JPA .It can be easily used in any environment supporting JPA including Java SE applications, Java EE application servers, Enterprise OSGi containers etc.
On the other hand, still choice is yours.

Does iPad development work with interacting through Java code with Spring Framework using TomCat to host the web service on a server? How?

Here is the background of my situation:
I want to create an iPad application that interacts with a oracle SQL database. I have existing Java code from my Flex application that handles all the database requests, and modifications using the Spring Framework. The Flex Application ran as a web service through TomCat. Now I want to make that flex application into a mobile iPad version. I am having trouble figuring out what is the easiest way to use existing Java code and use it for the iPad because the iPad interacts using URL requests instead of direct with the Java.
My question is, can I use the existing Java code with the Spring framework to save time from coding all the back-end handling? Basically I want to access all the classes from my Java code by doing Requests from the iPad. Is this possible and will I need JSON or XML to interact between the iPad and the Java code?
Summary:
Can I use
iPad Objective-C <-----> Java (with spring framework) on TomCat Web Service to handle oracle SQL data handeling? If so, how and what technologies do I need? Will I need JSON or XML and how does that factor between the iPad and Java?
Thanks!
A good approach would be to design your app to communicate with RESTful services that return JSON. Once this is done your iPad app doesn't have to even know that the server code is written in Java.. it's just interacting over HTTP.
Here's a good tutorial on setting up your tomcat to host your RESTful services: http://www.vogella.com/articles/REST/article.html - I've used this for an app I'm developing. Spring isn't even necessary.
You could go XML, but JSON is just easier in my opinion. Here's a good blog outlining the good and bad of both sides. http://digitalbazaar.com/2010/11/22/json-vs-xml/
OK, I'm making the following presumptions.
Your flex application runs on a different machine from the Tomcat
server
Your flex application makes web service calls to the Tomcat server
So, the flex application doesn't know the underlying technology that provides the web services. It's just seeing/consuming the output
There's no reason why the iPad app can't do the same thing. There's no reason why it can't use the same web services that the Flex application uses. It could consume the same messages (Assuming it can handle the request/response format currently employed by the Flex application).
You can make changes if you like if you want to change the structure of the requests/responses between the clients. But the clients don't know (nor care) how the web services are implemented. They are just requesting and consuming info.

How should I communicate with Spring backend - GWT front-end + mobile devices

I'm developing a server-client application. It is a service that is supposed to be used by thousands of users so it should scale well. The server side is done in Spring + JPA(Hibernate) and it provides about 80 API methods. There will be multiple clients - GWT webapp, mobile devices clients (iOS, Android, Windows) + a simple desktop client (Eclipse RCP / To be decided).
I'm considering various ways to connect to the server side. My ideas are (maybe there are some other, better ways):
Use SOAP Webservices to expose server API to all the clients
SOAP WS are considered to be slow and I don't know it can handle all the communication
Android doesn't officially support SOAP WS (bu there are some 3rd party libs)
Use RESTfull WS to handle communication
better performance than SOAP
official support on all the mobile devices
may be difficult to access RESTfull WS from non-web, desktop client
Use REST WS for mobile, GWT Request Factory for webapp
Request Factory is recommended way to communicate with GWT client (at least it was on 2009 Google I/O). I suppose it should perform better than Web Services?
Which solution (listed above or not) would perform best and be the most productive for developers?
If you've worked on a similar project, I'd love to know your opinion :)
I'd vote for Using RESTful services on the backend, and interacting with that from the front end of your choice.
This gives you the most flexibility in terms of serving multiple clients. For instance, you can end-of-life a front end technology without having to remove any server side code, or you can introduce a new front end without any back end changes.
If you avoid trying to support both REST WS for mobile and GWT-backed server side classes (such as GWT-RPC) for webapp, you will have the following advantages:
Single back end to develop and test: do not underestimate this!
Ease of monitoring network traffic to debug what either end actually sent. GWT network traffic is not so easy to debug, I'll take JSON over GWT-RPC any day.
Don't worry about one technology or another not being able to consume your services: REST WS is becoming so popular that there are a variety of ways to use those services from any front end. For instance, a GWT app could use GWT overlays to map JSON responses to GWT/Java objects, and a desktop client could use Apache HTTP Client.
If your webservices are RESTful, I will recomend you RestyGWT.
I used it a long time ago and it works pretty well.

Is it possible to access a JAX-WS from a web browser?

I was just wondering, whether is it possible to deploy a JAX-WS and access it from a browser without the need to install any software or proxy classes ..
Of course, JAX-WS is just a library built on top of SOAP, which is built on top of XML, which is built on top of HTTP (duh!)
If you have SOAP web services (the fact that it was developed using JAX-WS is irrelevant), any application capable of sending and receiving XML over HTTP can call it. We are successfully accessing our back-end web services using AJAX POST (the web services must be deployed on the same domain as your front-end due to same-origin-policy).
As far as I've seen it's not possible, since you need to have proxy classes in order to call the JAX-WS functions ... but maybe I'm wrong !

Client architecture for calling Spring based web service

I have written a SOAP based web service which runs fine on a Tomcat server. The Web Service service itself is a Spring MVC based web service that runs on the Tomcat application server.
Now i need to write a Thick client which will be a standalone Java app that will use the services of the web service. I think i am correct in that the client only needs to know about the service details (i.e. operations) and nothing else.
What i am not sure of is the architecture and environment i should use for the client. The client application will be based on Swing but is it possible to use Spring with Swing together?
On the web service i have the following setup
view --> Service --> Model
The client application is basically a configuration tool. It uses the web service to configure user accounts. This means that the client application does not actually write anything to any database. It just uses the services of the web service to make changes to 'user account' and probably view list of accounts.
My question really is
- Is an MVC design suitable for such a use case
- Usually Spring is used for web based applications. Is there any benefit in using Spring with the Swing based client?
- Are there any alternative or better solutions/design/architecture that would achieve the same?
An example showing Spring used in conjunction with a Swing application would be very usefull.
Thanks in advance.
Spring MVC is not appropriate for a Swing-based client. Use the core Spring framework and a JAX-RS implementation like Jersey to provide simple REST web services in tomcat. Jersey also provides a corresponding client API that you can use within your Swing application to invoke the REST services.
If you have decided upon Swing as your platform, there are two options you can look at:
(1) Net Beans Rich Client Platform
http://netbeans.org/kb/trails/platform.html
(2) You can roll up your sleeves and write your own app using a low level yet extremely flexible framework called Swixml
http://www.swixml.org/
Give Swixml a good try before you try others, it may surprise you.
You can implement Swing-based thin client application with Spring Integration backend serving as a integration tier. It can expose gateways accepting simple Java types or DTOs. Your Swing presenters / controllers interacts with these components in order to call remote webservices.

Categories

Resources