Wrapped service - java

I've been reaching wrapped services examples for java and spring and I cannot find anything useful. There are plenty of tutorials for java and spring web services but nothing on wrapped ones
Basically if given 2 wsdls, how can I create a wrapped service? I am hoping there are working examples or even a nice start to finish tutorial to help me out.

i think what you're looking for is like a 'federated service' or a 'business delegate' pattern. that is, one WSDL showing all the methods for the other two WSDL's combined.
one way of doing this is using Spring Integration. with Spring Integration you could expose your 'consolidated' WSDL and then route the various methods to the specific correct actual endpoints. have a look at this in the Spring Integration documents about exposing a webservice and then subsequently routing and invoking others.

Related

Best practice to have a RestController and a Controller in Spring Application

I am not asking if it is possible, I know it is but I would like to know what's the best way to offer a rest service while having a front end in my application.
I'm developing a Spring Boot application, I currently have a controller that calls jsp pages, and a separate RestController. I want to be able to consume it with an Android application.
So is it correct to have both a Controller and a separate Restcontroller in my application? For example the Rest controller methods will be called from /api/*.
Edit :
I know the difference between the two, but since I want to be able to return a view ( and I shouldn't do that with a RestController) and I want to have a rest service I am wondering if I can have both of them (separately of course).
Thank you so much in advance.
I'd say that it's possible, but considered a bad practice (except for corner cases like a controller for Swagger in a REST application) in a typical, layered, spring app (will get back to that)
you may want to create a multi-module project, that may look like that:
parent project
-- core
-- web api (jsp based)
-- rest api (for android)
both web api and rest api depend on the core.
web api and rest api are separate deployment units. you can deploy them on the same server or run as separate applications (for example using spring boot). Depends on your usecase.
with that you can have your business logic in one place (core).
you may also want to read about ports and adapters architecture, which may give you an idea how to solve this in a more organized way than just having Controllers and RestControllers sitting side by side

Sending an (asynchronous) message from one Spring Boot application to another using Spring Integration using annotations

I have been messing around with Spring Integration, and I'd like to use its capabilities in a project. I have two different applications, one is a business-sided one, which when users do certain actions, should send messages to another application. The other application should receive these messages (using some kind of queue (rabbitmq or another) to handle big loads) and store them, so it can use it to create realtime statistics of a number of applications running.
These messages will just contain information of the actions of the users, for example "bought N of product X" or "Used searchbar for Y".
This scenario is of course pretty simple, but I don't want to use any kind of XML configuration in my Spring applications. The examples I have seen so far all rely on XML, but I want to use some kind of annotations instead.
Spring Integration java dsl is already released which would serve your purpose.
A gentle introduction can be found at
https://dzone.com/articles/spring-integration-java-dsl
You can also checkout Camel (has a fluent dsl for EIP) which also gels well with spring

Apache CXF/JAX-RS, Felix and Jetty

I have an existing group of bundles that together create a web application (including an instance of Jetty). A new requirement is to extend this application to provide a RESTful api (using JAX-RS).
I was able to develop the majority of the RESTful API in isolation, away from the rest of the applciation. Without realising, the Apache CXF bundle I was using contained its own Jetty instance. So, in isolation, this worked fine. When I merged the two halves of the application, the two instances' addresses conflicted.
This much I know for sure.
What I do not know is how to re-configure the RESTful API part of the application (JAX-RS) to use the existing Jetty instance. This page suggests the use of CXFServlet, but I cannot find much information on this.
Could anybody shed some light or point me in the right direction?
Edit: I should also mention that, currently, my endpoints use the JAX-RS annotations in a Java interface to map between an endpoint and mapped class. I would prefer to keep this configuration method as opposed to XML or any other method.
One option, which does not use Apache CXF, is to use the web components of Amdatu, which also support JAX-RS annotations. You can find more documentation about them at http://amdatu.org/components/web.html which explains how to setup your project with a separate Jetty instance. You might also want to watch the video at http://amdatu.org/howto/createwebapp.html which deals with the same subject.
If you really want to use Apache CXF, there are two versions: an "all in one" that is pretty much self-contained (and therefore also includes Jetty) and a "modular" one that consists of many separate bundles. The latter in theory gives you the option to integrate with your own copy of Jetty, but you need to figure out what exact set of bundles you need based on their documentation at http://cxf.apache.org/docs/index.html

Creating java RESTful application

I want to create new RESTful application. I am bit confused about framework I can do it with spring+jersey , but can I do same application using jersey alone?
What is major difference between SpringREST and jersey?
Which is more convenient? why?
I've used both frameworks a bit. Spring is a large framework/API that covers many areas, one of which is rest services. Jersey on the other hand just covers rest. It's the reference implementation for the JAX-RS API (JSR 311 & JSR 339).
This is basically the "standard" way to do rest in Java. There are also other implementations like RestEasy. In theory your code will only need to reference the common JAX-RS interfaces meaning you ought to be able to swap to a different implementation later if required. This obviously only works if you don't become reliant on bespoke functionality that isn't part of the JAX-RS standard.
If you were to use Jersey, you might still decide you want spring. It can be useful just for its dependency injection alone. In this case you might have a JAX-RS class handling rest requests which then calls a spring service which has been injected. This is actually how I'm writing rest API's.
Whether you should use spring to write the rest services or JAX-RS is subjective and really up to you. Personally I went with the standard JAX-RS API because I found it was more focused on rest. The spring rest approach is basically an extension of spring-mvc which was originally intended for JSP's. I found things like error handling were easier using JAX-RS than spring-mvc. That said someone else may beg to differ. The other benefit is by following the standard in theory you have more flexibility in future if you want to switch to a different provider.
The main difference is that Jersey is standards-based, and Spring MVC is not, if that matters to you. Both are very good.
The main advantage I found in Jersey (I used 1.x) was that it could automatically use Jackson JSON Views automatically, and Spring MVC could not. Also, error handling in Spring MVC is kind of irritating, as error pages default to standard HTML.
There is another project you have not listed, and that is Spring Data + Spring HATEOAS, which is newer, but seems pretty good.

Recommended Java packages/jars to access and process RESTful web services

I want to access an external RESTFul Web service via Java, and use an open source package that processes the returned XML or Json result and creates object(s) from this data.
I know that there are many solutions out there for this, and I'd like to get your feedback on which one I should use.
For accessing the web services, I know that I can use packages such as apache HttpClient etc. but I'm sure that there are packages that wrap this and also take care of processing the returned data (i.e. creating java objects from the result).
Thanks,
Nina
Spring is great, but this is one case where there are higher-level libraries out there that make it even easier. See for example the clients that come along with JAX-RS implementations like the Jersey client and the CXF client. Some implementations can even provide clients through dynamic proxying if you have a service interface and resource classes available. This way, you hardly have to write any code at all.
Spring Rest Template is your friend.
Spring MVC has something called "RestTemplate" which can be used exactly for this.
http://aruld.info/resttemplate-the-spring-way-of-accessing-restful-services/
http://blog.springsource.com/2009/03/27/rest-in-spring-3-resttemplate/

Categories

Resources