Building REST Java API on existing PHP server - java

In a recent academic project I need to create some REST Java API (web service) that works on an existing PHP server.
I don't have much clear ideas on how to implement it. How would you implement the logic? Is it okay to send a request (Ajax) to the web service, which it then forwards it to the PHP server?
How would you implement it?
Thank you for your advises!

Java REST service could call PHP REST service. If REST service on php side not implemented, we can use some html robot for acting like a http client from java. HtmlUnit or Selenium for example.

Related

Use C# or VBA to call Jersey JAX-RS REST Webservice

I have a Jersey REST webservice and it works fine with java client. Now I'm wondering is it possible to use C# or VBA to call this webservice? Sorry I am new to C#/VBA. I am trying to create a add-in for excel. As far as I know I can use these two to create add-in. So my questions are:
What's the best way to create add-in in excel for getting/uploading data? Is Java possible? Or should I use C#?
If I use C#, is it possible to call java webservice in C#? I want to upload data via this webservice.
Thanks in advance.
Anything that can build an HTTP request matching the input expected for your Jersey REST service will work. JAX-WS and JAX-RS services are going to be exposed as agnostic access points for anything which can send an XML/JMS or HTTP request. You can confirm this by simply opening the endpoint in your web browser and trying to submit some GET requests that way.
That is the beauty of web services, they SHOULD be language agnostic. Basically you are just calling a url to return you some xml/json data which c# can handle.

Rest vs SOAP with regards to WSDL

I'm not completely clear on one thing and am hoping some one here will probably answer this.
I worked on an enterprise application where we had a Java app consuming services with a WSDL interface in between and a .NET application on the other side producing the services.
I have been reading RESTful webservices where jersey API is used to route a request through a jersey servlet to an URI that eventually talks to a Java class to send the data back.
I'm not able to understand the point where diverse applications like .NET and Java can talk through a REST interface and how for this particular scenario Rest is useful.How does Rest work in this case?. for SOAP there is WSDL, what about for REST assuming a Java app is consuming from a .NET through a Restful service. Please explain how it works.
Thanks in advance!
Both REST and SOAP use HTTP for communication. Requests are sent over the wire using the HTTP protocol from client to server. The server replies using the same protocol. As long as the client and the server both send information using HTTP, it doesn't matter what language the client or server are written in.
RESTful APIs may use some combination of WADL, HATEOAS, and documentation to reveal their API to clients.

Communication between JSP/Servlet and PHP pages?

I am working on a web based Java application(on localhost) and I want to send email using a PHP script which is hosted on a free web hosting site and also return to my java app.
Like this ->
Java(localhost)---->PHP(send mail)---->Java(localhost)
Few questions regarding this?
How to do this?
What about the session stored by the java app? Will the PHP script
read or interpret java's session?
My suggestion is Implement an web service (in REST or SOAP Architecture) with php
then in java code call your web service and Implement an acknowledgement response for
successful or failure mail sending operation in your php!
SOA (Service Oriented Architecture) could be one of best approach for communication between
different platforms.
if you use php only because of ease of sending mail it would be fine to know that java also
have JavaMail API that can be used for mailing application very easily
I hope it be beneficial
Regards

Consuming Java RESTFul web service with PHP client

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.
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.

Implement server and client

I need to implement a server that downloads a webpage and sends it to a client that saves it as a file.
On the server side I need to process socket.
So I was thinking about making a web service in java (with netbeans) but I don't know how to start the web service (I use osx lion).
How can I start the web service?
Is there another way to solve my problem?
Thanks
I'd strongly consider just using an HTTP-based RESTful client/server, using any of a million server-side frameworks. The server-side option may influence the client side implementation.
For example, you could use something like Jersey, which can also create the client-side library needed to consume your service.
On the server side I'd use something like HttpClient to retrieve the websites that will be returned to the client app.

Categories