The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » Metro and JAXB

Thread: performance and validation

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Jul 17, 2008 11:17 PM by: airwin
airwin

Posts: 9
performance and validation
Posted: Jul 3, 2008 8:53 PM
  Click to reply to this thread Reply

Hello,

I'm using Jax-ws 2.0 and trying to do schema validation of the incoming messages using the JAXB LogicalHandler, ValidationEventHandler and Unmarshaller. I have a few questions related to my design and performance issues.

1) The documentation mentions that a JAXBContext is expensive to create and designed to be thread safe, so as suggested I keep a Singleton version. However it also says that the Unmarshaller is not thread safe, yet I'd think it would be expensive to create due to the schemas that are required to be passed to it (I'm assuming it parses the schemas in prep for validation, please let me know if I'm wrong here). Is the normal design to create a new Unmarshaller for each call into the handler? Is this expensive?

2) In my LogicalHandler I make the call

unMarshaller.unmarshal(message.getPayload())

Which actually performs the unmarshalling and validation. Assuming the validation passes and the incoming call then proceeds to its final destination (endpoint) does the unmarshalling then happen again as the incoming data is passed to the endpoint? If that's the case, it would seem to me that I'd want just validation to happen in the Handler not unmarshalling as I wouldn't want unmarshalling to happen twice as I'd expect it's expensive. Any way to do that?

I apologize ahead of time if the answers to these questions are obvious and I've just missed them. Any insights are appreciated.

thanks!

airwin

Posts: 9
Re: performance and validation
Posted: Jul 17, 2008 10:55 PM   in response to: airwin
  Click to reply to this thread Reply

Over 300 views and no reply. Did I phrase the question badly? Leave out information? or does no one know?

jitu

Posts: 733
Re: performance and validation
Posted: Jul 17, 2008 10:58 PM   in response to: airwin
  Click to reply to this thread Reply

Why don't you use @SchemaValidation and SchemaValidationFeature ?

airwin

Posts: 9
Re: performance and validation
Posted: Jul 17, 2008 11:02 PM   in response to: jitu
  Click to reply to this thread Reply

I'm using JAX-WS 2.0, that's not available till a later version from my understanding.

jitu

Posts: 733
Re: performance and validation
Posted: Jul 17, 2008 11:04 PM   in response to: airwin
  Click to reply to this thread Reply

> Hello,
>
> I'm using Jax-ws 2.0 and trying to do schema
> validation of the incoming messages using the JAXB
> LogicalHandler, ValidationEventHandler and
> Unmarshaller. I have a few questions related to my
> design and performance issues.
>
> 1) The documentation mentions that a JAXBContext is
> expensive to create and designed to be thread safe,
> so as suggested I keep a Singleton version. However
> it also says that the Unmarshaller is not thread
> safe, yet I'd think it would be expensive to create
> due to the schemas that are required to be passed to
> it (I'm assuming it parses the schemas in prep for
> validation, please let me know if I'm wrong here).
> Is the normal design to create a new Unmarshaller
> for each call into the handler? Is this expensive?

See
https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html

>
> 2) In my LogicalHandler I make the call
>
>
> Marshaller.unmarshal(message.getPayload())
>
> Which actually performs the unmarshalling and
> validation. Assuming the validation passes and the

Marshaller.unmarshal() doesn't do complete schema validation.
To do the schema validation, you need to use JAXP API

> incoming call then proceeds to its final destination
> (endpoint) does the unmarshalling then happen again
> as the incoming data is passed to the endpoint? If
> that's the case, it would seem to me that I'd want
> just validation to happen in the Handler not
> unmarshalling as I wouldn't want unmarshalling to
> happen twice as I'd expect it's expensive. Any way
> to do that?
>
> I apologize ahead of time if the answers to these
> questions are obvious and I've just missed them. Any
> insights are appreciated.
>
> thanks!

airwin

Posts: 9
Re: performance and validation
Posted: Jul 17, 2008 11:17 PM   in response to: jitu
  Click to reply to this thread Reply

Thank you very much for that link! I had seen it before but must have not read the last few lines.

I use the unMarshaller.setSchema call to set the schemas for the unmarshaller (this uses JAXP underneath believe) and then the call to unmarshaller.unmarshal actually validates against those schemas using JAXP underneath again. I believe that's correct as it seems to be working for me.




 XML java.net RSS