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

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.

Related

Building REST Java API on existing PHP server

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.

Passing data from web form PHP application to Java web application

I have two WEB applications based on two different servers. How I can pass data from the PHP web form, which consists of 5-10 fields, to Java application(Struts2, Spring2) in the most elegant and safe way?
I think cURL should be enough, you can make HTTP(S) requests from one to the othe server.
let the PHP return a JSON object, best would be RESTfull.
let the java code make a REST call
One answer: API. That's what APIs are intended for - communication between applications.
Create endpoint in the JAVA app that acceps the data and does something with it.
In PHP after recieving the data from form make a call to the JAVA app endpoint and send the data there.
For security you may want to use some data encription using oauth (that is if you data requires that kind of security).
You have created an API which will return JSON array.
Call that API from java application and get JSON, decode JSON and use that.

WSDL2JAVA for simple http get on php page?

I have to request a PHP page with 3 Parameters (e.g. www.test.com/index.php?name=mrTest&no=1&id=10001). I'm using WSDL2JAVA for other Services and am now wondering if it is possible to generate a similar Service for this case. This PHP page Returns an XML. I'm just consumer/client of the Service.
I could also make a simple request and then use JAXB to parse the XML but i would like to implement all my Services the same way.
So, does anybody has already implement a php page consumer using WSDL2JAVA?
Best regards
So from my understanding this is a simple PHP page not a SOAP service. Remember XML is just the protocol used in a SOAP service however a SOAP service consists out of a WSDL that is published describing operations and how to call those operations.
A simple PHP page even if it returns XML data is NOT a SOAP service and thus does NOT have a WSDL. You wont be able to use WSDL2JAVA for that.
This PHP page seems more like a REST type service that returns XML instead of JSON. To be honest it really sounds like a REST service.
Try using the latest SOAPUI to connect to the page and see if you can use the REST project type with this page. If it is a REST service it might have a WADL file. YOu can use the WADL2JAVA cxf utility to generate classes to you. HOwever this is a BIG might as most REST services dont use WADL's yet. See this link on CXF

Passing json data between client and server

I need to implement web services, send json to a server and read the response. All of the requests are send to the service https://api.polldaddy.com/
This will take place within a web application. This is the api I have to implement :
http://support.polldaddy.com/api/
It seems straightforward, just send some json to the server and consume the json response that is sent back. There seems to be so many options of doing this task that its a little daunting where to start ?
So, where is the best place to start in learning how to implement this service, ie : send json to a server and consume the response.
First of all, you are using the wrong terminology. "Implement web services" implies you will create a service, it sound like you just want to call a web service. You could say "leverage web services" if you need it to be business speak complaint.
The harder way. If you can't add on any additional libraries use java.net.HttpURLConnection.
The easier way. If you can add libraries use the Jersey client API. http://jersey.java.net/nonav/documentation/latest/user-guide.html#client-api
Java EE 7 will include an official client API, EE 6 only included the REST server-side API.
But you should prefer the XML content over the JSON content yourself. JSON is great because it is easy for JavaScript to parse. Java has more ways to parse XML than it does JSON. If you really want to use JSON you could look at something like http://jettison.codehaus.org/
If there is no JAVA API already written I would go for a JAX-RS approach with a client framework like jersey client. Look at http://jersey.java.net/nonav/documentation/latest/client-api.html.
Since you're creating a web app that needs to do HTTP request handling... Start with either Tomcat or Jetty, and Apache HTTP Client, and use a JSON library such as available from json.org.
If you are familiar with maven, you could get all this wrapped up and building within 10 minutes. Otherwise, you'll have to build the webapp and handle dependencies yourself.
If you are on Java EE 7 and want to use the included JAX-RS 2.0 API then have a look at https://github.com/tobiasdenzler/jee7-rest-crud. Its a simple CRUD project using JSON.

Best way for handle Read HTTPRequst post data on Restful api

What is the best way of save data using Restful web service without using Ajax? As a example I need to add a new Customer to the database using submit button.
What is the best way of transfer data format (text,json,xml) ?
How to read POST or GET data from HttpRequest object?
If you can please give me a example in java .
Thank you
I think you need to separate the concepts a bit. A "Restful Web Service" is a web service designed using REST principals, whereas AJAX is a set of technologies used often on the client side for asynchronous requests to multiple resources (without fully reloading the page). The web service really shouldn't care how the HTTP request is generated, just the contents of the HTTP request.
Now if you're concerned about writing a rest service in Java, I would highly recommend looking into JAX-RS and the reference implementation Jersey. There are lots of examples of how to get up and running. You can use MessageBodyReader implementations are to convert data from the HTTP request entity into Java objects.
Obviously this is not the only way to get started with writing a Restful web service in Java, but is one way.
It's very definitely worth your time to carefully study Richardson and Ruby's RESTful Web Services to learn the REST architectural style. In addition to #ach_l's recommendation to use Jersey, take a look at the Restlet Java framework, which is completely wonderful.

Categories