Thanks for the help. :)
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: Monday, June 11, 2012 5:28 PM
To: [email protected]
Cc: Abhishek Sharma
Subject: Re: How to use XSD file with cxf
Hi Abhishek
On 09/06/12 07:40, Abhishek Sharma wrote:
> I Appreciate your efforts in getting it done and sharing the same :)
>
> One Q related to MappedNamespaceConvention provider:
>
> I used Jackson provider explicitly as I was getting some problem with the
> default json provider in CXF as it was creating an unnecessary wrapper for
> the root element.
>
> So when you publish your schema the json may or may not contain additional
> wrapper.
>
> Which one is syntactically correct as different parsers have different
> behaviors?
>
> For e.g.:
> Sample XML:
>
> <MMTHotelAvailRequest>
> <POS>
> <Requestor type="B2BAgent" idContext="FPH" id="AFF0987" channel="B2C"/>
> <Source iSOCurrency="INR"/>
> </POS>
> </MMTHotelAvailRequest>
>
> JSON1 (thru CXF):
> {
> "MMTHotelAvailRequest": {
> "POS": {
> "Requestor": {
> "type": "B2BAgent",
> "idContext": "FPH",
> "id": "AFF0987",
> "channel": "B2C"
> },
> "Source": { "iSOCurrency": "INR" }
> }
> }
> }
>
> JSON2 (thru Jackson):
> {
> "POS" : {
> "Requestor" : {
> "channel" : "Mobile",
> "id" : "AFF0987",
> "idContext" : "MMT",
> "type" : "MobileAgent"
> },
> "Source" : {"iSOCurrency" : "INR"
> }
> }
> }
Jettison is JAXB-driven so it may not be able to produce optimal JSON
sequences; despite that, one advantage of being JAXB-driven is that it
is quite configurable. Modifying, validating and restricting JSON
sequences are easy with Jettison. One option is to configure it to drop
the "POS" element, see
http://cxf.apache.org/docs/transformationfeature.html#TransformationFeature-Droppingoutputandinputelements
Use an outDropElements property
HTH, Sergey
>
> Thanks,
> Abhishek
>
> -----Original Message-----
> From: amathewcxf [mailto:[email protected]]
> Sent: Saturday, June 09, 2012 12:02 AM
> To: [email protected]
> Subject: RE: How to use XSD file with cxf
>
> Thank you Abhishek for all the help. I have it all working with WebClient&
> JSON as the type.
>
> Below is my final client code (I am posting so it may help others in the
> forum):
>
> try {
> WebClient webClient =
> WebClient.create("https://myremotws.com:18443/availability/v1?eventId=1146",
> Collections.singletonList(new MappedNamespaceConvention(new
> Configuration())));
> String authorizationHeader = "Basic " +
> org.apache.cxf.common.util.Base64Utility.encode("myusername:mypassword".getBytes());
> webClient.header("Authorization", authorizationHeader);
> webClient.accept(MediaType.APPLICATION_JSON);
>
> // This section of code will make sure client is
> treated as a Trusted
> source by remote service
> // and this is needed only if the remote server doesnt
> have a valid
> certificate
> HTTPConduit conduit =
> WebClient.getConfig(webClient).getHttpConduit();
>
> conduit.setTlsClientParameters(getConfiguredClientSSLParms(webClient));
>
> // This will make the exact remote webservice all to
> get the response
> // The response data will be JSON String and the above
> provider
> (MappedNamespaceConvention) which
> // we registered will take care of all JSON parsing to
> our JAXB classes.
> Availability avail = webClient.get(Availability.class);
>
> } catch (Throwable e) {
>
> }
>
> Thanks
> Anil Mathew
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-use-XSD-file-with-cxf-tp5708311p5709415.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com