tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris.Christo" <chris.chri...@mail.com>
Subject Re: Set custom ValidationEventHandler for jaxb and jax-rs
Date Mon, 24 Jun 2013 12:53:57 GMT
Hey Romain,

Yeah that worked a treat! using the new json config :D (see below)

Quick question though, I realised that having a class that you want to include in your 'services'
configuration, say for example here, the class 'SystemEventHandler', must be in a jar in lib/.
When having it in my project (and thus to end up as an ejb-jar in apps/), OpenEJB throws an
error saying class not found (org.apache.xbean.recipe.ConstructionException: Type class could
not be found: example.SystemEventHandler).

I'm guessing this is because; 

1) class loading of lib/ happens,
2) openejb.json (or xml etc.) is read
3) class loading of the apps/ejb.jar

So basically you can't have any classes (that you want to include in the "services" part of
config) in an ejb-jar in apps?


"services": {
	"SystemEventHandler": {
		"class-name": "example.SystemEventHandler"
	},
	"SystemJsonProvider": {
		"class-name": "org.apache.cxf.jaxrs.provider.json.JSONProvider",
		"properties": {
			"dropRootElement": true,
			"supportUnwrapped": true,
			"eventHandler": "$SystemEventHandler"
		}
	}
}

Chris,

@ChriChristo7 
{ https://twitter.com/ChrisChristo7 }
{ http://ChrisChristo7.tumblr.com }

LinkedIn { https://linkedin.com/in/ChrisChristo }
Angel { https://angel.co/chris-christo }
GitHub { https://github.com/ChrisChristo }

On 18 Jun 2013, at 20:58, Romain Manni-Bucau <rmannibucau@gmail.com> wrote:

> ok forgot i already added it.
> 
> <Service id="foo" class-name="...">
> attr = $other
> </Service>
> <Service id="other" class-name="..." />
> 
> Note: cycles are not handled
> 
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
> *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> *Github: https://github.com/rmannibucau*
> 
> 
> 
> 2013/6/18 Chris.Christo <chris.christo@mail.com>
> 
>> Yeah I was, but I just realised that I should be extending the
>> JSONProvider (as I was hitting my rest end point with JSON). Anyway its
>> working now with the code below. Thanks a bunch for your help. It is a bit
>> unpleasant that I have some configurations as properties (dropRootElement
>> etc.) and others by extending the class. This approach makes my code
>> dependent on one implementation (cxf-rs) which is not good imo. Is there
>> any chance we can configure object properties soon?
>> 
>> 
>> 
>> @javax.ws.rs.Produces({"application/json"})
>> @javax.ws.rs.Consumes({"application/json"})
>> @javax.ws.rs.ext.Provider
>> public class CustomJSONProvider extends
>> org.apache.cxf.jaxrs.provider.json.JSONProvider {
>> 
>>        public CustomJSONProvider() {
>>                setValidationHandler(new CustomValdationHandler());
>>        }
>> 
>> }
>> 
>> and the properties I have are:
>> 
>> json = new://Service?class-name=example.CustomJSONProvider
>> json.dropRootElement = true
>> json.supportUnwrapped = true
>> 
>> cxf.jaxrs.providers = json
>> 
>> 
>> 
>> 
>> 
>> Chris,
>> 
>> @ChriChristo7
>> { twitter.com/ChrisChristo7 }
>> { ChrisChristo7.tumblr.com }
>> 
>> LinkedIn { linkedin.com/in/ChrisChristo }
>> Angel { angel.co/chris-christo }
>> GitHub { github.com/ChrisChristo }
>> 
>> On 18 Jun 2013, at 17:57, Romain Manni-Bucau <rmannibucau@gmail.com>
>> wrote:
>> 
>>> Did you add @condule @produce on your impl?
>>> Le 18 juin 2013 18:51, "Chris.Christo" <chris.christo@mail.com> a écrit
>> :
>>> 
>>>> Ok so extended the class and added this new class to the providers list
>>>> (cxf.jaxrs.providers) however, when unmarshalling, it still uses the
>>>> original JAXBElementProvider and not my CustomJAXBElementProvider class
>> to
>>>> do the work. Its like both are now in memory as providers but the
>> original
>>>> JAXBElementProvider gets chosen to do the work.
>>>> 
>>>> Chris,
>>>> 
>>>> @ChriChristo7
>>>> { twitter.com/ChrisChristo7 }
>>>> { ChrisChristo7.tumblr.com }
>>>> 
>>>> LinkedIn { linkedin.com/in/ChrisChristo }
>>>> Angel { angel.co/chris-christo }
>>>> GitHub { github.com/ChrisChristo }
>>>> 
>>>> On 18 Jun 2013, at 16:30, "Chris.Christo" <chris.christo@mail.com>
>> wrote:
>>>> 
>>>>> yes, it just clicked what you meant (just before your mail arrive :D
),
>>>> will give it a shot.
>>>>> 
>>>>> Chris,
>>>>> 
>>>>> @ChriChristo7
>>>>> { twitter.com/ChrisChristo7 }
>>>>> { ChrisChristo7.tumblr.com }
>>>>> 
>>>>> LinkedIn { linkedin.com/in/ChrisChristo }
>>>>> Angel { angel.co/chris-christo }
>>>>> GitHub { github.com/ChrisChristo }
>>>>> 
>>>>> On 18 Jun 2013, at 16:25, Romain Manni-Bucau <rmannibucau@gmail.com>
>>>> wrote:
>>>>> 
>>>>>> Just inherit from cxf class then init it as you want.
>>>>>> 
>>>>>> Then configure in cxf.jaxrs.providers your own class
>>>>>> 
>>>>>> *Romain Manni-Bucau*
>>>>>> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
>>>>>> *Blog: **http://rmannibucau.wordpress.com/*<
>>>> http://rmannibucau.wordpress.com/>
>>>>>> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
>>>>>> *Github: https://github.com/rmannibucau*
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 2013/6/18 Chris.Christo <chris.christo@mail.com>
>>>>>> 
>>>>>>> Ok thanks for the help, just a little unsure what you mean? Can
you
>>>>>>> elaborate please? or show me a couple of lines of code :D
>>>>>>> 
>>>>>>> Chris,
>>>>>>> 
>>>>>>> @ChriChristo7
>>>>>>> { twitter.com/ChrisChristo7 }
>>>>>>> { ChrisChristo7.tumblr.com }
>>>>>>> 
>>>>>>> LinkedIn { linkedin.com/in/ChrisChristo }
>>>>>>> Angel { angel.co/chris-christo }
>>>>>>> GitHub { github.com/ChrisChristo }
>>>>>>> 
>>>>>>> On 18 Jun 2013, at 16:12, Romain Manni-Bucau <rmannibucau@gmail.com>
>>>>>>> wrote:
>>>>>>> 
>>>>>>>> Hmm, i missed the fact the attribute was an object. I think
it
>> doesn't
>>>>>>> work
>>>>>>>> ATM. The faster and easier will be to wrap it in a custom
bean then
>>>>>>> simply
>>>>>>>> configure your provider to be used (+ your configuration
doesn't
>>>> becomes
>>>>>>> as
>>>>>>>> complicated as your code this way).
>>>>>>>> 
>>>>>>>> *Romain Manni-Bucau*
>>>>>>>> *Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
>>>>>>>> *Blog: **http://rmannibucau.wordpress.com/*<
>>>>>>> http://rmannibucau.wordpress.com/>
>>>>>>>> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
>>>>>>>> *Github: https://github.com/rmannibucau*
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 2013/6/18 Chris.Christo <chris.christo@mail.com>
>>>>>>>> 
>>>>>>>>> Yeah I'm trying to do that via system.properties (same
thing I
>>>> guess).
>>>>>>>>> 
>>>>>>>>> But a bit unsure how you set an object as a property?
So I tried to
>>>>>>> define
>>>>>>>>> my CustomValidationHandler class as a service as well
and then just
>>>> set
>>>>>>> the
>>>>>>>>> eventHandler property of the JAXBElementProvider to the
the
>> handler,
>>>>>>>>> something like:
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>> 
>>>> 
>> customValidationHandler=new://Service?class-name=example.CustomValdationHandler
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>> 
>>>> 
>> jaxb_element_provider=new://Service?class-name=org.apache.cxf.jaxrs.provider.JAXBElementProvider
>>>>>>>>> jaxb_element_provider.eventHandler=customValidationHandler
>>>>>>>>> 
>>>>>>>>> cxf.jaxrs.providers = jaxb_element_provider
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Chris,
>>>>>>>>> 
>>>>>>>>> @ChriChristo7
>>>>>>>>> { twitter.com/ChrisChristo7 }
>>>>>>>>> { ChrisChristo7.tumblr.com }
>>>>>>>>> 
>>>>>>>>> LinkedIn { linkedin.com/in/ChrisChristo }
>>>>>>>>> Angel { angel.co/chris-christo }
>>>>>>>>> GitHub { github.com/ChrisChristo }
>>>>>>>>> 
>>>>>>>>> On 18 Jun 2013, at 15:48, Romain Manni-Bucau <
>> rmannibucau@gmail.com>
>>>>>>>>> wrote:
>>>>>>>>> 
>>>>>>>>>> Hi,
>>>>>>>>>> 
>>>>>>>>>> you can define the JAXBElementProvider in resources.xml
then
>>>> configure
>>>>>>>>> its
>>>>>>>>>> attribute through the properties of the <Service/>
block. Then
>>>> simply
>>>>>>>>>> reference it through the id in cxf.jaxrs.providers
list.
>>>>>>>>>> 
>>>>>>>>>> Romain Manni-Bucau
>>>>>>>>>> Twitter: @rmannibucau
>>>>>>>>>> Blog: http://rmannibucau.wordpress.com/
>>>>>>>>>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>>>>>>>>>> Github: https://github.com/rmannibucau
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 2013/6/18 Chris.Christo <chris.christo@mail.com>
>>>>>>>>>>> 
>>>>>>>>>>> Hi,
>>>>>>>>>>> 
>>>>>>>>>>> Trying to configure tomee to register my custom
>>>> ValidationEventHandler
>>>>>>>>>> for the unmarshaller of jaxb when my rest points
are hit, but not
>>>> sure
>>>>>>>>>> where to set this.
>>>>>>>>>>> 
>>>>>>>>>>> I found something here,
>>>>>>>>>> http://osdir.com/ml/users-cxf-apache/2011-03/msg00525.html,
in
>> that
>>>>>>> I'm
>>>>>>>>>> supposed to set
>>>>>>>>>> 
>> org.apache.cxf.jaxrs.provider.JAXBElementProvider.validationHandler
>>>> to
>>>>>>> my
>>>>>>>>>> custom class.
>>>>>>>>>>> 
>>>>>>>>>>> I did also try adding the class name to cxf.jaxrs.providers
>>>> (something
>>>>>>>>>> like cxf.jaxrs.providers = example.CustomValidationHandler)
but
>>>> didn't
>>>>>>>>> work.
>>>>>>>>>>> 
>>>>>>>>>>> Any pointers?
>>>>>>>>>>> 
>>>>>>>>>>> 
>>>>>>>>>>> Chris,
>>>>>>>>>>> 
>>>>>>>>>>> @ChriChristo7
>>>>>>>>>>> { twitter.com/ChrisChristo7 }
>>>>>>>>>>> { ChrisChristo7.tumblr.com }
>>>>>>>>>>> 
>>>>>>>>>>> LinkedIn { linkedin.com/in/ChrisChristo }
>>>>>>>>>>> Angel { angel.co/chris-christo }
>>>>>>>>>>> GitHub { github.com/ChrisChristo }
>>>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>> 
>>>> 
>>>> 
>> 
>> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message