You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by TheWinch <vi...@thalesgroup.com> on 2010/02/22 22:49:29 UTC

Help with Camel JAXB (SMX4 + Camel 2.1.0)

Hi people,

I'm experiencing a curious problem with Camel JAXB. To make it short:
unmarshalling works correctly, but not marshalling.

I have a route that receives a CxfPayload and unmarshals it to Java. It
works perfectly.
A second route has a processor that emits a Java payload, that must then be
marshaled to XML -> I get the exception below.
Both payloads are in the same package, they are generated using JaxB
generation so they have the correct annotations.

Route 1 (correct) :
from("file:/var/diva/crisis")
    .unmarshal("jxb")
    .to( "bean:crisisServiceImpl?method=createCrisis" );

Route 2 (incorrect) :
from("direct:sendAck")
    .to("log:cr-sendack1")
    .marshal("jxb")
    .to("log:cr-sendack2")

The exception: 
22:42:28,531 | INFO  | cr-sendack1                        88 |
Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
Body:<ns2:AlarmA ......]
22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 | Application
{http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
Exception occurred during execution on the exchange: Exchange[Message:
eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
        at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
        at
org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
        at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
        at
org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
.....
Caused by: org.apache.camel.CamelExecutionException: Exception occurred
during execution on the exchange: Exchange[Message:
eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
        at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
        at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
        at
org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
        at
org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
        at
eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
 ............
Caused by: javax.xml.bind.JAXBException: Unable to create context
 - with linked exception:
[java.lang.NoSuchMethodException:
com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
java.lang.ClassLoader)]
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
        ... 68 more
Caused by: java.lang.NoSuchMethodException:
com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
java.lang.ClassLoader)
        at java.lang.Class.getMethod(Class.java:1605)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
        ... 74 more


I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
resolved correctly :
karaf@root> packages:imports  210 | grep v2
Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
version=0.0.0

All processing is performed inside the same bundle (a SOAP service is
invoke, which calls a ProducerTemplate to send a message to the "direct"
route depicted above).


If you have the key, please, help me !
-- 
View this message in context: http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by ext2 <xu...@tongtech.com>.
Hi,TheWinch:

 	I am using JAXB in osgi too, it seems I haven't encounter such a
problem; But I really want know what's exactly problem you have.
	And could you help me to send you project to my private mail, if you
don't mind?
	If you cannot sent , could you help me to tell some details:

	Is the generated JAXB Object in a separate bundle? Or generated JAXB
object exists in the same bundle of camel route?

	If the generated JAXB Object in a separate bundle,  how do you
import the jaxb object's class?  Using "import-package" or
"Require-Package"? 
	It seems the JAXB Class can be find, but JAXB.index cannot be find,
in you test.
	If you are using "Require-Package" ... Felix has a bug for
Require-Package, it will cause some class or resource searching failed,
until 3.0.2 solved it, so if you are using SMX, you must update to Apache
Karaf 2.1.0(it bundled the felix framework 3.0.2 inside)
	But if you are using "Import-Package", I am not sure why now;


Thanks a lot;

-----Original-----
Sender: TheWinch [mailto:vincent.girardreydet@thalesgroup.com] 
Date: 2010/2/23 5:49
Receiver: users@camel.apache.org
Subject: Help with Camel JAXB (SMX4 + Camel 2.1.0)


Hi people,

I'm experiencing a curious problem with Camel JAXB. To make it short:
unmarshalling works correctly, but not marshalling.

I have a route that receives a CxfPayload and unmarshals it to Java. It
works perfectly.
A second route has a processor that emits a Java payload, that must then be
marshaled to XML -> I get the exception below.
Both payloads are in the same package, they are generated using JaxB
generation so they have the correct annotations.

Route 1 (correct) :
from("file:/var/diva/crisis")
    .unmarshal("jxb")
    .to( "bean:crisisServiceImpl?method=createCrisis" );

Route 2 (incorrect) :
from("direct:sendAck")
    .to("log:cr-sendack1")
    .marshal("jxb")
    .to("log:cr-sendack2")

The exception: 
22:42:28,531 | INFO  | cr-sendack1                        88 |
Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
Body:<ns2:AlarmA ......]
22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 | Application
{http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.d
iva.eu/schemas/crisissvc/1.0}TreatCrisis
has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
Exception occurred during execution on the exchange: Exchange[Message:
eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
        at
org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.j
ava:155)
        at
org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMet
hodInvoker.java:85)
        at
org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:1
21)
        at
org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
.....
Caused by: org.apache.camel.CamelExecutionException: Exception occurred
during execution on the exchange: Exchange[Message:
eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
        at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.
java:1055)
        at
