How to call a webservice with GET? - java

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.

Related

exposing soap as rest service in java

I have a vendor web service which is in SOAP but I have to write a wrapper class and expose it as Rest. Is it possible??
it will be something like client will call Rest Service but internally rest service will call Soap service.
It's certainly possible, and quite common actually. Writing middleware/glue/wrapper code is done all the time.
The approach I would take is to generate the client code using your vendors web service WSDL - for example using Axis wsdl2java. This generated code can be put into it's own lib/jar. Then write your own REST code using whatever framework you want that leverages the lib you created.
Clients would call your REST service which would internally use the lib code to connect to your vendors web service.
1)
Protocol Bridging SOA Patternis used to transform between different protocols by using a bridging broker as intermediary. The broker holds the transformation logic. bridges are available in most ESBs and EAI middle-wares.
http://soapatterns.org/design_patterns/protocol_bridging
2) Write your own logic adopter read Soap request convert in your code and expose as rest .

Calling a restful web service (non SOAP) with 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

How to generate entities from REST service?

I work with REST service provided by RESTeasy. It's REST, so there is no WSDL, right? Does that mean that I have to write all entities on my own and do unmarshalling on my own?
If it would be rest service, I could just download WSDL and then generate client from it. How do i do it with REST, that is served as xml in Atom feed?
I don't really see any advantage in REST, if it has no way of generating client and doesn't provide any public specification of entities.
Thank you for your help.
Correct, with REST, there's no WSDL like there's with SOAP. That does not mean there's no unmarshalling directly to objects however. You can still use Jax-RS to bind the JSON/XML to an object, so you'll have the flexibility of mapping directly like you would in SOAP, you just need to build this class rather than letting SOAP build it for you.
Consider the example here

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

Categories