Alireza Noori
Alireza Noori

Reputation: 15253

Access java app from PHP

I have a java app. It has 3 important functions that provide important data. I want to create a web interface for this app. I want access these functions (call them) from a PHP and retrieve the returned data. What is the best way to achieve this? I previously created a WSDL web service but I encountered some problems explained here:

https://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped

and here:

PHP: SoapClient constructor is very slow (takes 3 minutes)

If there's any other way (or a better way), please let me know how can I do it. Thank you in advance.

Upvotes: 2

Views: 836

Answers (3)

anubhava
anubhava

Reputation: 785156

There are couple of more viable alternatives:

Here is a good tutorial on integrating Java with PHP using Thrift

Upvotes: 1

Adrian Rodriguez
Adrian Rodriguez

Reputation: 3242

Expose the java app as a service using JAX-RS. You can use Jersey http://jersey.java.net/ to get up and running relatively quickly. Once you do that, you can easily issue curl commands with stuff like:

Assuming you have the necessary jars from jersey and you've configured the web.xml (follow jersey getting started tutorial), you can do this on the java side:

@Path("/helloservice")
public class HelloServiceResource {
    @GET
    @Path("/sayhello")
    @Produces("application/json")
    public String sayHello() {
        return "{\"message\":\"Hello\"}";
    }
}

Now in PHP you can:

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://myserver.com/myapp/helloservice/sayhello");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

Upvotes: 0

stevebot
stevebot

Reputation: 24005

Hessian is a protocol you can you:

http://en.wikipedia.org/wiki/Hessian_%28web_service_protocol%29

Upvotes: 0

Related Questions