org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:4
45)
        at
org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProdu
cerTemplate.java:431)
        at
org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProdu
cerTemplate.java:156)
        at
eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl
.java:322)
 ............
Caused by: javax.xml.bind.JAXBException: Unable to create context
 - with linked exception:
[java.lang.NoSuchMethodException:
com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
java.lang.ClassLoader)]
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.
java:138)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.jav
a:103)
        at
org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:5
8)
        ... 68 more
Caused by: java.lang.NoSuchMethodException:
com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
java.lang.ClassLoader)
        at java.lang.Class.getMethod(Class.java:1605)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
        ... 74 more


I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
resolved correctly :
karaf@root> packages:imports  210 | grep v2
Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
version=0.0.0

All processing is performed inside the same bundle (a SOAP service is
invoke, which calls a ProducerTemplate to send a message to the "direct"
route depicted above).


If you have the key, please, help me !
-- 
View this message in context:
http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp2769
5115p27695115.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.




Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)(Maybe a bug of Camel)

Posted by ext2 <xu...@tongtech.com>.
Hi, Camel: 
	I have raised a JIRA for the question;
Hi, Camel:
	I have raised a issue to show it more clearly using source code
https://issues.apache.org/jira/browse/CAMEL-3438

major changes exists in the JAXBDataFormatter .getContext() method

=====================================================================
Hi,Camel:
	Camel's JAXBDataFormatter using Thread.contextClassLoader() to
create JAXBContext;
	It's suspiciously, I think it's bug;
	Spring DM (from 1.2.0)'s extender will using a separate Thread to
loading  spring configures; In this thread, the thread's context ClassLoader
will be set to the current bundle's ClassLoader; So if JaxbDataFormatter's
context is created in the thread, the class loader will be right;
	But this is not always guaranteed, so sometimes, the Camel's jaxb
will not works;
	I think the JAXBDataFormatter should explicitly use Spring
Application Context's class loader; 


-----Origin-----
Sender: sharma_arun_se [mailto:arun.kaundal@gmail.com] 
Date: 2010/12/17 23:28
Receiver: users@camel.apache.org
Subject: Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)


Hi,

It was in same bundle of camel route.

Do let me know, if you need more input.


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
0566p3309556.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.






Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)(Maybe a bug of Camel)

Posted by ext2 <xu...@tongtech.com>.
Hi,Camel:
	Camel's JAXBDataFormatter using Thread.contextClassLoader() to
create JAXBContext;
	It's suspiciously, I think it's bug;
	Spring DM (from 1.2.0)'s extender will using a separate Thread to
loading  spring configures; In this thread, the thread's context ClassLoader
will be set to the current bundle's ClassLoader; So if JaxbDataFormatter's
context is created in the thread, the class loader will be right;
	But this is not always guaranteed, so sometimes, the Camel's jaxb
will not works;
	I think the JAXBDataFormatter should explicitly use Spring
Application Context's class loader; 


-----Origin-----
Sender: sharma_arun_se [mailto:arun.kaundal@gmail.com] 
Date: 2010/12/17 23:28
Receiver: users@camel.apache.org
Subject: Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)


Hi,

It was in same bundle of camel route.

Do let me know, if you need more input.


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
0566p3309556.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.




Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by sharma_arun_se <ar...@gmail.com>.
Hi,

It was in same bundle of camel route.

Do let me know, if you need more input.


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-tp470566p3309556.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by ext2 <xu...@tongtech.com>.
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:
<bean id="jaxbContextResolver"
class="com.blogspot.techiesweek.util.JAXBContextResolver"/>

and processor class bean, which make use of jaxb context is declare as:
    <bean id="dataExtractorBuilder"
class="com.blogspot.techiesweek.processor.DataExtractorBuilder">
        <property name="dataExtractorService" ref="dataExtractorService"/>
        <property name="tempReportFilePath" value="${tempReportFilePath}"/>
        <property name="validationSchemaUri"
value="${validationSchemaUri}"/>
        <property name="reportFilenamePrefix"
value="${reportFilenamePrefix}"/>
        <property name="jaxbContextResolver" ref="jaxbContextResolver"/>
    </bean>

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.



Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by sharma_arun_se <ar...@gmail.com>.
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:
<bean id="jaxbContextResolver"
class="com.blogspot.techiesweek.util.JAXBContextResolver"/>

and processor class bean, which make use of jaxb context is declare as:
    <bean id="dataExtractorBuilder"
class="com.blogspot.techiesweek.processor.DataExtractorBuilder">
        <property name="dataExtractorService" ref="dataExtractorService"/>
        <property name="tempReportFilePath" value="${tempReportFilePath}"/>
        <property name="validationSchemaUri"
