How to build configurable facade over set of RESTful services - java

It's time to ask question on StackOverflow because I did not find a good one in Google.
We have a legacy systems(2 in my case) that provide some functionality via RESTful web-services.
Now we are building a Java EE system that will consume RESTful services from that legacy systems.
Questiuon: how to build convenient facade API over mentioned RESTful web-services to use them easily in our Java EE app?
Are there some frameworks to easily consume a set of REST web-services and it can be XML-configured?

There is a number of options
The most "low level" - HTTP Client (http://hc.apache.org/httpclient-3.x/)
Something more abstract - RestEasy ClientRequest/ClientRespons (http://docs.jboss.org/resteasy/docs/1.2.GA/javadocs/org/jboss/resteasy/client/ClientRequest.html) there is a number of tutorials how to work with it
You might like it most due to XML config - Spring Framework RestTemplate support (see, for instance http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/client/RestTemplate.html), there is a number of tutorials in the web too.

Related

Consuming RESTful API in Java, generating artifacts.

I am tasked with creating a layer in Java/Spring that consumes web services from a couple different providers. These services define specific request beans but the end points do not publish XSD information.
What would be the best way to generate the artifacts required to consume these services? It seems building our own request objects is not the best way of doing things.
REST services do not offer XSD as the WSDL of a traditional SOAP service. Some REST frameworks offer WADL, or the may user Swagger.io to describe the service, or expose documentation like Spring boots actuator /docs.
If there is no such documentation, and you can't get the source code for the system you are integrating with, I recommend that you build your own set of Java POJOs so you can interface with the service in a typed manner.
I have done that for multiple systems that expose (online) documented REST services, but do not provide a set of DTO that you can use when consuming them.

RESTful webservices with Struts 2

We are evaluating one design for educational activity. We would like to create complete backend (which handles business logic) in form of RESTful web services.
These services can be used by various apps. Is it good idea to call these web services from Struts 2 framework? I read couple of docs, and people discourage it.
We would love to go with Struts 2 as team is quite strong on it. But if its bad approach, we may consider for other options.
If you want to leverage development on presentation layer between client-side and server-side (this is where Struts2) then you can utilize web services using a web services client API. At this point these web services can be used as data resources.
If you want to stay only on client-side then you don't need any server-side framework for the frontend development.
Note that The introduction to Struts2 and RESTful applications you have posted in comment introduces an alternative way instead of web services for creating backend in a form of RESTful API using Struts2 framework.
Using Struts2 for the REST instead of web services could be a solution for RAD (Rapid Application Development). Because web services are very complicated technology that used in upper high level architectures and using some alternative resource APIs might be cost effective.

Is there a way to build a java rest service so that wsdl can be autogenerated from it?

One problem that continuously comes up at my workplace is creating clients for Java rest services that we create. We have 4 different programming languages to support and it is costly to create clients for each programming language. Often this means our web services aren't available in a cross platform manner since we rarely have time to build all of the clients.
SOAP provides this type of discovery and machine created client mechanism based off of tools that consume WSDL but our architectural direction is to write REST based services in Java instead of SOAP services.
We would also prefer not to write WSDL documents by hand that expose these REST web services. In a .NET environment, WCF and ASMX web services automatically create the WSDL for consumption in other applications, but this is not a direction my team is allowed to pursue.
Can this be done in some fashion for a Java based REST service?
How can this be done without having to invest a lot of manual labor?
We're currently using spring controllers but might be able to argue for a different Java framework if it provides better velocity.
Jersey (JAX-RS implementation) has support for WADL. You can use Jersey to automatically generate a WADL and there is also some support for generating Java clients from the WADL.
That's for Java, and I don't know if it's more than basic support, but I doubt you can pull it off for 4 different programming languages.
You might want to read these first though (tl;dr: REST is more than a CRUD style Web API and is different than SOAP):
Do we need WADL?
Why the slow WADL uptake?
You may want to check third party tools like swagger (http://swagger.io/) and mashery. I know swagger has support for client generation.

Need help: Building Java Web-Service(s) and .NET/WPF Client consuming it

I am required to build couple of Java WebServices on JBoss 5.x. One of the services will be consumed by a WPF Application. I am quite new to the world of WebServices and researching more on that. Needed to know if someone has been through the same and can share the pointers on how to achieve it.
I am reading one of the articles on JBoss Communities: http://docs.jboss.org/jbossas/jboss4guide/r2/html/ch12.html
I am not sure if web services explained here are interoperable with my WPF Client. I am planning to use WCF to consume these web services.
Can anyone share some pointers about it?
Thanks!
WCF can consume SOAP web services as well as RESTful ones. I recommend looking into JAX-RS for REST, and/or JAX-WS for SOAP. Both JAX-RS and JAX-WS are APIs that let you create web services by annotating Java code, rather than having to work with XML configuration files.
These days, SOAP is often considered over-engineered, and REST is considered leaner. There are a ton of questions comparing the two on SO.

what is spring web services used for

I am building websites in spring MVC. as there are many spring projects , i wanted know what will be scenario when spring web Services is used for.
i mean what can be done with that. Do i really need it for ecommerce site
Your question is really about "web services". For a layman's explanation of what it is all about, read this Wikipedia article.
There are a number of related acronyms that get bandied about:
SOAP (Simple Object Access Protocol) is a protocol for sending requests to a service and getting back a response. The messages are encoded in XML, and send over HTTP.
WSDL (Web Services Description Language) is a service description language for SOAP-based services. It does things like specify what is in the messages, and how the messages are bound to services.
SOA (Service Oriented Architecture) is essentially a system architecture in which the system consists of lots of SOAP services (and others) described using WSDL.
(The proponents of SOA talk about "design principles", but in my cynical view is that this is just a repackaging / recasting of stuff that people have been doing for 20+ years under other names.)
Do i really need it for ecommerce site
Ask your customers. Ask the people whose systems your system will be interfacing with. Ask the vendors whose components you intend to embed in your system.
If you have to use WS then what extra facility it will give
If you have to use WS (e.g. because your site needs to talk to other services that require WS), then you have to. That is sufficient justification.
If you don't have to use WS, then you need to balance the advantages of using WSDL + SOAP against the advantages of some other approach to implementing your web APIs. An SOA expert will probably say use SOA; an AJAX expert will probably say otherwise. And there are other remote procedure call technologies around ... if you really need that kind of thing.
WSDL + SOAP certainly does have some advantages; e.g.
machine readable specifications for your web APIs,
possibility of validation of messages against XML schemas,
an ecosystem of existing WSDL services,
adoption in some sectors of IT.
But it has downsides also; e.g.
WSDL + SOAP have a significant learning curve compared to some alternatives,
XML is a heavy-weight encoding scheme - relatively expensive to parse,
SOAP only pretends to be type-safe (compared with say CORBA / IIOP),
SOAP is not usually used* in browser-based clients; JSON or plain XML are commonly used for AJAX apps,
many people think SOA is over-hyped and steer clear.
* However, it can be used; read these IBM DeveloperWorks Articles.
My advice (FWIW) if your system is primarily a website, doesn't need to talk to SOAP services, and doesn't need to provide a SOAP service API for others .... don't bother. You can always add SOAP service APIs later if you need to.
Spring Web Services is a product of the Spring community focused on creating document-driven Web services. Spring Web Services aims to facilitate contract-first SOAP service development, allowing for the creation of flexible web services using one of the many ways to manipulate XML payloads.
More here : Spring Web Services
How to use Spring Web Service : Spring WS
If you don't know what Web Services are, you probably don't need them. Web Services are a way (speaking generally here) for one web application to talk to another. You can formulate a request as an xml document and send that xml to a web service, which is listening on a specific URL and port. The Web Service can then perform some action based on this document, and respond back with an XML document. It's commonly used as a means for integration between applications.
If you're building a simple e-commerce site, which does not integrate with other live web products, then likely you don't need Web Services. Spring Web Services is simply an API/library to make reading/writing web services easy.

Categories