java2db

How to call java RESTful web service in PHP client



RESTful web services are lightweight and fast to access. These are good to use in web based application communications and data exchange . It is easy to call java RESTful web service in PHP client with simple php code.

So first create a simple RESTful web service in java .

 

call java RESTful web service in PHP clientBasic requirements to create a java RESTful web service  :

 

Softwares :
Java (Download).
GlassFish server (Download).
Eclipse IDE (Download).
Jersey Jar files:  (Download)
jersey-client.jar
jersey-common.jar
jersey-container-servlet.jar
jersey-container-servlet-core.jar
jersey-media-jaxb.jar
jersey-server.jar
servlet-api-2.4.jar

 

call java RESTful web service in PHP clientIn the example application  , we used Jersey jars released from Oracle, If you want ,you can use other libraries like RESTEasy  from Jboss and others.

 

 

 

call java RESTful web service in PHP client Step 1 :

Create a dynamic web project in IDE ( Eclipse , NetBeans , MyEclipse or RAD ).

Crate a java class ( HelloWorld .java) , jsp file (index.jsp) and web.xml  and copy the source code.

Add all jar files to the lib folder of the project.See the directory structure below.

 

 

call java RESTful web service in PHP client

 

 index.jsp

 

call java RESTful web service in PHP client HelloWorld .java

 

 web.xml

 

 

 

 Step 2 :

Deploy the above web project in any web/application server like GlassFish , Tomcat , WebSphere , Wildfly or JBoss. Use latest server version. Otherwise it may ask additional jar files.

 

WSDL in java Web Services

 

 

 Step 3 :

Test the RESful web service application with it’s URL from the web browser.

Enter URL (localhost:9090/RESTfulWebServiceExample/index.jsp) in the browser address bar .

After successful submit , you will get the below screen.

 

WSDL in java Web Services

 

 Step 4 :

Click the link (Click Here ) to call the resource of the RESTful web service . Finally the web service return the below output.

 

WSDL in java Web Services

From the above (screen) response the URI is,

http://localhost:9090/RESTfulWebServiceExample/hello/welcome

localhost : Is the IP address (127.0.01).

9090 : Is the server port.

RESTfulWebServiceExample : Project name (Web application name).

hello :  Is the <url-pattern>  that configured in the web.xml file .

welcome : Is the resource path that configured in the HelloWorld .java class (@Path(“welcome”)).

 

Now create a php client to call it using the URL.

RESTful web service example in java using JAX-RS (Eclipse , GlassFish) Steps to call java RESTful web service in PHP client :

 Step 1 :

Create a php file at server location (If it is XAMPP create at htdocs location).

In the below example we created at C:\xampp\htdocs\phpServiceExe .

 

 

 Step 2 :

copy the below code to the php file to call java RESTful web service in PHP client. No need to add any library to run the application.

 

 

 

 Step 3:

Start the web server to run the phpRESTfulClientForJavaService.php file .

 

 

 Step 4 :

Open a web browser and enter the URL of the php file.

http://localhost/phpServiceExe/phpRESTfulClientForJavaService.php

See the output below .

WSDL in java Web Services

Successfully we used the java RESTful web service in PHP client.




Related Posts :
How to call C# .Net WCF web service in PHP SOAP client
How to call PHP RESTful web service in java client
How to create a java client to call PHP SOAP web service
How to create PHP RESTful web service and client with example
How to call java SOAP web service in php ( php web service client )
   [will not be published]



^ <