Results 1 to 3 of 3
  1. #1
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Default 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 :-).

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    They need a <rambling/> tag..

    <rambling style="incoherent">
    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
    </rambling>
    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.

  3. #3
    BigBear is offline Member
    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Very Simple Web Service
    By wael in forum New To Java
    Replies: 5
    Last Post: 07-28-2010, 10:12 AM
  2. Using a Web Service
    By ragnor2004 in forum Advanced Java
    Replies: 12
    Last Post: 02-06-2010, 01:57 AM
  3. how to call service method inside another service
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 03:19 AM
  4. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 03:55 AM
  5. Replies: 2
    Last Post: 05-04-2008, 06:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •