Hi

it appears to be quite an interesting case that may lead us to doing a minor enhancement,

On 01/12/11 12:30, laksu wrote:
Hi Sergey, thanks for the reply.
Excel has a concept called an "XML Mapping". Upon connecting to my RS method
I get this
"The specified XML source does not refer to a schema. Excel will create a
schema based on the source XML data"

It appears Excel expects something like this:
<products xmlns="http://myproducts";
  xsi:schemaLocation="
http://myproducts http://localhost:8080/mywebapp/schemas/products.xsd";>
<!-- products data -->
</products>

Can you please confirm it by importing an xml document locally and with xsi:schemaLocation pointing to a local file system, ex, "file:/C:/schemas/products.xsd' ? Or may be check some of their tech notes...

would automatically pick it up. That would be nice to have but I would be
even fine with supplying the XSD manually to Excel. Essentially at this
stage I am interested in generating the XSD automatically and supplying it
to Excel would be another thing.
What I understand from your reply is if I had been returning a single object
rather than a collection, then it would be possible to generate the schema
definition. I think this does not work right out of the box and I should be
doing something for that as I have another method that is returning a single
object but it is returning a similar plain XML file with no reference to any
XSD.

If you wrap it in a single bean then you can query the service for a WADL instance (using a ?_wadl query) and that WADL will include the generated schema, WADL itself will be of no use in this particular case but you can copy the generated schema and reuse it

Assuming Excel does expect a xsi:schemaLocation set, I think what you need to do is to get the schema created (manually or copy it from the generated WADL) and save it to say /schemas/products.xsd relative to the webapp root.

Next, configure JAXBElementProvider as shown here:

http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-ConfiguringJAXBprovider, set a property like this
<entry key="jaxb.schemaLocation" "http://myproducts /schemas/products.xsd"/>

Now, if Excel will manage to resolve this relative "/schemas/products.xsd" against the original request URI then things are good.

If not then you can confirm things are working by hardcoding an absolute location:

<entry key="jaxb.schemaLocation" "http://myproducts http://localhost:8080/mywebapp/schemas/products.xsd"/>

but to fix it properly, we'd need to probably introduce a SchemaLocation annotation and may be manage some substitution there, similarly to a would be XMLInstruction annotation which Christian said would be handy to have;

Extending JAXBElementProvider will let you manage the absolute URI for this schemaLocation easily enough too, but perhaps @SchemaLocation would be even easier

Let me know please how it works
Cheers, Sergey


--
View this message in context: 
http://cxf.547215.n5.nabble.com/automatic-schema-generation-for-a-RS-method-tp5033048p5038521.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

Reply via email to