You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dulanov <du...@gmail.com> on 2009/07/12 17:20:36 UTC

JAXB pretty print marshaling

How receive pretty print XML output?

Next solution just output something like ":<?xml version="1.0"
encoding="UTF-8" standalone="yes"?><interplat
xmlns="http://example.com/schema/v1.0"><payload><currencyRates
date="2009-06-02"><rate currency="EUR">43.4875</rate><rate
currency="USD">30.7441</rate></currencyRates>..." 
 
JaxbDataFormat jaxb = new JaxbDataFormat("com.example.canonical.v1");
jaxb.setPrettyPrint(true);
from(SERVICE_IN).to(LOG_URI).multicast(new AggregationStrategy() {

	@Override public Exchange aggregate(Exchange oldExchange, Exchange
newExchange) {
		...
		return oldExchange;
	}
}).to("direct:receiveForEUR",
"direct:receiveForUSD").end().marshal(jaxb).to(LOG_URI);
-- 
View this message in context: http://www.nabble.com/JAXB-pretty-print-marshaling-tp24449564p24449564.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: JAXB pretty print marshaling

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

I just checked the camel-jaxb code and found the the pretty print flag 
is not set to jaxb context. It's a bug of camel-jaxb.
I filled a JIRA[1] for it and will do a quick fix for it.

[1] https://issues.apache.org/activemq/browse/CAMEL-1828

Willem

Claus Ibsen wrote:
> Hi
> 
> If I understand your questions, you cannot get pretty print to work?
> What is your problem more precisely?
> And what version of Camel are you using?
> 
> A good idea is try looking in the camel-jaxb/src/test/java for
> examples how to use marshal/unmarshal data format to/from XML.
> 
> 
> On Sun, Jul 12, 2009 at 5:20 PM, dulanov<du...@gmail.com> wrote:
>> How receive pretty print XML output?
>>
>> Next solution just output something like ":<?xml version="1.0"
>> encoding="UTF-8" standalone="yes"?><interplat
>> xmlns="http://example.com/schema/v1.0"><payload><currencyRates
>> date="2009-06-02"><rate currency="EUR">43.4875</rate><rate
>> currency="USD">30.7441</rate></currencyRates>..."
>>
>> JaxbDataFormat jaxb = new JaxbDataFormat("com.example.canonical.v1");
>> jaxb.setPrettyPrint(true);
>> from(SERVICE_IN).to(LOG_URI).multicast(new AggregationStrategy() {
>>
>>        @Override public Exchange aggregate(Exchange oldExchange, Exchange
>> newExchange) {
>>                ...
>>                return oldExchange;
>>        }
>> }).to("direct:receiveForEUR",
>> "direct:receiveForUSD").end().marshal(jaxb).to(LOG_URI);
>> --
>> View this message in context: http://www.nabble.com/JAXB-pretty-print-marshaling-tp24449564p24449564.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 


Re: JAXB pretty print marshaling

Posted by Dmitry Ulanov <du...@gmail.com>.
I saw this example. And, yes, you are right, I cannot get pretty print to
work. I am using FUSE-Mediation-Router 1.6.1.0 (Camel-1.6.1 is wrapped).

Instead of

"<?xml version="1.0" encoding="UTF-8" standalone="yes"?><interplat xmlns="
http://example.com/schema/v1.0"><payload><currencyRates
date="2009-06-02"><rate currency="EUR">43.4875</rate><rate
currency="USD">30.7441</rate></currencyRates>..."

I would like to have

"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<interplat xmlns="http://exapmple.com/schema/v1.0">
  <payload>
    <currencyRates date="2009-06-02">
      <rate currency="EUR">43.4875</rate>
      <rate currency="USD">30.7441</rate>
    </currencyRates>..."

I tried to use JaxbDataFormat jaxb = new
JaxbDataFormat("com.example.canonical.v1"); jaxb.setPrettyPrint(true); But
it doesn't help.

Full example:

        CBRQueryProcessor processor = new CBRQueryProcessor();
        JaxbDataFormat jaxb = new
