You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by james555 <lu...@gmx.net> on 2014/05/19 16:27:18 UTC

JAXB-Unmarshalling of soap xml including schema validation

Hello,

is there an appropriate way to unmarshal soap-xml with jaxb using
SoapJaxbDataFormat including xsd schema validation (camel 2.13.0) ? 

e.g. 

...
SoapJaxbDataFormat soapJaxbDataFormat = new SoapJaxbDataFormat();
soapJaxbDataFormat.setContextPath("foo.bar.jaxb");
soapJaxbDataFormat.setEncoding("UTF-8");
soapJaxbDataFormat.setSchema("classpath:person.xsd");		
...    

since there is no setSchema-Method on SoapJaxbDataFormat to activate schema
validation ? (I don't want to use cxf) 

	Am I missing something ?
	
	
		james





--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by akoufoudakis <ak...@gmail.com>.
Hello, James!

Glad that it partially worked...
You could just unmarshall it buy SoapJaxb... and then to validate it inside
a processor or a predicate.
It is an artisan solution and more a workaround. But, may be, it will save
you some time.



--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751340.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by Willem Jiang <wi...@gmail.com>.
You can create the SoapJaxbDataFormat directly inside your RouteBuilder if you like.

I’m going to add setSchema method to the org.apache.camel.model.dataformat.SoapJaxbDataFormat which could be used as DataFormatDefinition in DSL.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 21, 2014 at 3:49:40 PM, james555 (luke333@gmx.net) wrote:
>  
> Hi Willem,
>  
> a little bit confusing, but now I got it. In my code I used "import
> org.apache.camel.model.dataformat.SoapJaxbDataFormat;" where setSchema is an  
> invalid method. Compared with your testcase "import
> org.apache.camel.dataformat.soap.SoapJaxbDataFormat;" with setSchema method  
> is used, thanks !
>  
> Sideeffect of the two existing SoapJaxbDataFormat classes:
> I define my SoapJaxbDataFormat in a servlet scenario with a
> CamelContextLifecycle. Since
> "org.apache.camel.dataformat.soap.SoapJaxbDataFormat" is not a
> "DataFormatDefinition" I can't use
>  
> e.g.
> camelContext.getDataFormats().put("soapJaxbDataFormat", soapJaxbDataFormat);  
>  
> to access the SoapJaxbDataFormat in a RouteBuilder comfortably (Compiler
> says: "The method put(String, DataFormatDefinition) in the type
> Map is not applicable for the arguments
> (String, SoapJaxbDataFormat)". Is that meant to be ? As a workaround I now
> have to use the Registry with bean binding:
>  
> e.g.
> registry.bind("soapJaxbDataFormat", soapJaxbDataFormat);
>  
> Is there a better way to access SoapJaxbDataFormat ?
>  
> big thanks !
>  
> james
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751406.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by james555 <lu...@gmx.net>.
Hi Willem,

a little bit confusing, but now I got it. In my code I used "import
org.apache.camel.model.dataformat.SoapJaxbDataFormat;" where setSchema is an
invalid method. Compared with your testcase "import
org.apache.camel.dataformat.soap.SoapJaxbDataFormat;" with setSchema method
is used, thanks !

Sideeffect of the two existing SoapJaxbDataFormat classes:
I define my SoapJaxbDataFormat in a servlet scenario with a
CamelContextLifecycle. Since
"org.apache.camel.dataformat.soap.SoapJaxbDataFormat" is not a
"DataFormatDefinition" I can't use

e.g.
camelContext.getDataFormats().put("soapJaxbDataFormat", soapJaxbDataFormat);

to access the SoapJaxbDataFormat in a RouteBuilder comfortably (Compiler
says: "The method put(String, DataFormatDefinition) in the type
Map<String,DataFormatDefinition> is not applicable for the arguments
(String, SoapJaxbDataFormat)". Is that meant to be ? As a workaround I now
have to use the Registry with bean binding: 

e.g.
registry.bind("soapJaxbDataFormat", soapJaxbDataFormat);

Is there a better way to access SoapJaxbDataFormat ?

	big thanks !
	
		james






    	



--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751406.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

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

I just updated a unit test[1] which shows you how to set up the schema,

BTW, the package name of the SoapJaxbDataFormat is org.apache.camel.dataformat.soap.

[1] http://git-wip-us.apache.org/repos/asf/camel/diff/8ea12ce7 

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 20, 2014 at 5:36:14 PM, james555 (luke333@gmx.net) wrote:
> Hi Willem,
>  
> yes, camel-soap and camel-jaxb are defined in pom.xml. Both have version
> 2.13.0, also in the generated war file under WEB-INF/lib
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751339.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by james555 <lu...@gmx.net>.
Hi Willem,

yes, camel-soap and camel-jaxb are defined in pom.xml. Both have version
2.13.0, also in the generated war file under WEB-INF/lib



--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751339.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by Willem Jiang <wi...@gmail.com>.
Can you check if  camel-jaxb and camel-soap jar in you class path are the same version?

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 20, 2014 at 3:27:16 PM, james555 (luke333@gmx.net) wrote:
> Hello Willem, hello akoufoudakis,
>  
> thanks for your both answers! When using method setSchema Compiler says "the
> method setSchema(String) is undefined for the type SoapJaxbDataFormat".
> Casting does also fail.
>  
> trying akoufoudakis idea seems to work partly. After sending soap-xml
> validator initially warns:
>  
> "Cannot find the declaration of element 'soapenv:Envelope'"
>  
> But after that the real payload validation message follows like expected:
> "Invalid content was found starting with element 'B-ELEMENT'. One of
> '{A-ELEMENT}' is expected."
>  
> Perhaps I have to extract soap-body payload manually or filter validation
> messages ?
>  
>  
> james
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751332.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  


Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by james555 <lu...@gmx.net>.
Hello Willem, hello akoufoudakis,

thanks for your both answers! When using method setSchema Compiler says "the
method setSchema(String) is undefined for the type SoapJaxbDataFormat".
Casting does also fail.

trying akoufoudakis idea seems to work partly. After sending soap-xml
validator initially warns: 

"Cannot find the declaration of element 'soapenv:Envelope'" 

But after that the real payload validation message follows like expected:
"Invalid content was found starting with element 'B-ELEMENT'. One of
'{A-ELEMENT}' is expected."

Perhaps I have to extract soap-body payload manually or filter validation
messages ?

	
		james





--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751332.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by akoufoudakis <ak...@gmail.com>.
Hello, James!

Did you try to do the following:
from(src).to("validator:[your_xsd_file]").unmarshal().
...

?




--
View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290p5751291.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JAXB-Unmarshalling of soap xml including schema validation

Posted by Willem Jiang <wi...@gmail.com>.
SoapJaxbDataFormat extends the JaxbDataFormat which has the setSchema method, you should be able to set the schema as you just did.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 19, 2014 at 10:33:26 PM, james555 (luke333@gmx.net) wrote:
> Hello,
>  
> is there an appropriate way to unmarshal soap-xml with jaxb using
> SoapJaxbDataFormat including xsd schema validation (camel 2.13.0) ?
>  
> e.g.
>  
> ...
> SoapJaxbDataFormat soapJaxbDataFormat = new SoapJaxbDataFormat();
> soapJaxbDataFormat.setContextPath("foo.bar.jaxb");
> soapJaxbDataFormat.setEncoding("UTF-8");
> soapJaxbDataFormat.setSchema("classpath:person.xsd");
> ...
>  
> since there is no setSchema-Method on SoapJaxbDataFormat to activate schema
> validation ? (I don't want to use cxf)
>  
> Am I missing something ?
>  
>  
> james
>  
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/JAXB-Unmarshalling-of-soap-xml-including-schema-validation-tp5751290.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>