Best way for validate Bean in Spring+Jersey rest api - spring

I want to validate bean in rest api. In Spring mvc application we can use BindingResult for validate bean. But when We make rest application in spring , i am not able validate bean with the help BindingResult. I knew that we can validate bean in rest api using The JSR 303 . But my want to know what is best practice for validate a bean in spring rest application and this bean created in application.

Related

Spring boot Bean concept in Rest API

while creating rest api in spring boot , at database end we pass the object of entities to the methods , i dont want to pass the entity i want pass the bean
Please explain anyone how to create the bean and pass it to the all methods

How to lookup a JSF bean from a Spring bean

I am having a JSF application and I am using Spring for bean management. I registered all JSF beans as Spring beans and everything was running very smoothly. Now, I have got a requirement to use JSF's view scope, so it means I have to create a JSF managed bean (which I did using JSF annotations and all).
Now, I want to access this JSF bean in a Spring bean, certainly I cannot inject or get it using Spring's application context because Spring container doesn't know about this bean. So, currently in my Spring bean code I am getting this JSF bean using JSF's EL Resolver (examples mentioned here).
What I want to know is that is there any better way to do this?
My application is on Spring 4.0 and JSF 2.0 (MyFaces implementation), please let me know if you need any other information. I have not placed code because all my code is in remote server, moreover I think code is not required for this as there is no debugging over here.

Automatic invocation of Bean Validator for #Valid outside of Spring MVC

Simple scenario:-
In a Spring 4 app the following #Valid gets triggered when I make a REST call but not when I make an API call. The docs talks about it but does not state how to do it the way I want.
#RequestMapping(name="/something")
public Entity save(#Valid Entity e){ return repo.save(e);}
Without writing any custom AOP code to achieve this myself etc. how do I get bean validation #Valid triggered in Spring ? Looking for any Spring or Hibernate configuration that will turn this on for simple API calls.
Example: When I bundle my component as a maven I would like to get my beans validated irrespective of whether they run in a web context or outside , say Spring Batch or just JUnit Tests.
And when I bundle this jar in a web app I definitely don't want this executed twice.

How to inject a Spring bean in to Camel DefultProducer

I have written a camel component by extending DefaultComponent and also have the associative classes implemetation for endpoint, consumer, producer. My producer is extending the camel DefaultProducer and I want to inject a spring bean inside this class, so that whenever a route will be executed like
<route id="myRoute"><from uri="file://inbox"/><to uri="myComp://outbox"/>
I will be able to get the file from the file system and store it into database. For storing the file into the DB I have a service class instantiated by the spring container, but whenever I inject that bean into MyProducer we are getting null.
I recongnized the problem was not about Camel, it is related to the spring and I was injecting the bean in a wrong way. I resolved the problem by implementing the ApplicationContextAware interface into my helper class and storing the spring context as static variable and with the help of this helper class I am able to get spring bean inside MyProducer class. Thanks for spring ApplicationContextAware interface.

Integrating Spring request scope with JSF controllers

I am working on a project that uses a hybrid of JSF and Spring-MVC. User interface endpoints are accessed through a JSF front controller (javax.faces.webapp.FacesServlet), whereas REST service calls are accessed through a Spring-MVC front controller (org.springframework.web.servlet.DispatcherServlet). Deeper layers are Spring-managed (more-or-less). I don't like this arrangement, but I'm not in a position to change it.
The problem is that Spring's request-scoped beans aren't initialized when processing requests that come in through the JSF front controller. Is there an off-the-shelf solution for integrating Spring's WebApplicationContext with the JSF machinery so that the Spring request-scoped beans are initialized for each request regardless of whether that request comes through the JSF or Spring servlet?
There are two ways to integrate JSF with Spring, depending on which framework you want to give most control:
JSF front controller:
One way is to route all requests via the JSF faces servlet and let JSF route them to controllers, let JSF manage navigation state via faces-config. Then inject spring beans into JSF managed beans and access spring beans from the facelets view using value expressions via SpringBeanFacesELResolver.
See this post for a working example.
Spring front controller: put spring as a front controller with a dispatcher servlet and put in place spring webflow. This is the preferred and most powerful way to integrate the two frameworks, see this section of the documentation.
Spring webflow will manage the navigation state and the faces config file is mostly empty. There is no need for the JSF managed beans layer, request get directly handled by webflow.
Actions in JSF buttons trigger webflow transitions directly, and spring beans can also be used in value expressions to build the view. With this solution the integration with Spring is more seamless as webflow offers more possibilities then the JSF navigation mechanism: trigger bean methods between transitions, post redirect get pattern for avoiding double submissions.
Namelly the problem with the initialization of spring request scoped beans is solved with this direction, altough an alternative for this is to add a RequestContextListener OR a RequestContextFilter to web.xml (see section 3.4.4.1 of the docs).

Resources