users@jax-ws.java.net

RE: Re: Validating mandatory parameters of XML using JAXB 2.0

From: <praveen.mar_at_wipro.com>
Date: Thu, 19 Apr 2007 18:45:52 +0530

Thanks Chris.


Praveen P
* ESN 343-3315
* E-mail praveen.mar_at_wipro.com

-----Original Message-----
From: breadfan_at_gmx.de [mailto:breadfan_at_gmx.de]
Sent: Thursday, April 19, 2007 5:14 AM
To: users_at_jax-ws.dev.java.net
Subject: Re: Validating mandatory parameters of XML using JAXB 2.0

Hello,

we use the following code to check the parameters of a jaxws
call/response against a schema, it's working quite fine, but is
definitely slow.

        try
        {
            JAXBContext jaxbContext = JAXBContext.newInstance(packages);

            Marshaller marshaller = jaxbContext.createMarshaller();
            SchemaFactory schemaFactory = SchemaFactory
                .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

            URL schemaURL =
Thread.currentThread().getContextClassLoader().getResource(
                schemaLocation);

            if (schemaURL == null)
            {
                throw new RuntimeException("Schema for validation cannot
be found in classpath: "
                    + schemaLocation);
            }

            Schema schema = schemaFactory.newSchema(schemaURL);
            marshaller.setSchema(schema);

            String className =
ClassUtils.getShortName(object.getClass());
            String elementName = className.substring(0, 1).toLowerCase()
+ className.substring(1);

            JAXBElement jaxbElement = new JAXBElement(new
QName(schemaNamespace, elementName),
                Object.class, object);

            if (LOGGER.isDebugEnabled())
            {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                marshaller.marshal(jaxbElement, os);
                LOGGER.debug("Marshalled Soap Transfer Object: " +
os.toString());
            }
            else
            {
                OutputStream os = new NullOutputStream();
                marshaller.marshal(jaxbElement, os);
            }
        }
        catch (JAXBException e)
        {
            String errorMessage = buildValidationErrorMessage(pathInfo,
object, e);
            LOGGER.debug(errorMessage);
            throw new RuntimeException(errorMessage);
        }
        catch (SAXException e)
        {
            String errorMessage = buildValidationErrorMessage(pathInfo,
object, e);
            LOGGER.debug(errorMessage);
            throw new RuntimeException(errorMessage);
        }


Best regards,
Chris
-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jax-ws.dev.java.net
For additional commands, e-mail: users-help_at_jax-ws.dev.java.net
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com