JaxbDataFormat("com.example.canonical.v1");
        jaxb.setPrettyPrint(true);
        from(SERVICE_IN).to(LOG_URI).multicast(new AggregationStrategy() {

            @Override public Exchange aggregate(Exchange oldExchange,
Exchange newExchange) {
                List<CurrencyRates> eurRates =
oldExchange.getOut().getBody(Interplat.class).getPayload().getCurrencyRates();
                List<CurrencyRates> usdRates =
newExchange.getOut().getBody(Interplat.class).getPayload().getCurrencyRates();
                for (int i = 0; i < eurRates.size(); i++) {

eurRates.get(i).getRate().add(usdRates.get(i).getRate().get(0));
                }
                return oldExchange;
            }
        }).to("direct:receiveForEUR",
"direct:receiveForUSD").end().marshal(jaxb).to(LOG_URI);
        from("direct:receiveForEUR").bean(processor,
"processEUR").inOut().to("direct:receiveCurrencyRates");
        from("direct:receiveForUSD").bean(processor,
"processUSD").inOut().to("direct:receiveCurrencyRates");
        from("direct:receiveCurrencyRates").pipeline("
http://www.cbr.ru/scripts/XML_dynamic.asp", LOG_URI,
"xslt:to_canonical_v1.xsl", LOG_URI).unmarshal(jaxb);


On Mon, Jul 13, 2009 at 1:59 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> If I understand your questions, you cannot get pretty print to work?
> What is your problem more precisely?
> And what version of Camel are you using?
>
> A good idea is try looking in the camel-jaxb/src/test/java for
> examples how to use marshal/unmarshal data format to/from XML.
>
>
> On Sun, Jul 12, 2009 at 5:20 PM, dulanov<du...@gmail.com> wrote:
> >
> > How receive pretty print XML output?
> >
> > Next solution just output something like ":<?xml version="1.0"
> > encoding="UTF-8" standalone="yes"?><interplat
> > xmlns="http://example.com/schema/v1.0"><payload><currencyRates
> > date="2009-06-02"><rate currency="EUR">43.4875</rate><rate
> > currency="USD">30.7441</rate></currencyRates>..."
> >
> > JaxbDataFormat jaxb = new JaxbDataFormat("com.example.canonical.v1");
> > jaxb.setPrettyPrint(true);
> > from(SERVICE_IN).to(LOG_URI).multicast(new AggregationStrategy() {
> >
> >        @Override public Exchange aggregate(Exchange oldExchange, Exchange
> > newExchange) {
> >                ...
> >                return oldExchange;
> >        }
> > }).to("direct:receiveForEUR",
> > "direct:receiveForUSD").end().marshal(jaxb).to(LOG_URI);
> > --
> > View this message in context:
> http://www.nabble.com/JAXB-pretty-print-marshaling-tp24449564p24449564.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
> >
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Re: JAXB pretty print marshaling

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If I understand your questions, you cannot get pretty print to work?
What is your problem more precisely?
And what version of Camel are you using?

A good idea is try looking in the camel-jaxb/src/test/java for
examples how to use marshal/unmarshal data format to/from XML.


On Sun, Jul 12, 2009 at 5:20 PM, dulanov<du...@gmail.com> wrote:
>
> How receive pretty print XML output?
>
> Next solution just output something like ":<?xml version="1.0"
> encoding="UTF-8" standalone="yes"?><interplat
> xmlns="http://example.com/schema/v1.0"><payload><currencyRates
> date="2009-06-02"><rate currency="EUR">43.4875</rate><rate
> currency="USD">30.7441</rate></currencyRates>..."
>
> JaxbDataFormat jaxb = new JaxbDataFormat("com.example.canonical.v1");
> jaxb.setPrettyPrint(true);
> from(SERVICE_IN).to(LOG_URI).multicast(new AggregationStrategy() {
>
>        @Override public Exchange aggregate(Exchange oldExchange, Exchange
> newExchange) {
>                ...
>                return oldExchange;
>        }
> }).to("direct:receiveForEUR",
> "direct:receiveForUSD").end().marshal(jaxb).to(LOG_URI);
> --
> View this message in context: http://www.nabble.com/JAXB-pretty-print-marshaling-tp24449564p24449564.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus