You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dresden <is...@gmail.com> on 2010/09/08 22:22:35 UTC

JAXB Unmarshalling - DataFormat error ... suggestions?

I am trying to get basic unmarshalling to work. The samples show this (and I
am trying it verbatim, but changed the package ref), but I get the following
error.

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <dataFormats>
    <jaxb id="myJaxb" prettyPrint="true"
contextPath="org.apache.camel.example"/>
  </dataFormats>

  <route>
    <from uri="direct:start"/>
    <marshal ref="myJaxb"/>
    <to uri="direct:marshalled"/>
  </route>
  <route>
    <from uri="direct:marshalled"/>
    <unmarshal ref="myJaxb"/>
    <to uri="mock:result"/>
  </route>

</camelContext>


Failed to create route route1 at: >>> Marshal[ref:myJaxb] <<< in route:
Route[[From[direct:start]] -> [Marshal[ref:myJaxb], To[direc... because of
dataFormat must be specified

Are the docs out of date? What am I missing?

My Spring config points to these XSDs:

xsi:schemaLocation="
   http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
   "

Thanks in advance for any help!
-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2814620.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Christian Müller <ch...@gmail.com>.
Hello dresden!

(Sounds lucky for me, because I was born in Dresden... :o) )

Claus has explained this in his book Camel in action (
http://www.manning.com/ibsen/). I think you need a copy... :-)

The source code is available at google code and I think you should follow
the following links:
http://code.google.com/p/camelinaction/source/browse/trunk/chapter3/order/src/test/java/camelinaction/PurchaseOrderJaxbTest.java
http://code.google.com/p/camelinaction/source/browse/trunk/chapter3/order/src/test/resources/camelinaction/order-jaxb.xml
http://code.google.com/p/camelinaction/source/browse/trunk/chapter3/order/src/test/resources/camelinaction/jaxb.index

I think you have forgotten the jaxb.index file.
Alternative, you can use the ObjectFactory class (which is generated by the
JAXB xjc).

Hope this will help,
Christian

On Fri, Sep 10, 2010 at 7:05 PM, dresden <is...@gmail.com> wrote:

>
> Hello,
> I am using maven and this are the dependencies:
>
>                <dependency>
>                        <groupId>org.apache.camel</groupId>
>                        <artifactId>camel-spring</artifactId>
>                        <version>2.4.0</version>
>                </dependency>
>
>                <dependency>
>                        <groupId>org.apache.camel</groupId>
>                        <artifactId>camel-jms</artifactId>
>                        <version>2.4.0</version>
>                </dependency>
>
>                <dependency>
>                        <groupId>org.apache.camel</groupId>
>                        <artifactId>camel-jaxb</artifactId>
>                        <version>2.4.0</version>
>                </dependency>
>
> I am still getting this error. Maybe I am missing something on how Jaxb is
> supposed to work for Camel.
>
> This is my route (verbatim)
>
>                <route>
>                        <from uri="amq:queue:event.x" />
>                        <unmarshal>
>                                <jaxb prettyPrint="true"
> contextPath="test.integration.dto" />
>                        </unmarshal>
>                        <marshal>
>                                <jaxb prettyPrint="true"
> contextPath="test.integration.dto" />
>                        </marshal>
>                        <to uri="amq:queue:event.y" />
>                </route>
>
> This is the my class that I want to marshall, unmarshall:
>
> package test.integration.dto;
>
> import java.io.Serializable;
>
> import javax.xml.bind.annotation.XmlRootElement;
>
> @XmlRootElement
> public class Event implements Serializable {
>    String type;
>    String user;
>    String system;
>
>    public String getType() {
>        return type;
>    }
>    public void setType(String type) {
>        this.type = type;
>    }
>    public String getUser() {
>        return user;
>    }
>    public void setUser(String user) {
>        this.user = user;
>    }
>    public String getSystem() {
>        return system;
>    }
>    public void setSystem(String system) {
>        this.system = system;
>    }
> }
>
> That is all the config I have done. Does anyone see any problems with that?
> I send a JMS message to event.x
>
> <Event/>
>
> is the content of the JMS message. I am hoping that it will unmarshall that
> into an Event pojo (above, annotated). Then marshal it back into xml. I
> still get the DataFormat error:
>
> Caused by: java.io.IOException: "test.integration.dto" doesnt contain
> ObjectFactory.class or jaxb.index
>
> Thanks for all the responses!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2835310.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by dresden <is...@gmail.com>.
Hello,
I am using maven and this are the dependencies:

                <dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring</artifactId>
			<version>2.4.0</version>
		</dependency>

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jms</artifactId>
			<version>2.4.0</version>
		</dependency>
		
		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-jaxb</artifactId>
			<version>2.4.0</version>
		</dependency>

I am still getting this error. Maybe I am missing something on how Jaxb is
supposed to work for Camel.

This is my route (verbatim)

                <route>
			<from uri="amq:queue:event.x" />
			<unmarshal>
				<jaxb prettyPrint="true" contextPath="test.integration.dto" />
			</unmarshal>
			<marshal>
				<jaxb prettyPrint="true" contextPath="test.integration.dto" />
			</marshal>
			<to uri="amq:queue:event.y" />
		</route>

This is the my class that I want to marshall, unmarshall:

package test.integration.dto;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlRootElement;
 
@XmlRootElement
public class Event implements Serializable {
    String type;
    String user;
    String system;
    
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }
    public String getSystem() {
        return system;
    }
    public void setSystem(String system) {
        this.system = system;
    } 
}

That is all the config I have done. Does anyone see any problems with that?
I send a JMS message to event.x

<Event/>

is the content of the JMS message. I am hoping that it will unmarshall that
into an Event pojo (above, annotated). Then marshal it back into xml. I
still get the DataFormat error:

Caused by: java.io.IOException: "test.integration.dto" doesnt contain
ObjectFactory.class or jaxb.index

Thanks for all the responses!



-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2835310.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Christian Müller <ch...@gmail.com>.
Do you have camel-jaxb in your classpath? Which version of camel do you use?

Cheers,
Christian

Am 08.09.2010 22:23 schrieb "dresden" <is...@gmail.com>:


I am trying to get basic unmarshalling to work. The samples show this (and I
am trying it verbatim, but changed the package ref), but I get the following
error.

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
 <dataFormats>
   <jaxb id="myJaxb" prettyPrint="true"
contextPath="org.apache.camel.example"/>
 </dataFormats>

 <route>
   <from uri="direct:start"/>
   <marshal ref="myJaxb"/>
   <to uri="direct:marshalled"/>
 </route>
 <route>
   <from uri="direct:marshalled"/>
   <unmarshal ref="myJaxb"/>
   <to uri="mock:result"/>
 </route>

</camelContext>


Failed to create route route1 at: >>> Marshal[ref:myJaxb] <<< in route:
Route[[From[direct:start]] -> [Marshal[ref:myJaxb], To[direc... because of
dataFormat must be specified

Are the docs out of date? What am I missing?

My Spring config points to these XSDs:

xsi:schemaLocation="
  http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
  "

Thanks in advance for any help!
--
View this message in context:
http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2814620.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Jason Chaffee <jc...@ebates.com>.
Well, you have an example of the contextPath being
"com.mycompany.connector.jms" yet your bean example that worked had the
package of "com.mycompany.connector.bean" for the TestBean. Those don't
look the same to me.  From this, it would guess that your contextPath in
the example below is not correct and that it should be
"com.mycompany.connector.bean".  



-----Original Message-----
From: dresden [mailto:isaacvoth@gmail.com] 
Sent: Wednesday, September 08, 2010 2:25 PM
To: users@camel.apache.org
Subject: RE: Solution?? JAXB Unmarshalling - DataFormat error ...
suggestions?


Yes. I have an annotated class in that package that I want to
"unmarshall
into".

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="test")
public class TestBean {
...

Now, it is not an ObjectFactory, but it is annotated. Am I using the
Jaxb
bean correctly?

<route>
	<from uri="amq2:queue:take" />

	<unmarshal>
		<jaxb id="myJaxb" prettyPrint="true"
contextPath="com.mycompany.connector.jms" />
	</unmarshal>

	<bean ref="consumer" />
	<to uri="amq2:queue:taken" />
</route>
-- 
View this message in context:
http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-su
ggestions-tp2814620p2818518.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Mark <ja...@gmail.com>.
JDK 1.5 or 1.6 ?

On 8 September 2010 22:24, dresden <is...@gmail.com> wrote:
>
> Yes. I have an annotated class in that package that I want to "unmarshall
> into".
>
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>
> @XmlRootElement(name="test")
> public class TestBean {
> ...
>
> Now, it is not an ObjectFactory, but it is annotated. Am I using the Jaxb
> bean correctly?
>
> <route>
>        <from uri="amq2:queue:take" />
>
>        <unmarshal>
>                <jaxb id="myJaxb" prettyPrint="true"
> contextPath="com.mycompany.connector.jms" />
>        </unmarshal>
>
>        <bean ref="consumer" />
>        <to uri="amq2:queue:taken" />
> </route>
> --
> View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2818518.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

RE: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by dresden <is...@gmail.com>.
Yes. I have an annotated class in that package that I want to "unmarshall
into".

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="test")
public class TestBean {
...

Now, it is not an ObjectFactory, but it is annotated. Am I using the Jaxb
bean correctly?

<route>
	<from uri="amq2:queue:take" />

	<unmarshal>
		<jaxb id="myJaxb" prettyPrint="true"
contextPath="com.mycompany.connector.jms" />
	</unmarshal>

	<bean ref="consumer" />
	<to uri="amq2:queue:taken" />
</route>
-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2818518.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Jason Chaffee <jc...@ebates.com>.
And all of your jaxb classes are in this package
"com.mycompany.connector.jms"?

-----Original Message-----
From: dresden [mailto:isaacvoth@gmail.com] 
Sent: Wednesday, September 08, 2010 2:10 PM
To: users@camel.apache.org
Subject: Re: Solution?? JAXB Unmarshalling - DataFormat error ...
suggestions?


Thanks for the response.

I am hoping to get this to work from Spring config xml. So my JAXB
Context
is configured like this:


<dataFormats> 
    <jaxb id="myJaxb" prettyPrint="true"
contextPath="com.mycompany.connector.jms"/> 
  </dataFormats> 

I tried specifying both the package and the package and class name. Both
get
the error.

I found a different way to achieve unmarshalling, which I am going to
post
next, but this is concerning as I should be able to get JAXB to work.
-- 
View this message in context:
http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-su
ggestions-tp2814620p2817298.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by Jason Chaffee <jc...@ebates.com>.
Well based on this example and the jaxb contextPath you gave earlier, it
appears they aren't the same package.  If jaxb can't find annotated
classes or an ObjectFactory in the contetPath then you will get the
error you were seeing.

-----Original Message-----
From: dresden [mailto:isaacvoth@gmail.com] 
Sent: Wednesday, September 08, 2010 2:19 PM
To: users@camel.apache.org
Subject: Re: Solution?? JAXB Unmarshalling - DataFormat error ...
suggestions?


I was able to achieve unmarshalling using a different approach. I found
the
suggestion here:

http://stackoverflow.com/questions/2631662/using-apache-camel-how-do-i-u
nmarshal-my-deserialized-object-that-comes-in-throug

My Spring config looks like this:

<route>

	<from uri="amq2:queue:eat" />
	<to
uri="xslt:file:src/com/mycompany/connector/resources/test.xslt" />
	<convertBodyTo type="com.mycompany.connector.bean.TestBean" />

	<bean ref="consumer" />
	<to uri="amq2:queue:eaten" />

</route>

Currently this method is working. My TestBean class is annotated with
JAXB
(XmlRootElement). The consumer bean receives a POJO, not an XML message
or
String. 

However, if anyone has an example of using an explicit Jaxb DataFormat
from
a Spring configuration, that would be great.
-- 
View this message in context:
http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-su
ggestions-tp2814620p2817914.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by dresden <is...@gmail.com>.
I was able to achieve unmarshalling using a different approach. I found the
suggestion here:

http://stackoverflow.com/questions/2631662/using-apache-camel-how-do-i-unmarshal-my-deserialized-object-that-comes-in-throug

My Spring config looks like this:

<route>

	<from uri="amq2:queue:eat" />
	<to uri="xslt:file:src/com/mycompany/connector/resources/test.xslt" />
	<convertBodyTo type="com.mycompany.connector.bean.TestBean" />			
	<bean ref="consumer" />
	<to uri="amq2:queue:eaten" />

</route>

Currently this method is working. My TestBean class is annotated with JAXB
(XmlRootElement). The consumer bean receives a POJO, not an XML message or
String. 

However, if anyone has an example of using an explicit Jaxb DataFormat from
a Spring configuration, that would be great.
-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2817914.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by dresden <is...@gmail.com>.
Thanks for the response.

I am hoping to get this to work from Spring config xml. So my JAXB Context
is configured like this:


<dataFormats> 
    <jaxb id="myJaxb" prettyPrint="true"
contextPath="com.mycompany.connector.jms"/> 
  </dataFormats> 

I tried specifying both the package and the package and class name. Both get
the error.

I found a different way to achieve unmarshalling, which I am going to post
next, but this is concerning as I should be able to get JAXB to work.
-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2817298.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Solution?? JAXB Unmarshalling - DataFormat error ... suggestions?

Posted by dresden <is...@gmail.com>.
I downgraded from 2.4.0 to 2.3.0 and the error seems to go away.

I have no desire to use and older version. If anyone has insight, please
comment.

Now I get a different error. Not sure if this is Camel related or Jaxb.
Again - help appreciated...


org.apache.camel.RuntimeCamelException: java.io.IOException:
"com.mycompany.connector.jms.TestBean" doesnt contain ObjectFactory.class or
jaxb.index
-- 
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-DataFormat-error-suggestions-tp2814620p2815791.html
Sent from the Camel - Users mailing list archive at Nabble.com.