ProjectStruture

159 views
Skip to first unread message

Sam Wootton

unread,
Feb 19, 2016, 8:54:25 AM2/19/16
to GWT Users
​Dear GWT Users,

Many thanks in advance for any help and advice. Very much appreciated!

I have a legacy application: java Swing client with XML based Servlet communication (request and response).

The server comprised of aro
​​
und 10 Servlets, one 'Front Controller' that forwarded (RequestDispatcher
​ ) to other Servlets depending on the initial XML request from client.  These delegated Servlets did everything (parsed XML, db queries, session data, etc).​

I decided move java swing client to gwt. Also move from XML to gwt rpc.  Ideally I dont want to rewrite the whole server again (even thought it just talks in XML / Strings).

I thought I could just forward my request from my main RemoteServiceServlet class, on to my 'legacy' XML servlets.

What do I have so far?

A working GWT client, making RPC calls to my RemoteServiceServlet.
Successfully set session data and forward on to a e.g. LoginServlet.
LoginServlet queries db and updates session data.
Read updated session data in RemoteServiceServlet.

For example:
RemoteServiceServlet
getThreadLocalRequest().getSession().setAttribute("username", username);
requestDispatcher = getThreadLocalRequest().getRequestDispatcher("/LoginServlet");
requestDispatcher.forward(getThreadLocalRequest(), getThreadLocalResponse());

LoginServlet
String username = (String) session.getAttribute("username");
// do some db stuff & set new session data
session.setAttribute("userEmail", userEmail);

RemoteServiceServlet
getThreadLocalRequest().getSession().getAttribute("userEmail")

This seems very convoluted and hacky, and not scalable for the amount of work done in my 'legacy' servlets.  Is there a better way?

Can I have multiple servlets extend RemoteServiceServlet?
Whats the best way to implement a 'front controller' style architecture with gwt?
Whats the best way to integrated multiple legacy XML servlets with a GWT facade / front controller?
My legacy servlets just read and write a lot of XML, for example

<MFRequest>
<Request type='SaveSettings' data=''/>
<UserPrefs download_pref='../' email_pref='yes' decompress_pref='no' password_pref='no'/>
</MFRequest>

 
I have a lot of XML data, session data and file upload / download data (hence have these split up in to different servlets).

Anyway-  hope this gives an overall picture of my project / problem(s).

Regards, Sam


Sam Wootton

unread,
Feb 19, 2016, 12:18:44 PM2/19/16
to GWT Users
I guess one of the main problems is jumping from RemoteServiceServlet (setting session data), then handing control over to a 'standard' Servlet (which does db work, business logic, sets new session data and attempts to write, a now redundant?, response)... then jumping back in to the original RemoteServiceServlet and returning the original rpc call.

Btw - Im having problems formatting my posts here (using Firefox 42.0b9), I cant put spaces in between words in my post titles, apologies :]

Regards, Sam

Gilberto

unread,
Feb 19, 2016, 1:35:56 PM2/19/16
to GWT Users
I don't think my comment will help you out, but in my opinion you shouldn't go to GWT RPC if you're rewriting the communication with the server. Go RESTful. Given the nature of your application, a pure RESTful structure can not be achieved, but at least you can start using REST frameworks, such as Jersey (on the server) and RestyGWT (on the client).

I say that because I'm currently working on a project where I have to convert GWT RPC calls to REST calls, to enable the server to be called from native mobile apps. Trust me: I'd be happier if I had started RESTful since day 1.

About the XML stuff: were you using SOAP? Or something else? Is the XML just the transport for the entity data? If so, you could replace it with JSON... without having to write the parsers for it. You get it for free when using Jersey or any other REST framework for Java.

Sam Wootton

unread,
Feb 19, 2016, 2:17:36 PM2/19/16
to google-we...@googlegroups.com
Thank you Gilberto, good advice. Im not sure it will reduce work or achieve the 'minimal' server rewrite (or rather maximal legacy reuse), but at least it will be done properly.  I hadnt heard of RestyGWTbefore, so thanks.  I'll give your advice a go, and see where it takes me.

Regards, Sam

--
You received this message because you are subscribed to a topic in the Google Groups "GWT Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/rR0liCZDSl4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Paul Robinson

unread,
Feb 19, 2016, 2:54:49 PM2/19/16
to google-we...@googlegroups.com

GWT RPC may not be supported beyond GWT 2.8, so I'd be wary of using it for a new project now.

Paul

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.

Kirill Prazdnikov

unread,
Feb 20, 2016, 1:22:29 AM2/20/16
to GWT Users
Can you avoid rewriting the server code at all ? 
It might be possible to just rewrite a client in GWT and leave the protocol as is.

Sam Wootton

