Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 8022 invoked from network); 17 Dec 2010 12:03:50 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 17 Dec 2010 12:03:50 -0000 Received: (qmail 41142 invoked by uid 500); 17 Dec 2010 12:03:50 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 40960 invoked by uid 500); 17 Dec 2010 12:03:48 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 40952 invoked by uid 99); 17 Dec 2010 12:03:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Dec 2010 12:03:47 +0000 X-ASF-Spam-Status: No, hits=1.3 required=10.0 tests=SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [218.240.155.146] (HELO tongtech.com) (218.240.155.146) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 17 Dec 2010 12:03:41 +0000 Received: from IBM0618 (unknown [218.240.156.210]) by tongtech.com with CMailServer 5.3 SMTP; Fri, 17 Dec 2010 20:03:17 +0800 From: "ext2" To: References: <55f2e4a81002221711j5dbbf388x1f8813c4663009d1@mail.gmail.com> <1280404060855-470568.post@n5.nabble.com> <4B8396D5.6000208@gmail.com> <1280404060856-470570.post@n5.nabble.com> <4B83C1C7.4040607@gmail.com> <1280404060853-2256724.post@n5.nabble.com> <1289915289434-3267328.post@n5.nabble.com> <4CE31F69.4060102@gmail.com> <1290230217429-3273359.post@n5.nabble.com> <4CE87545.6090503@gmail.com> <1292565908245-3308986.post@n5.nabble.com> Subject: Re: Help with Camel JAXB (SMX4 + Camel 2.1.0) Date: Fri, 17 Dec 2010 20:03:16 +0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <1292565908245-3308986.post@n5.nabble.com> Thread-Index: AcudsHE/UL2YRX0YRcWqYare+I6zJAAMaGwQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 X-Virus-Checked: Checked by ClamAV on apache.org Hi, sharma_arun_se: Where do you deploy the JAXBContextResolver class? Deploy it in the same bundle of camel route? In the generated jaxb object's bundle? Or in a separate bundle? Thanks a lot -----origin ----- Sender: sharma_arun_se [mailto:arun.kaundal@gmail.com] Date: 2010/12/17 14:05 Receiver: users@camel.apache.org Subject: Re: Help with Camel JAXB (SMX4 + Camel 2.1.0) Hi All, Below is the solution that I used to integrate JAXB with apache camel and to resolve class-loading problem in OSGI: 1. I have written separate bean class to resolve Jaxb-Context something like: public class JAXBContextResolver { private static Logger log = Logger.getLogger(JAXBContextResolver.class); // annotatedPackages is the package , where I have put the generated jaxb's class private final static String annotatedPackages = "com.blogspot.techiesweek.jaxb.generated"; private final static JAXBContext context = initContext(); @SuppressWarnings({"ThrowInsideCatchBlockWhichIgnoresCaughtException"}) private static JAXBContext initContext() { JAXBContext context; try { ClassLoader cl = JAXBContextResolver.class.getClassLoader(); context = JAXBContext.newInstance(annotatedPackages, cl); log.info("jaxbContext created successfully!"); } catch (PropertyException pEx) { log.error("unable to set jaxb property: ", pEx); throw new RuntimeException("unable to set jaxb property:", pEx); } catch (JAXBException jaxbEx) { log.error("jaxb error while converting object to xml: ", jaxbEx); throw new RuntimeException("jaxb error while converting object to xml: ", jaxbEx); } return context; } @SuppressWarnings({"MethodMayBeStatic"}) public JAXBContext getContext() { log.debug("### inside JAXBContextResolver->getContext..."); return context; } } 2. I have declare this JAXBContextResolver bean class in spring application context config file as: and processor class bean, which make use of jaxb context is declare as: 3. Now in my camel processor class, I have used jaxb context to marshel jaxb classes to XML file as : public void process(Exchange exchange) throws ProcessingException { OutputStream os = null; String generatedFileName = getGeneratedFileName(); try { log.debug("loading jaxb context..."); JAXBContext jaxbContext = jaxbContextResolver.getContext(); Marshaller marshaller = jaxbContext.createMarshaller(); RootElementData rootElementData = myDataExtractorService.getRootElementData(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, validationSchemaUri); File xmlDocumentFile = new File(tempReportFilePath, generatedFileName); os = new FileOutputStream(xmlDocumentFile); marshaller.marshal(rootElementData , os); message.setHeader("CamelFileName", generatedFileName ); message.setBody(xmlDocumentFile); that's it. If anybody face any problem, do let me know. I will be more than happy to resolve your queries. Thanks, Arun Kumar (Sharma_arun_se) ----- Regards, Arun Kumar (sharma_arun_se) Expert SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open Source Contributor. linkedin: http://in.linkedin.com/in/aronkumar twitter: https://twitter.com/#!/SharmaArunKumar blog: http://techiesweek.blogspot.com/ Gtalk: arun.kaundal@gmail.com -- View this message in context: http://camel.465427.n5.nabble.com/Help-with-Camel-JAXB-SMX4-Camel-2-1-0-tp47 0566p3308986.html Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.