Rest version of "Soap Headers and Handlers" - java

I have a question about Rest web services.
In soap, we can use SOAP handlers to process the request before execution. For example we can parse Soap Headers in Soap Handlers before we are doing the real job.
Is there something like that in Rest services? Rest headers and Rest handlers?
Thanks

I guess you are working on client side. If you use jersey framework for rest request , you can use filter implementations. Otherwise If you use apache httpclient, you can use handler implementations.
Jersey docs: https://docs.oracle.com/cd/E19182-01/821-0540/6nlj9lcpf/index.html
apache docs:https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java

Related

How to POST XML using CXF client?

I'm experienced in creating soap webservice clients with cxf and jaxb.
However now I have a jaxb java mapping class, and have to send this as XML using HTTP POST/1.1 to a URL path.
Question: can this be done using cxf? Or if not, with spring? I especially need (de)-serialization of request and response, automatic logging, etc. Just as it is the case with cxf soap clients.
Yes, you can use CFX for JAXWS clients. You simple need the WSDL from the service provider. Then you use wsdl2java tool to turn the WSDL into Java stub code that you then compile along with your application.
There is a really good guide here.

Calling SOAP service inside REST service

I want to code for a REST service using Restlet framework that wraps a third party SOAP service with some XML data. So whenever I call the REST service with some XML data that REST service internally calls that third party SOAP service with the XML data that I provided and the response travels from that third party SOAP API to REST API and from REST API to me.
I have gone through this questions;
Calling a SOAP service using REST service
Calling SOAP in Jersey
But it didn't help me a lot, So it would be great if anyone provide me the links or tutorial where I can get any help. Thanks.
I think that the following links could help you if you want to implement by hand:
Restlet tutorial - http://restlet.com/technical-resources/restlet-framework/tutorials/2.3
Writing a SOAP Client - https://docs.oracle.com/cd/E19340-01/820-6767/aeqgc/index.html
The key challenge here is to convert request elements into the SOAP request since SOAP only uses HTTP as a transport protocol (both headers and payload) and the same for response (extract headers and payload to build the REST response). With Restlet, you need to leverage its REST API for this. See this link: http://restlet.com/technical-resources/restlet-framework/guide/2.3/core/http-headers-mapping.
I also saw these tools that seem to provide a proxy to adapt a SOAP service as REST service:
Exposing SOAP Services as REST Resources - http://www.membrane-soa.org/service-proxy-doc/4.0/rest2soap-gateway.htm, https://github.com/membrane/service-proxy
a RESTful API proxy to a SOAP-based service - http://apigee.com/docs/api-services/content/exposing-soap-service-api-proxy
Hope it helps you,
Thierry

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.

HTTPGET request of a soap webservice in java application

I had written a method in soap web service which returns the data from database. now i am facing the problem to write HTTP GET request in java application. Any help and suggestions will be appreciated
Thank you
Why you are not using jax-ws or apache axis2 or apache CXF for consuming your webbservice ? Direct http invoke will be little tricky and you will required to construct your soap message and some http headers to call soap based service directly http client. check the http client for soap service here How to call a SOAP webservice with a simple String (xml in string format)

JSON Web Service over simple HTTP GET/POST

Can you suggest a way or a framework or etc. for Java EE in order to make simple HTTP GET/POST calls to some web services like in SOAP web services but transport format must be JSON; not XML and there must not be any wrapper around(may be some vey lightweight header) like SOAP etc.
In short, my purpose is to serve web services using JSON and HTTP Get/Post in a maximum possible lightweight solution.
A JSON Web Service can be as simple as a servlet that parses the JSON text data from the request, and outputs text in JSON format in the response. JSON is a pretty simple format - you might not need a framework.
My favorite RESTful web services framework is Restlet.
If you want the ability to support a SOAP service as well as a RESTful one, check out Apache CXF.
Both of these frameworks support JSON, and either are suitable for both client side and server side applications.
Have a look at Dropwizard. Their documentation is very good and should have you writing REST services using JSON as transport very quickly.
Saw the date of the post just now oops...

Categories