value="${validationSchemaUri}"/>
        <property name="reportFilenamePrefix"
value="${reportFilenamePrefix}"/>
        <property name="jaxbContextResolver" ref="jaxbContextResolver"/>
    </bean>

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-tp470566p3308986.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by Willem Jiang <wi...@gmail.com>.
Hi,

If you found the solution, do you mind to share it with the community ?

On 11/20/10 1:16 PM, sharma_arun_se wrote:
>
> Hi All,
>
> I have found alternative solution of my problem. If anybody face same kind
> of problem, I will be more than happy to discuss the solution.
>
>
> 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/
>
> -----
> Arun Kumar
>
> SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open
> Source Contributor
>
> Linkedin :http://in.linkedin.com/in/aronkumar
> Gtalk: arun.kaundal@gmail.com
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by sharma_arun_se <ar...@gmail.com>.
Hi All,

I have found alternative solution of my problem. If anybody face same kind
of problem, I will be more than happy to discuss the solution.


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/

-----
Arun Kumar

SOA (Fuse ESB, Camel, ActiveMQ, OSGi) and RESTful Solution Architect, Open
Source Contributor 

Linkedin :http://in.linkedin.com/in/aronkumar
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-tp470566p3273359.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by Willem Jiang <wi...@gmail.com>.
You are deploying the application context into a OSGi container, it's 
more complicate.

Currently camel will try to use the application context classloader to 
load the jaxb context classes. So please make sure your spring 
application context bundle imports the generated package, and the 
generated package is exported rightly.

On 11/16/10 9:48 PM, sharma_arun_se wrote:
>
> Hi,
>
> I hope somebody have solved this problem, as I can see there are number of
> posting for the problem but no real and satisfactory common solution to the
> problem.
>
> Let me discuss my issue:
>
> I have created jaxb bean as :
> <bean id="myJaxb" class="org.apache.camel.model.dataformat.JaxbDataFormat">
>    <property name="prettyPrint" value="true"/>
>    <property name="contextPath" value="com.xyz.abc.xa.jaxb.generated"/>
> </bean>
>
> In my routeBuilder.java Class, I have create route as :
>
>       from(quartzUri)
>        .to(DataextracterUri)
>        .marshal(myjaxb)
>        .(ftpServerURI);
>
> Now for your concern, I verify you that my jaxb generated classes are in
> package: com.xyz.abc.xa.jaxb.generated. This include ObjectFactory.class.
> But there is nothing like jaxb.index inside it.
>
> Why classloader not picking up the class ObjectFactory, although it is there
> in com.xyz.abc.xa.jaxb.generated package.
>
>
> FYI: I am deploying my bundle using feature in ServiceMix 4.3--2.0
>
>
> Error Log:
>
> Caused by: javax.xml.bind.JAXBException: Unable to create context
> - with linked exception:
> http://java.lang.reflect.InvocationTargetException
> at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
> at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)
> ... 54 more
> Caused by: java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_18
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_18
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_18
> at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_18
> at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)
> ... 58 more
> Caused by: javax.xml.bind.JAXBException: "com.xyz.abc.xa.jaxb.generated"
> doesnt contain ObjectFactory.class or jaxb.index
> at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
> ... 63 more
>
>
> Thank you,
>
> Arun Kumar (sharma_arun_se)


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by sharma_arun_se <ar...@gmail.com>.
Hi,

I hope somebody have solved this problem, as I can see there are number of
posting for the problem but no real and satisfactory common solution to the
problem.

Let me discuss my issue:

I have created jaxb bean as :
<bean id="myJaxb" class="org.apache.camel.model.dataformat.JaxbDataFormat">
  <property name="prettyPrint" value="true"/>
  <property name="contextPath" value="com.xyz.abc.xa.jaxb.generated"/>
</bean>  

In my routeBuilder.java Class, I have create route as :

     from(quartzUri)
      .to(DataextracterUri)
      .marshal(myjaxb)
      .(ftpServerURI);

Now for your concern, I verify you that my jaxb generated classes are in
package: com.xyz.abc.xa.jaxb.generated. This include ObjectFactory.class.
But there is nothing like jaxb.index inside it.

Why classloader not picking up the class ObjectFactory, although it is there
in com.xyz.abc.xa.jaxb.generated package. 


FYI: I am deploying my bundle using feature in ServiceMix 4.3--2.0


Error Log:

