That generated grammar where one schema imports the type from the
schema without a target namespace looks
strange, guess technically it is valid, but it is likely something in
your resource class, RequestWrapper or in package-info.java is
confusing the schema generator.

Anyway, have those two schemas merged into a single schema, and then
check the server log, if the schema is not found or can not be loaded
then a warning should be displayed...

Cheers, Sergey

On Thu, May 5, 2011 at 8:01 PM, yhu <[email protected]> wrote:
> Ok, so I must use the explicit xsd file validation. I try it, but it does not
> work for me.
>
> Using the same classes I used in another question:
>
> @Path("/luckynumbers")
> public class LuckyNumbers {
>
>
>    @POST
>    @Path("/addRequest")
>    @Produces({MediaType.APPLICATION_XML})
>    @Consumes({MediaType.APPLICATION_XML})
>    public String addRequest(RequestWrapper rw) {
>        System.out.println(rw);
>        return rw.toString();
>    }
>
>   @XmlRootElement(name="requestWrapper", namespace="http://luckynumbers";)
>    public static class RequestWrapper {
>        List<String> theList = new ArrayList();
>        String theRequest;
>
>
>       @XmlElement (name="listItem")
>       @XmlElementWrapper
>        public Collection<String> getTheList() {
>            return theList;
>        }
>
>        public void setTheList(List<String> theList) {
>            this.theList = theList;
>        }
>        @XmlAttribute(required=true)
>        public String getTheRequest() {
>            return theRequest;
>        }
>
>        public void setTheRequest(String theRequest) {
>            this.theRequest = theRequest;
>        }
>
>       @Override
>       public String toString() {
>           return "RequestWrapper{" +
>                   "theList=" + theList +
>                   ", theRequest='" + theRequest + '\'' +
>                   '}';
>       }
>   }
> }
>
> The xsd file (the content is copy from WADL, saved as
> /WEB-INF/schemas/LuckyNumbersRest.xsd. theRequest is required attribute):
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> attributeFormDefault="unqualified" elementFormDefault="unqualified">
>    <xs:complexType name="requestWrapper">
>        <xs:sequence>
>            <xs:element minOccurs="0" name="theList">
>                <xs:complexType>
>                    <xs:sequence>
>                        <xs:element maxOccurs="unbounded" minOccurs="0"
> name="listItem" type="xs:string"/>
>                    </xs:sequence>
>                </xs:complexType>
>            </xs:element>
>        </xs:sequence>
>        <xs:attribute name="theRequest" type="xs:string" use="required"/>
>    </xs:complexType>
> </xs:schema>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> xmlns="http://luckynumbers"; attributeFormDefault="unqualified"
> elementFormDefault="unqualified" targetNamespace="http://luckynumbers";>
>    <xs:import namespace=""/>
>    <xs:element name="requestWrapper" type="requestWrapper"/>
> </xs:schema>
>
> The jaxrs configure in beans.xml:
>
>    <jaxrs:server id="luckyNumbersRest"
>                  serviceClass="prototype.rest.LuckyNumbers"
>                  address="/LuckyNumbersRest">
>
>        <jaxrs:providers>
>          <ref bean="jaxbProvider" />
>        </jaxrs:providers>
>
>    </jaxrs:server>
>
>    <bean id="jaxbProvider"
> class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
>        <property name="schemaHandler" ref="schemaHolder"/>
>        <property name="marshallerProperties" ref="propertiesMap"/>
>    </bean>
>
>    <bean id="schemaHolder"
> class="org.apache.cxf.jaxrs.utils.schemas.SchemaHandler">
>       <property name="schemas" ref="theSchemas"/>
>    </bean>
>
>    <util:list id="theSchemas">
>      <value>classpath:/WEB-INF/schemas/LuckyNumbersRest.xsd</value>
>    </util:list>
>
>    <util:map id="propertiesMap">
>        <entry key="jaxb.formatted.output">
>            <value type="java.lang.Boolean">true</value>
>        </entry>
>    </util:map>
>
>
> Post XML data <prefix1:requestWrapper
> xmlns:prefix1="http://luckynumbers";><theList><listItem>item1</listItem></theList></prefix1:requestWrapper>
> without theRequest attribute, I expect the JAXB error like "theRequest must
> appear on element requestWrapper", but this not happens, and the XML
> response returns successfully: RequestWrapper{theList=[item1],
> theRequest='null'}
>
> Could you advice what may make the validation not work? The xsd file not
> good, the jaxbprovider not configured well, others?
>
> Thanks.
>
>
> --
> View this message in context: 
> http://cxf.547215.n5.nabble.com/How-to-enable-xml-schema-validation-for-CXF-Restful-web-service-tp4371287p4373720.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Reply via email to