unread,
Feb 20, 2016, 3:29:05 AM2/20/16
to google-we...@googlegroups.com
Hello Kirill,

That's *exactly* what I want to aim for, that would be ideal. Hence my original post. But given that my communication between my java swing client and my servlets was xml based e.g.
<?xml version="1.0" encoding="ISO-8859-1"?>
<MFRequest>
<Request type='Login' data=''/>
<Login username='sam' password='test'/>
</MFRequest>

<MFResponse>
<Response type='Login'>
<Login name='Sam' session='CF66F005071BD0BC4F0B4D089A4F191A'/>
</Response>
</MFResponse>

now looks like (from the front-end)
server.loginUser(userName, password, repo);

then all the xml modelling is no longer applicable, and org.w3c.dom.* libraries used in the swing client to parse the XML arent available in gwt. on my server I use Document Builder and sax libraries. As mentioned in my previous post, I had a front-controller pattern e.g.

ControllerServlet
> LoginServlet
> UploadServlet
> UpdateServlet
.... etc

which Im finding hard to model in gwt's rpc world.  If i could just use a new gwt client with my old xml / servlet based server - then great! id be very happy indeed. I should also mention that my application uses multi-part file uploads too.

Regards, Sam
 

Kirill Prazdnikov

unread,
Feb 20, 2016, 7:13:12 AM2/20/16
to GWT Users
Sorry, I did not get you question.

You server uses HTTP protocol. 
You are able to sent HTTP requests form a GWT application to you server.

What prevents you from doing that ? 

-Kirill

Sam Wootton

unread,
Feb 20, 2016, 10:24:05 AM2/20/16
to google-we...@googlegroups.com
Hi Kirill,

​It was my understanding that GWT used rpc as its protocol.  Additionally, as im constrained to JS libraries, I dont have access to any of the Document / XML modelling and parsing libraries that I use in core Java, so thought that XML based HTTP communication was not an option.

How can a GWT front-end, make standard requests and parse responses of plain http based XML?
Can it also handle file uploads to servlets?

Apologies... perhaps i've got a huge gap in my understanding.  I went through "GWT In Action" book, and didnt see anything that suited my project.

Regards, Sam​


--

Jens

unread,
Feb 20, 2016, 10:46:02 AM2/20/16
to GWT Users
GWT-RPC is just one convenient way to communicate with a server using GWT. However GWT-RPC uses its own serialization format that is based on JSON. While convenient to use GWT-RPC also has some pain points that are often discovered later.

If you just want to make a POST / GET to an URL and transfer some serialized data (JSON, XML, custom) you can use GWT's RequestBuilder class (which is actually used internally by GWT-RPC as well). In order to get your XML going you can use GWT's XML API http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsXML.html or use a library that maps from Java POJOs to/from XML. As example of such a library take a look at https://github.com/hpehl/piriti

The above should allow you to not rewrite all the server side code.

-- J.

Sam Wootton

unread,
Feb 20, 2016, 11:48:06 AM2/20/16
to google-we...@googlegroups.com
Thanks Jens... perfect. Exactly what I was after (before I disappeared down a dead-end of rpc calls and tons of re-writing, which I'd probably give up on).

Loads to look in to, and get going on.  Thank you. I'll see how far I get and post any questions I have.  Hopefully my only remaining concern is the file upload and download functionality.

Thanks again, much appreciated.

Regards, Sam

--

Kirill Prazdnikov

unread,
Feb 20, 2016, 12:08:34 PM2/20/16
to GWT Users
Hi Sam, 

Think of it differently. 
GWT is a java compiler at first. You live in a HTML5 system. 
This system supports String operations (so that JSON+XML).
It supports File Download\Uploads (and binary).
It supports HTTP requests.
It supports DOM, Canvas rendering, WebGL + 3D VR + Web 3d Audio, e,t,c.

As a result all of that is supported in GWT.

Right ?

Sam Wootton

unread,
Feb 21, 2016, 4:07:02 AM2/21/16
to google-we...@googlegroups.com
Thank you all for your prompt, and very helpful responses.  It's very much appreciated!

Thanks for explaining not just the "how", but the "why" too. Hopefully it's saved me lots of blood, sweat and tears. If I get stuck, ill be sure to ask.

Regards, Sam

--

Kirill Prazdnikov

unread,
Feb 24, 2016, 2:55:58 AM2/24/16
to GWT Users
Can I add one little comment.

Sam, If you find a "portable" XML parser you will not only use it in GWT, but you also can use it whatever: Android client, iOS client (there are compilers), GWT client 

This is what I'm trying to do now is to move more of our code to "multi-platform" package. 
Reply all
Reply to author
Forward
0 new messages