Caused by: javax.xml.bind.JAXBException: Unable to create context
- with linked exception:
http://java.lang.reflect.InvocationTargetException
at javax.xml.bind.ContextFinder.find(ContextFinder.java:68)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
at com.vzb.ram.bind.ns.XmlPoJoUtil.toPoJo(XmlPoJoUtil.java:185)
... 54 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_18
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_18
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_18
at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_18
at javax.xml.bind.ContextFinder.find(ContextFinder.java:63)
... 58 more
Caused by: javax.xml.bind.JAXBException: "com.xyz.abc.xa.jaxb.generated"
doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
... 63 more


Thank you,

Arun Kumar (sharma_arun_se)
-- 
View this message in context: http://camel.465427.n5.nabble.com/Help-with-Camel-JAXB-SMX4-Camel-2-1-0-tp470566p3267328.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by Willem Jiang <wi...@gmail.com>.
Maybe you can consider to put the JAXB jars into the endorse directory 
of JDK 1.6.

Willem

TheWinch wrote:
> I cannot easily because I have code that is bound to jdk1.6. Do you think
> that uninstalling the jaxb-impl-2.1.12 bundle and adding com.sun.xml.bind.v2
> to the org.osgi.framework.system.packages variable would do ?
> 
> 
> willem.jiang wrote:
>> Which kind of JDK are you using?
>> Can you try to use JDK 1.5.0 which doesn't embed the JAXB API and 
>> implementation ?
>>
>> Willem
>>
>> TheWinch wrote:
>>> The unmarshal("jxb") refers to a JaxbDataFormat defined in Spring
>>> configuration :
>>> <camelContext>
>>> <routeBuilder ref="myBuilder"/>
>>> <dataFormats>
>>>   <jaxb id="jxb" context="eu.diva.tis.api.domain.esb"/>
>>> </dataFormats>
>>> </camelContext>
>>>
>>> And I've triple-checked that the context is correct and no other package
>>> than the one being referenced is used. Note also that this DataFormat is
>>> used with success during the unmarshalling operation :-( ???
>>>
>>> I really don't have a clue why the createMethod cannot be found during
>>> marshalling operations, but can be found during unmarshalling. Maybe I'm
>>> using the wrong JAXB library ? But I'm using the standard set provided
>>> with
>>> Fuse ESB 4.1 release candidate, so it should be OK ?
>>>
>>>
>>>
>>> Stephen Gargan wrote:
>>>> It could be that your route definition is incorrect, it should read
>>>> jaxb not jxb. You could also try creating a JaxbDataFormat explicitly
>>>> and use that in your route instead.
>>>>
>>>> e.g
>>>>
>>>> DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
>>>>
>>>>                 from("direct:start").
>>>>                         unmarshal(jaxb).
>>>>                         to("mock:result");
>>>>
>>>>
>>>> On Mon, Feb 22, 2010 at 9:49 PM, TheWinch
>>>> <vi...@thalesgroup.com> wrote:
>>>>> Hi people,
>>>>>
>>>>> I'm experiencing a curious problem with Camel JAXB. To make it short:
>>>>> unmarshalling works correctly, but not marshalling.
>>>>>
>>>>> I have a route that receives a CxfPayload and unmarshals it to Java. It
>>>>> works perfectly.
>>>>> A second route has a processor that emits a Java payload, that must
>>>>> then
>>>>> be
>>>>> marshaled to XML -> I get the exception below.
>>>>> Both payloads are in the same package, they are generated using JaxB
>>>>> generation so they have the correct annotations.
>>>>>
>>>>> Route 1 (correct) :
>>>>> from("file:/var/diva/crisis")
>>>>>    .unmarshal("jxb")
>>>>>    .to( "bean:crisisServiceImpl?method=createCrisis" );
>>>>>
>>>>> Route 2 (incorrect) :
>>>>> from("direct:sendAck")
>>>>>    .to("log:cr-sendack1")
>>>>>    .marshal("jxb")
>>>>>    .to("log:cr-sendack2")
>>>>>
>>>>> The exception:
>>>>> 22:42:28,531 | INFO  | cr-sendack1                        88 |
>>>>> Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
>>>>> Body:<ns2:AlarmA ......]
>>>>> 22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 |
>>>>> Application
>>>>> {http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
>>>>> has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
>>>>> Exception occurred during execution on the exchange: Exchange[Message:
>>>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>>>        at
>>>>> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
>>>>>        at
>>>>> org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
>>>>>        at
>>>>> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
>>>>>        at
>>>>> org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
>>>>> .....
>>>>> Caused by: org.apache.camel.CamelExecutionException: Exception occurred
>>>>> during execution on the exchange: Exchange[Message:
>>>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>>>        at
>>>>> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
>>>>>        at
>>>>> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
>>>>>        at
>>>>> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
>>>>>        at
>>>>> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
>>>>>        at
>>>>> eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
>>>>>  ............
>>>>> Caused by: javax.xml.bind.JAXBException: Unable to create context
>>>>>  - with linked exception:
>>>>> [java.lang.NoSuchMethodException:
>>>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>>>> java.lang.ClassLoader)]
>>>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
>>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
>>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
>>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
>>>>>        at
>>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
>>>>>        at
>>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
>>>>>        at
>>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
>>>>>        ... 68 more
>>>>> Caused by: java.lang.NoSuchMethodException:
>>>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>>>> java.lang.ClassLoader)
>>>>>        at java.lang.Class.getMethod(Class.java:1605)
>>>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
>>>>>        ... 74 more
>>>>>
>>>>>
>>>>> I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
>>>>> resolved correctly :
>>>>> karaf@root> packages:imports  210 | grep v2
>>>>> Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
>>>>> version=0.0.0
>>>>>
>>>>> All processing is performed inside the same bundle (a SOAP service is
>>>>> invoke, which calls a ProducerTemplate to send a message to the
>>>>> "direct"
>>>>> route depicted above).
>>>>>
>>>>>
>>>>> If you have the key, please, help me !
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
>>>>> Sent from the Camel - Users (activemq) mailing list archive at
>>>>> Nabble.com.
>>>>>
>>>>>
>>
>>
> 


Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by TheWinch <vi...@thalesgroup.com>.
I cannot easily because I have code that is bound to jdk1.6. Do you think
that uninstalling the jaxb-impl-2.1.12 bundle and adding com.sun.xml.bind.v2
to the org.osgi.framework.system.packages variable would do ?


willem.jiang wrote:
> 
> Which kind of JDK are you using?
> Can you try to use JDK 1.5.0 which doesn't embed the JAXB API and 
> implementation ?
> 
> Willem
> 
> TheWinch wrote:
>> The unmarshal("jxb") refers to a JaxbDataFormat defined in Spring
>> configuration :
>> <camelContext>
>> <routeBuilder ref="myBuilder"/>
>> <dataFormats>
>>   <jaxb id="jxb" context="eu.diva.tis.api.domain.esb"/>
>> </dataFormats>
>> </camelContext>
>> 
>> And I've triple-checked that the context is correct and no other package
>> than the one being referenced is used. Note also that this DataFormat is
>> used with success during the unmarshalling operation :-( ???
>> 
>> I really don't have a clue why the createMethod cannot be found during
>> marshalling operations, but can be found during unmarshalling. Maybe I'm
>> using the wrong JAXB library ? But I'm using the standard set provided
>> with
>> Fuse ESB 4.1 release candidate, so it should be OK ?
>> 
>> 
>> 
>> Stephen Gargan wrote:
>>> It could be that your route definition is incorrect, it should read
>>> jaxb not jxb. You could also try creating a JaxbDataFormat explicitly
>>> and use that in your route instead.
>>>
>>> e.g
>>>
>>> DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
>>>
>>>                 from("direct:start").
>>>                         unmarshal(jaxb).
>>>                         to("mock:result");
>>>
>>>
>>> On Mon, Feb 22, 2010 at 9:49 PM, TheWinch
>>> <vi...@thalesgroup.com> wrote:
>>>> Hi people,
>>>>
>>>> I'm experiencing a curious problem with Camel JAXB. To make it short:
>>>> unmarshalling works correctly, but not marshalling.
>>>>
>>>> I have a route that receives a CxfPayload and unmarshals it to Java. It
>>>> works perfectly.
>>>> A second route has a processor that emits a Java payload, that must
>>>> then
>>>> be
>>>> marshaled to XML -> I get the exception below.
>>>> Both payloads are in the same package, they are generated using JaxB
>>>> generation so they have the correct annotations.
>>>>
>>>> Route 1 (correct) :
>>>> from("file:/var/diva/crisis")
>>>>    .unmarshal("jxb")
>>>>    .to( "bean:crisisServiceImpl?method=createCrisis" );
>>>>
>>>> Route 2 (incorrect) :
>>>> from("direct:sendAck")
>>>>    .to("log:cr-sendack1")
>>>>    .marshal("jxb")
>>>>    .to("log:cr-sendack2")
>>>>
>>>> The exception:
>>>> 22:42:28,531 | INFO  | cr-sendack1                        88 |
>>>> Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
>>>> Body:<ns2:AlarmA ......]
>>>> 22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 |
>>>> Application
>>>> {http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
>>>> has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
>>>> Exception occurred during execution on the exchange: Exchange[Message:
>>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>>        at
>>>> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
>>>>        at
>>>> org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
>>>>        at
>>>> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
>>>>        at
>>>> org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
>>>> .....
>>>> Caused by: org.apache.camel.CamelExecutionException: Exception occurred
>>>> during execution on the exchange: Exchange[Message:
>>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>>        at
>>>> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
>>>>        at
>>>> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
>>>>        at
>>>> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
>>>>        at
>>>> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
>>>>        at
>>>> eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
>>>>  ............
>>>> Caused by: javax.xml.bind.JAXBException: Unable to create context
>>>>  - with linked exception:
>>>> [java.lang.NoSuchMethodException:
>>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>>> java.lang.ClassLoader)]
>>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
>>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
>>>>        at
>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
>>>>        at
>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
>>>>        at
>>>> org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
>>>>        ... 68 more
>>>> Caused by: java.lang.NoSuchMethodException:
>>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>>> java.lang.ClassLoader)
>>>>        at java.lang.Class.getMethod(Class.java:1605)
>>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
>>>>        ... 74 more
>>>>
>>>>
>>>> I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
>>>> resolved correctly :
>>>> karaf@root> packages:imports  210 | grep v2
>>>> Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
>>>> version=0.0.0
>>>>
>>>> All processing is performed inside the same bundle (a SOAP service is
>>>> invoke, which calls a ProducerTemplate to send a message to the
>>>> "direct"
>>>> route depicted above).
>>>>
>>>>
>>>> If you have the key, please, help me !
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
>>>> Sent from the Camel - Users (activemq) mailing list archive at
>>>> Nabble.com.
>>>>
>>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27700324.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by Willem Jiang <wi...@gmail.com>.
Which kind of JDK are you using?
Can you try to use JDK 1.5.0 which doesn't embed the JAXB API and 
implementation ?

Willem

TheWinch wrote:
> The unmarshal("jxb") refers to a JaxbDataFormat defined in Spring
> configuration :
> <camelContext>
> <routeBuilder ref="myBuilder"/>
> <dataFormats>
>   <jaxb id="jxb" context="eu.diva.tis.api.domain.esb"/>
> </dataFormats>
> </camelContext>
> 
> And I've triple-checked that the context is correct and no other package
> than the one being referenced is used. Note also that this DataFormat is
> used with success during the unmarshalling operation :-( ???
> 
> I really don't have a clue why the createMethod cannot be found during
> marshalling operations, but can be found during unmarshalling. Maybe I'm
> using the wrong JAXB library ? But I'm using the standard set provided with
> Fuse ESB 4.1 release candidate, so it should be OK ?
> 
> 
> 
> Stephen Gargan wrote:
>> It could be that your route definition is incorrect, it should read
>> jaxb not jxb. You could also try creating a JaxbDataFormat explicitly
>> and use that in your route instead.
>>
>> e.g
>>
>> DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
>>
>>                 from("direct:start").
>>                         unmarshal(jaxb).
>>                         to("mock:result");
>>
>>
>> On Mon, Feb 22, 2010 at 9:49 PM, TheWinch
>> <vi...@thalesgroup.com> wrote:
>>> Hi people,
>>>
>>> I'm experiencing a curious problem with Camel JAXB. To make it short:
>>> unmarshalling works correctly, but not marshalling.
>>>
>>> I have a route that receives a CxfPayload and unmarshals it to Java. It
>>> works perfectly.
>>> A second route has a processor that emits a Java payload, that must then
>>> be
>>> marshaled to XML -> I get the exception below.
>>> Both payloads are in the same package, they are generated using JaxB
>>> generation so they have the correct annotations.
>>>
>>> Route 1 (correct) :
>>> from("file:/var/diva/crisis")
>>>    .unmarshal("jxb")
>>>    .to( "bean:crisisServiceImpl?method=createCrisis" );
>>>
>>> Route 2 (incorrect) :
>>> from("direct:sendAck")
>>>    .to("log:cr-sendack1")
>>>    .marshal("jxb")
>>>    .to("log:cr-sendack2")
>>>
>>> The exception:
>>> 22:42:28,531 | INFO  | cr-sendack1                        88 |
>>> Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
>>> Body:<ns2:AlarmA ......]
>>> 22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 |
>>> Application
>>> {http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
>>> has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
>>> Exception occurred during execution on the exchange: Exchange[Message:
>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>        at
>>> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
>>>        at
>>> org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
>>>        at
>>> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
>>>        at
>>> org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
>>> .....
>>> Caused by: org.apache.camel.CamelExecutionException: Exception occurred
>>> during execution on the exchange: Exchange[Message:
>>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>>        at
>>> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
>>>        at
>>> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
>>>        at
>>> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
>>>        at
>>> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
>>>        at
>>> eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
>>>  ............
>>> Caused by: javax.xml.bind.JAXBException: Unable to create context
>>>  - with linked exception:
>>> [java.lang.NoSuchMethodException:
>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>> java.lang.ClassLoader)]
>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
>>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
>>>        at
>>> org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
>>>        at
>>> org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
>>>        at
>>> org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
>>>        ... 68 more
>>> Caused by: java.lang.NoSuchMethodException:
>>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>>> java.lang.ClassLoader)
>>>        at java.lang.Class.getMethod(Class.java:1605)
>>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
>>>        ... 74 more
>>>
>>>
>>> I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
>>> resolved correctly :
>>> karaf@root> packages:imports  210 | grep v2
>>> Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
>>> version=0.0.0
>>>
>>> All processing is performed inside the same bundle (a SOAP service is
>>> invoke, which calls a ProducerTemplate to send a message to the "direct"
>>> route depicted above).
>>>
>>>
>>> If you have the key, please, help me !
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
>>> Sent from the Camel - Users (activemq) mailing list archive at
>>> Nabble.com.
>>>
>>>
>>
> 


Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by TheWinch <vi...@thalesgroup.com>.
The unmarshal("jxb") refers to a JaxbDataFormat defined in Spring
configuration :
<camelContext>
<routeBuilder ref="myBuilder"/>
<dataFormats>
  <jaxb id="jxb" context="eu.diva.tis.api.domain.esb"/>
</dataFormats>
</camelContext>

And I've triple-checked that the context is correct and no other package
than the one being referenced is used. Note also that this DataFormat is
used with success during the unmarshalling operation :-( ???

I really don't have a clue why the createMethod cannot be found during
marshalling operations, but can be found during unmarshalling. Maybe I'm
using the wrong JAXB library ? But I'm using the standard set provided with
Fuse ESB 4.1 release candidate, so it should be OK ?



Stephen Gargan wrote:
> 
> It could be that your route definition is incorrect, it should read
> jaxb not jxb. You could also try creating a JaxbDataFormat explicitly
> and use that in your route instead.
> 
> e.g
> 
> DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
> 
>                 from("direct:start").
>                         unmarshal(jaxb).
>                         to("mock:result");
> 
> 
> On Mon, Feb 22, 2010 at 9:49 PM, TheWinch
> <vi...@thalesgroup.com> wrote:
>>
>> Hi people,
>>
>> I'm experiencing a curious problem with Camel JAXB. To make it short:
>> unmarshalling works correctly, but not marshalling.
>>
>> I have a route that receives a CxfPayload and unmarshals it to Java. It
>> works perfectly.
>> A second route has a processor that emits a Java payload, that must then
>> be
>> marshaled to XML -> I get the exception below.
>> Both payloads are in the same package, they are generated using JaxB
>> generation so they have the correct annotations.
>>
>> Route 1 (correct) :
>> from("file:/var/diva/crisis")
>>    .unmarshal("jxb")
>>    .to( "bean:crisisServiceImpl?method=createCrisis" );
>>
>> Route 2 (incorrect) :
>> from("direct:sendAck")
>>    .to("log:cr-sendack1")
>>    .marshal("jxb")
>>    .to("log:cr-sendack2")
>>
>> The exception:
>> 22:42:28,531 | INFO  | cr-sendack1                        88 |
>> Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
>> Body:<ns2:AlarmA ......]
>> 22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 |
>> Application
>> {http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
>> has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
>> Exception occurred during execution on the exchange: Exchange[Message:
>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>        at
>> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
>>        at
>> org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
>>        at
>> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
>>        at
>> org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
>> .....
>> Caused by: org.apache.camel.CamelExecutionException: Exception occurred
>> during execution on the exchange: Exchange[Message:
>> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>>        at
>> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
>>        at
>> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
>>        at
>> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
>>        at
>> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
>>        at
>> eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
>>  ............
>> Caused by: javax.xml.bind.JAXBException: Unable to create context
>>  - with linked exception:
>> [java.lang.NoSuchMethodException:
>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>> java.lang.ClassLoader)]
>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
>>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
>>        at
>> org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
>>        at
>> org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
>>        at
>> org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
>>        ... 68 more
>> Caused by: java.lang.NoSuchMethodException:
>> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
>> java.lang.ClassLoader)
>>        at java.lang.Class.getMethod(Class.java:1605)
>>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
>>        ... 74 more
>>
>>
>> I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
>> resolved correctly :
>> karaf@root> packages:imports  210 | grep v2
>> Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
>> version=0.0.0
>>
>> All processing is performed inside the same bundle (a SOAP service is
>> invoke, which calls a ProducerTemplate to send a message to the "direct"
>> route depicted above).
>>
>>
>> If you have the key, please, help me !
>> --
>> View this message in context:
>> http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
>> Sent from the Camel - Users (activemq) mailing list archive at
>> Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27699759.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Re: Help with Camel JAXB (SMX4 + Camel 2.1.0)

Posted by Stephen Gargan <st...@gmail.com>.
It could be that your route definition is incorrect, it should read
jaxb not jxb. You could also try creating a JaxbDataFormat explicitly
and use that in your route instead.

e.g

DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");

                from("direct:start").
                        unmarshal(jaxb).
                        to("mock:result");


On Mon, Feb 22, 2010 at 9:49 PM, TheWinch
<vi...@thalesgroup.com> wrote:
>
> Hi people,
>
> I'm experiencing a curious problem with Camel JAXB. To make it short:
> unmarshalling works correctly, but not marshalling.
>
> I have a route that receives a CxfPayload and unmarshals it to Java. It
> works perfectly.
> A second route has a processor that emits a Java payload, that must then be
> marshaled to XML -> I get the exception below.
> Both payloads are in the same package, they are generated using JaxB
> generation so they have the correct annotations.
>
> Route 1 (correct) :
> from("file:/var/diva/crisis")
>    .unmarshal("jxb")
>    .to( "bean:crisisServiceImpl?method=createCrisis" );
>
> Route 2 (incorrect) :
> from("direct:sendAck")
>    .to("log:cr-sendack1")
>    .marshal("jxb")
>    .to("log:cr-sendack2")
>
> The exception:
> 22:42:28,531 | INFO  | cr-sendack1                        88 |
> Exchange[BodyType:eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage,
> Body:<ns2:AlarmA ......]
> 22:42:28,546 | WARN  | phase.PhaseInterceptorChain       361 | Application
> {http://tis.diva.eu/schemas/crisissvc/1.0}CrisisManagerService#{http://tis.diva.eu/schemas/crisissvc/1.0}TreatCrisis
> has thrown exception, unwinding now org.apache.cxf.interceptor.Fault:
> Exception occurred during execution on the exchange: Exchange[Message:
> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>        at
> org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:155)
>        at
> org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:85)
>        at
> org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:121)
>        at
> org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:60)
> .....
> Caused by: org.apache.camel.CamelExecutionException: Exception occurred
> during execution on the exchange: Exchange[Message:
> eu.diva.tis.api.ws.alert.alarmtypes.AlarmAckMessage@11ffde3]
>        at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1055)
>        at
> org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:445)
>        at
> org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:431)
>        at
> org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:156)
>        at
> eu.diva.tis.crisis.internal.CrisisServiceImpl.sendAckToEsb(CrisisServiceImpl.java:322)
>  ............
> Caused by: javax.xml.bind.JAXBException: Unable to create context
>  - with linked exception:
> [java.lang.NoSuchMethodException:
> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
> java.lang.ClassLoader)]
>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:72)
>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:77)
>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:73)
>        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:69)
>        at
> org.apache.camel.converter.jaxb.JaxbDataFormat.createContext(JaxbDataFormat.java:138)
>        at
> org.apache.camel.converter.jaxb.JaxbDataFormat.getContext(JaxbDataFormat.java:103)
>        at
> org.apache.camel.converter.jaxb.JaxbDataFormat.marshal(JaxbDataFormat.java:58)
>        ... 68 more
> Caused by: java.lang.NoSuchMethodException:
> com.sun.xml.bind.v2.ContextFactory.createContext(java.lang.String,
> java.lang.ClassLoader)
>        at java.lang.Class.getMethod(Class.java:1605)
>        at javax.xml.bind.ContextFinder.find(ContextFinder.java:69)
>        ... 74 more
>
>
> I have tried to add com.sun.xml.bind.v2 to the imported packages. It is
> resolved correctly :
> karaf@root> packages:imports  210 | grep v2
> Apache ServiceMix Bundles: jaxb-impl-2.1.12 (90): com.sun.xml.bind.v2;
> version=0.0.0
>
> All processing is performed inside the same bundle (a SOAP service is
> invoke, which calls a ProducerTemplate to send a message to the "direct"
> route depicted above).
>
>
> If you have the key, please, help me !
> --
> View this message in context: http://old.nabble.com/Help-with-Camel-JAXB-%28SMX4-%2B-Camel-2.1.0%29-tp27695115p27695115.html
> Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.
>
>