1

I have a Swing based application which uses a MySQL Database. Currently I am using a direct database connection to connect to the database to fetch/update data. But now I am thinking to create a web service like my android application is using (I am using a PHP web service with JSON for android).

The web service can be consumed by performing a simple GET request. If I paste the URL in a browser, I can see the json decoded echo response.

I have NO experience with Java based web services. Is there any method to use that PHP/JSON based service in Java or to create a very simple web service for my Java application without involving complex libraries/classes?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Gagan93
  • 1,826
  • 2
  • 25
  • 38
  • *Is there any method to use that PHP/JSON based service in Java* yes, there is. This depends on the protocol your service use: soap or rest. *to create a very simple web service for my Java application without involving complex libraries/classes?* depends on what's *complex* for you; it's no rocket science but if you're in learning phase then don't go this way yet. – Luiggi Mendoza Oct 27 '14 at 15:25
  • I am using the simplest web service from PHP ...I just take GET request, run query on database and echo the json_encoded response. How to retrieve this in Java application @LuiggiMendoza ? – Gagan93 Oct 27 '14 at 15:32
  • It seems like a REST service. Then you must seek for consume REST services. – Luiggi Mendoza Oct 27 '14 at 15:33
  • it is not a rest based service. I think we call it RPC based web service, the easiest one in PHP – Gagan93 Oct 27 '14 at 15:35
  • Provide how you consume such service in an external tool. – Luiggi Mendoza Oct 27 '14 at 15:36
  • my friend is consuming this service. he starts with HttpURLConnection class, then creates HTTPEntity, HTTPResponse and simple reads the JSON array – Gagan93 Oct 27 '14 at 15:40
  • something like this http://stackoverflow.com/questions/10500775/parse-json-from-httpurlconnection-object – Gagan93 Oct 27 '14 at 15:41
  • Again: **how**? Is he just performing a simple GET request on your service, is he using some kind of XML format to exchange data and you have to use a tool to test the consumption of the service or is as easy as copy an URL and paste it in any browser and see the results? – Luiggi Mendoza Oct 27 '14 at 15:42
  • if we paste that URL in a browser, we will see the json decoded echo response. And yes, he is performing a simple GET request – Gagan93 Oct 27 '14 at 15:43
  • Have you attempted to work with the code in that link? You seem to have an answer already in that link, I'm not sure what more you expect us to provide you, with what you have in your post. We could give you another example, but if you don't understand the one in the posted answer, what's to say that will understand a different example? You should give it a shot, and if it doesn't work, then post what you've tried and any error/exception/stacktraces you are getting, or simply an explanation about how it's not working – Paul Samsotha Oct 27 '14 at 16:09

0 Answers0