You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by jllado <jl...@gmail.com> on 2016/03/14 15:06:09 UTC
Service object is not a singleton, use a custom invoker to validate
Hi,
When I add the JAXRSBeanValidationInInterceptor() to a RestServer
application, then I get the following warning:
Service object is not a singleton, use a custom invoker to validate
I guess is not a problem and I can ignore the warming but I prefer to ask to
prevent a surprice.
The code is the following:
@ApplicationPath("resources")
public class RestServer extends Application {
@Override
public Set getSingletons() {
JacksonJsonProvider p = new
JacksonJsonProvider(JsonParser.defaultJacksonObjectMapper());
Set set = new HashSet<>();
set.add(p);
set.add(new JAXRSBeanValidationInInterceptor());
return set;
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> set = new HashSet<>();
set.add(CityService.class);
set.add(BookingService.class);
set.add(AuthenticationService.class);
set.add(ApiListingResource.class);
return set;
}
}
I'm developing it with Tomee 7.0.0-M2 and CXF.
Thanks,
Juan Lladó
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
It was something related with the swagger jaxrs providers. Because when I
disabled auto provider scanning, the warming stopped.
Thanks,
Juan Lladó
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677934.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-04-21 14:58 GMT+02:00 jllado <jl...@gmail.com>:
> Great! When M4 is out, we'll update tomee :-D
>
> But about "TomEE 7 doesnt need system interceptors since it has bval 1.1",
> we are using hibernate-validation. So actually we don't have bval jar's
> into
> our tomme lib directory. Then, can I use BeanValidation in jaxrs with
> hibernate-validation (without the cxf interceptor)?
>
>
bval defines CDI interceptors in a standard fashion so configuring it to be
active (either validation.xml or @ValidateOnExecution) works whatever
provider you use.
> Thanks!
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4678187.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
Great! When M4 is out, we'll update tomee :-D
But about "TomEE 7 doesnt need system interceptors since it has bval 1.1",
we are using hibernate-validation. So actually we don't have bval jar's into
our tomme lib directory. Then, can I use BeanValidation in jaxrs with
hibernate-validation (without the cxf interceptor)?
Thanks!
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4678187.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
Side note: FYI tomee master got this interceptor by default this morning.
TomEE 7 doesnt need system interceptors since it has bval 1.1:
http://tomee-openejb.979440.n4.nabble.com/TomEE-7-bean-validation-td4677232.html
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>
2016-04-21 12:45 GMT+02:00 jllado <jl...@gmail.com>:
> Hi Romain,
>
> Again I'm having same issue :_(.
>
> So I've tried to use BeanValidation interceptor features instead of the
> org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor. But I do
> not get it to work. I've checked this thread:
>
> http://tomee-openejb.979440.n4.nabble.com/JAX-RS-Bean-Validation-td4667501.html
>
> Maybe the problem is we are using hibernate-validation :S (we are not using
> the bval.jar's). So for property
> org.apache.openejb.default.system.interceptors what value I have to use?
>
> We are still using Tomee 7.0.0-M2.
>
> Thanks!
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4678183.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
Hi Romain,
Again I'm having same issue :_(.
So I've tried to use BeanValidation interceptor features instead of the
org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor. But I do
not get it to work. I've checked this thread:
http://tomee-openejb.979440.n4.nabble.com/JAX-RS-Bean-Validation-td4667501.html
Maybe the problem is we are using hibernate-validation :S (we are not using
the bval.jar's). So for property
org.apache.openejb.default.system.interceptors what value I have to use?
We are still using Tomee 7.0.0-M2.
Thanks!
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4678183.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Right but if it is a @Provider or a @Path (resource) is decided at boot
time (you can check in CxfRsHttpListener#deployApplication).
If you don't manage to sort it out you would need to reproduce it on a
public/trusted source repository and share a sample.
Side note: maybe using BeanValidation interceptor features would make it:
1- smoother
2- more reliable since CXF is not able to go through the proxy layers of
CDI/EJB
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>
2016-03-14 17:21 GMT+01:00 jllado <jl...@gmail.com>:
> Well... the call to getSingletons happens at boot time. And as you said,
> it's
> called two times.
>
> But the warning happens when I do a call to the swagger end point.
>
> Thanks,
> Juan Lladó
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677904.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
Well... the call to getSingletons happens at boot time. And as you said, it's
called two times.
But the warning happens when I do a call to the swagger end point.
Thanks,
Juan Lladó
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677904.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-03-14 16:51 GMT+01:00 jllado <jl...@gmail.com>:
> I'm afraid it not work :_(. I'm still getting the warning when I call to
> the
> swagger end point.
>
> Here you are the code:
> @ApplicationPath("resources")
> public class RestServer extends Application {
>
> private Set singletons = new HashSet<>();
>
> public RestServer() {
> singletons.add(new
> JacksonJsonProvider(JsonParser.defaultJacksonObjectMapper()));
> singletons.add(new JAXRSBeanValidationInInterceptor());
> }
>
> @Override
> public Set getSingletons() {
> return singletons;
> }
>
> @Override
> public Set<Class<?>> getClasses() {
> Set<Class<?>> classes = new HashSet<>();
> classes.add(CityService.class);
> classes.add(BookingService.class);
> classes.add(AuthenticationService.class);
> classes.add(ApiListingResource.class);
> return classes;
> }
>
> }
>
> If I debug the call and I check the stack trace, I see the following calls:
> <http://tomee-openejb.979440.n4.nabble.com/file/n4677900/stack_trace.png>
>
> And I've tried to put a break point at getSingletons but never stoped.
>
>
This part is weird, looks like you don't use this Application then. Can you
check it is really read?
> Any idea?
>
> Thanks!!,
> Juan Lladó
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677900.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
I'm afraid it not work :_(. I'm still getting the warning when I call to the
swagger end point.
Here you are the code:
@ApplicationPath("resources")
public class RestServer extends Application {
private Set singletons = new HashSet<>();
public RestServer() {
singletons.add(new
JacksonJsonProvider(JsonParser.defaultJacksonObjectMapper()));
singletons.add(new JAXRSBeanValidationInInterceptor());
}
@Override
public Set getSingletons() {
return singletons;
}
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(CityService.class);
classes.add(BookingService.class);
classes.add(AuthenticationService.class);
classes.add(ApiListingResource.class);
return classes;
}
}
If I debug the call and I check the stack trace, I see the following calls:
<http://tomee-openejb.979440.n4.nabble.com/file/n4677900/stack_trace.png>
And I've tried to put a break point at getSingletons but never stoped.
Any idea?
Thanks!!,
Juan Lladó
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677900.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
getSingletons() { return singletons; } would do what i described (so you
init the singletons set in the constructor for instance).
Then I don't guarantee it works but the interceptor is setup as a provider.
You can also use openejb-jar.xml to setup it if it makes it smoother for
you.
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>
2016-03-14 15:35 GMT+01:00 jllado <jl...@gmail.com>:
> Mmmm, I'm not sure if I understand what you mean. How can I ensure that I'm
> always returning the same instance of that resource?
>
> If I debug the call in ValidationUtils, I see that the resource is
> OpenEJBPerRequestPojoResourceProvider which extends CdiResourceProvider.
> And
> the method isSingleton (of CdiResourceProvider) is always returning
> false...
>
> On the other hand, I've seen is something related with swagger. Because It
> only happens when I call to the swagger end point:
> http://localhost:7070/resources/swagger.json
>
> Thanks,
> Juan Lladó
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677897.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Service object is not a singleton, use a custom invoker to
validate
Posted by jllado <jl...@gmail.com>.
Mmmm, I'm not sure if I understand what you mean. How can I ensure that I'm
always returning the same instance of that resource?
If I debug the call in ValidationUtils, I see that the resource is
OpenEJBPerRequestPojoResourceProvider which extends CdiResourceProvider. And
the method isSingleton (of CdiResourceProvider) is always returning false...
On the other hand, I've seen is something related with swagger. Because It
only happens when I call to the swagger end point:
http://localhost:7070/resources/swagger.json
Thanks,
Juan Lladó
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891p4677897.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Service object is not a singleton, use a custom invoker to validate
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
think we got something close last week: if you return singletons - and
until M4 is out - you need to ensure you return the same instance for each
call (we are/were calling getSingletons() twice typically) otherwise the
@Provider would be considered as a resource instead if you don't do it.
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>
2016-03-14 15:06 GMT+01:00 jllado <jl...@gmail.com>:
> Hi,
>
> When I add the JAXRSBeanValidationInInterceptor() to a RestServer
> application, then I get the following warning:
> Service object is not a singleton, use a custom invoker to validate
>
> I guess is not a problem and I can ignore the warming but I prefer to ask
> to
> prevent a surprice.
>
> The code is the following:
> @ApplicationPath("resources")
> public class RestServer extends Application {
>
> @Override
> public Set getSingletons() {
> JacksonJsonProvider p = new
> JacksonJsonProvider(JsonParser.defaultJacksonObjectMapper());
> Set set = new HashSet<>();
> set.add(p);
> set.add(new JAXRSBeanValidationInInterceptor());
> return set;
> }
>
> @Override
> public Set<Class<?>> getClasses() {
> Set<Class<?>> set = new HashSet<>();
> set.add(CityService.class);
> set.add(BookingService.class);
> set.add(AuthenticationService.class);
> set.add(ApiListingResource.class);
> return set;
> }
>
> }
>
> I'm developing it with Tomee 7.0.0-M2 and CXF.
>
> Thanks,
> Juan Lladó
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/Service-object-is-not-a-singleton-use-a-custom-invoker-to-validate-tp4677891.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>