2

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.

Community
  • 1
  • 1
Alireza Noori
  • 14,961
  • 30
  • 95
  • 179

3 Answers3

1

There are couple of more viable alternatives:

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

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thank you. I used Thrift. There were some small speed bumps along the way but it got me somewhere nice at the end :D I'm happy with the result and I think it was worth the effort. Especially the tutorial that you provided helped me. Thanks again. – Alireza Noori May 18 '11 at 23:15
  • You are most welcome, I had also followed same tutorial to learn Thrift. Other than thorough documentation I think Thrift is pretty robust IDL. – anubhava May 19 '11 at 00:01
  • Excellent, Very nice Blog tutorial on Thrift I must say. – anubhava Aug 05 '11 at 18:01
  • I've moved my tutorial to my new host. Here's the link: [thrift tutorial](http://www.alireza-noori.com/programming/thriftpart-one-introduction/) – Alireza Noori Oct 23 '12 at 08:16
0

Hessian is a protocol you can you:

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

stevebot
  • 23,275
  • 29
  • 119
  • 181
0

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);
Adrian Rodriguez
  • 3,232
  • 2
  • 24
  • 34
  • Thank you. In [my other question](http://stackoverflow.com/questions/5929669/call-a-wsdl-web-service-created-by-java-from-nushphere-phped) I posted how I exposed my app as service. Does it work with that? If so, could you please tell me how can I call the `sayHello` function in the described service? – Alireza Noori May 17 '11 at 23:12
  • Thanks but since I'm new to both PHP and Java, I didn't quite understand how it works. So how can I pass argument? Where do I get the result to use it? And, should I change my Java code to return {message: }, ... stuff? What about string array return type or custom type? – Alireza Noori May 18 '11 at 10:31