2

I am having some problems developing a PHP client that will consume Java RESTful services, created in NetBeans 7.1.1.

For those who don't know: When you create a Java RESTful web-service based on MySQL database (entities), NetBeans will create, automatically, the entities class, and each entity "facade", that can be known as a service provider.

I developed a web application using Java RESTful web-service server and the Java RESTful client that consumes the web-services through Jersey & Servlets.

Now on to a planned PHP client: I already googled a lot, and what I see is: no interoperability (or i'm "the" noob), which is one of the purposes of web-services. I know how to create a RESTful web-service in PHP, and communicate with a PHP client, and the same with Java, but what I want is create the Java RESTful web-services server, and a php client.

Sorry if I said something wrong on the subject, and feel free to correct me.

If anyone could help me, giving me some ideas, code examples, explaining the "know-how", I would appreciate a lot.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
hugh
  • 31
  • 1
  • 4
  • RESTful web services are interoperable, so what exact problem are you facing? How would you write a PHP client for a PHP RESTful WS and why can't you do the same with Java endpoint? – Piotr Nowicki Apr 30 '12 at 12:45
  • @hugh - I edited out your second question at the end. It is really a separate question. Feel free to ask a new SO question for it. For those who care to read it here: "PS: If, btw, someone could explain to me, how to deploy manually a java restful webservice server (.war) to the apache tomcat folder, **with the database connections**, would be awsome." – ArjunShankar May 02 '12 at 11:11

1 Answers1

0

This is rather an easy problem to solve. For an enterprise application, I have modeled this same solution. The Java layer has CXF restful web services mapping to a mixture of SOAP endpoints (external systems) as well as entity objects (mapped via Hibernate/IBatis). Consuming the CXF rest layer is rather simple. In PHP, I would definitely recommend using the Guzzle client.

/** USE REST SERVICES **/

$client = new Client("http://example.com/);

$locationRequest = $client->get('/someservice/rest/location/findstatebyzip.json?zip=12345');
$locationResponse = $locationRequest->send();

$locationResults = json_decode($locationResponse->getBody());

The great thing about Guzzle Client is that you aren't required to have CURL enabled/installed, it can use other transport mechanisms.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47