Results 1 to 3 of 3
Thread: make simple web service
- 06-02-2010, 03:07 AM #1Member
- Join Date
- Jan 2010
- Rep Power
make simple web service
Hi all, I'd like to make simple web service. I made a desktop (swing) application, which requires access to database. The database is not accessible from outside of the server.
But I have web application on this server, so I can create a servlet (or jsp), which could operate as web service. Afterwards I can create a connection in my desktop application directed to this service page. The page downloads required data and grants them for my desktop application.
But I don't know the way I could do it. Can you help me please? Thank you :-).
- 06-03-2010, 02:05 AM #2
They need a <rambling/> tag..
Well, I have been thinking for some time that a good web service for swing client applications should be JSON based, instead of XML based. Where JSON is a structured format, well suited for transport within HTTP, and does not have the terse baggage of XML. Plus there are several great JSON based parsers out there to conveniently serialize a java object to a JSON string and then to de-serialize a JSON string back into an object again. One such I have found quite useful is the "easyjson" project on sourceforge.
Then, coming up with some kind of remote procedure call (RPC) style mechanism where by each HTTP request is modelled like a single function call would be, having a function "name", and taking on zero or more parameters, and returning exactly one result object. And then maybe other fluff like a "service" identifier, or some kind of namespace mechanism, a versionioning for the API so different clients can fail gracefully when working with more recent servers.
It turns out, this kind of thinking is already being collected into thoughts and ideas by the "JSON-RPC" (google news group ) There are several other sites focused on earlier implementations of the specification, but it looks like the 1.2 effort is the only active one lately.
So then, we need some kind of simple Java classes to model a JSON-RPC request and response object, and with the above easyjson java-json serializer tool, perhaps we can create a servlet to listen to requests, and maybe I would invent a "service" interface that is registered with the servlet , that contains my specific (in this case database) query functions, so that the JSON-RPC servlet is a general purpose, generic dispatcher of sorts.
The client side could also make use of the easyjson serializer, the JSON-RPC request and response objects, and possibly a HTTP client API, such as that jakarta commons-httpclient.
So then, after figuring out all this technology plumbing, having the actual service of methods that you need to do the thing you want to do, and then creating your own objects to be used as the request parameters when these methods are invoked, and objects to store the results. In theory, you should be able to build a single Java class that implements an interface where everthing the swing application needs to do to the database goes thru this single manager class, using your own request and response beans as the payload, no JDBC specific things, etc. At this point, separating the front end from the back end is a matter of creating client side stubs for this manager interface that just package JSON-RPC requests and send them over HTTP
I dunno, how does that sound ? I have done a lot of thinking about this but just haven't had any time to get around to actually building it.
- 06-13-2010, 12:53 PM #3Member
- Join Date
- Jan 2010
- Rep Power
Well, it sounds great, but I've just read documentation and several example codes and I haven't found any examples with communication between classic desktop (swing) application and web application. It probably is possible, but I have too little time to developing. So I think, that XML-RPC, concretely ws-xmlrpc - Apache XML-RPC will be better for me.
- By wael in forum New To JavaReplies: 5Last Post: 07-28-2010, 09:12 AM
- By ragnor2004 in forum Advanced JavaReplies: 12Last Post: 02-06-2010, 12:57 AM
- By kirtichopra2003 in forum Web FrameworksReplies: 1Last Post: 10-24-2009, 02:19 AM
- By webbusiness23 in forum New To JavaReplies: 9Last Post: 08-03-2009, 02:55 AM
- By cakeman in forum New To JavaReplies: 2Last Post: 05-04-2008, 05:27 PM