Calling a restful web service (non SOAP) with java - java

I'm trying to develop, using Java, a simple application that call a web-service restful which returns an xml and then I need to provide the result to a jsp page.
I was thinking to use CXF but what is not clear is the fact that the restful service can have different urls with parameters like:
http://ws-host.com/rest/products?BRAND=020&LOCALE=en_gb?product_code=600200
http://ws-host.com/rest/products?BRAND=020&LOCALE=en_gb&VEHICLE_BRAND=test
or
http://ws-host.com/rest/dealers?BRAND=020&LOCALCE=en_gb&SEARCH_TERM=Test
How can I do that? I'm a bit confused.
Thanks

CXF supports JSR-339 spec so you can use this API to create your mappings with different parameters.
You can use #QueryParam annotation, here is an example

Related

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

How to call a webservice with GET?

I have experiences in creating clients to a SOAP Webservice using JAX-WS. Therefore I'd mainly create a #WebService class with #WebMethod methods that take #WebParam params and return a #WebResult.
Mostly I start using CXFto auto-generate the Java classes from theWSDL`.
But what if the webservice is a GET service instead of a SOAP, like http://www.cleartrip.com/places/hotels/info/41748.
I can use a XSD accordingly to auto-generate my Java classes to JAXB as well.
But how do I then call that GET-Service? Which framework will assist me here? Is it also possible with JAX-WS?
You are confused because this is a restfull service and not a SOAP web service, java has an API for accessing restful services easily, see 'https://jersey.java.net/documentation/latest/getting-started.html' for more info.
What you call a GET service looks like a RESTful service. Take a look at JAX-RS 2.0 and the new client API.

Is it possible to consume an EJB 3 Web Service form a Java client without first generating client stubs/proxies?

In most tutorials that I have seen so far people are using wsconsume or something like that to create classes that clients can use to access an EJB 3 Web Service.
Is this the only possible option? As my EJB's interface is annotated with WebMethod, WebParam, etc. isn't it possible to create a dynamic proxy or use runtime bytecode enhancement to create the proxies, etc. on the fly? E.g.:
MyWebService webService = WebServiceEnhance.getWebService(MyWebService.class);
webService.webMethod("foo");
A link to good reference material is also highly appreciated.
One way is to deal with pure XML request/response. You can trap sample request/response for the web service you want to consume using either SoapUI or Fiddler and then use these samples as templates within your client.

Convert servlet to a webservice

I have a servlet to a webservice in java,
I have a servlet that process user information ,(registeration) and return a result as a string , how do I use that servlet as webservice to be called and do the same thing?
Look at JAX-WS that is a Java specification for webservices, making a POJO service available as a Webservice Soap Endpoint.
http://jax-ws.java.net/
You may need to move your code from your servlet to a POJO class.
There are several methods depending on your need.
I found the WebService Axix User guide quite useful here -> http://ws.apache.org/axis/java/user-guide.html
It contains description on how to use the Java2WSDL tool which ultimately allows you to publish your final webservice. http://ws.apache.org/axis/java/user-guide.html#Java2WSDLBuildingWSDLFromJava

Creating a Java based web service

I have a very basic Java based web service requirement. Requirement is very simple, pass some String parameters, save them to database and generate a response ("success", "failed"). There is also a case where I need to return simple XML representation (SOAP message) of a simple Object:
<person>
<name>the name</name>
<address>the name</address>
......
</person>
Our current environment is Windows, Apache Tomcat 5, SQL Server.
I'm new to web services so I'm trying to figure out what technologies I could use to make this work. For example:
Do I really need Apache Axis 2 to implement this or would it be overkill?
I saw a tutorial online where all that was needed to create web service was Eclipse, Lomboz plugin for Eclipse and Apache Tomcat. Will I still need Apache Axis2 if I take this route?
Is it possible for Tomcat to process web service requests messages or do I need third party libraries?
I guess I'm looking for the easiest way to implement this. Thank you.
Do you actually need SOAP support? If you do, Axis is probably your best bet. Otherwise, I'd take a look at Jersey.
If it will be as simple as you have mentioned, why don't you look at RESTful Web Services? You can specify your resource calls through a GET, POST, DELETE or PUT HTTP methods.
There's a blog tutorial on how to achieve this. It also shows you how you can return JSON strings/XML (depending on what you want).
A web framework would make this much easier (and actually maintainable), but you could just write a raw servlet to handle requests. You'll want to use an XML object serialization method, though, or at the very least an xml parsing library.
I think you would need axis for this one. But I'll advice you to look at Apache CXF, if in future you will need more support with web service apps. CXF just like axis2 is an implimentation of jax-ws but with an advantage of supporting jax-rs (rest). This means you can expose both REST and SOAP web service interfaces.

Categories