You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by nikosdim <ni...@gmail.com> on 2014/12/02 17:51:42 UTC

Validate JAXB Object with xsd schema

Hi 

I have written a JAXRS service with accepts xml as input in the body of a
POST request. The xml is converted to an JAXB Object automatically. Below is
my code and configuration

Using CXF 3.0.1, tomcat 7.0.42, java 1.7.0_55

*Service*
@Path("incident")
public class CreateIncident {
	@POST
	@Consumes({ MediaType.APPLICATION_XML})
	public Response createIncident(Incident incident) {
			//code
	}
}

*JAXB Object*
@XmlRootElement(name = "incident")
@XmlAccessorType(XmlAccessType.FIELD)
public class Incident extends Event {
	public Incident() {
		super("incident");
	}
	
	private String importProfile;
	
	public String getImportProfile() {
		return importProfile;
	}

	public void setImportProfile(String importProfile) {
		this.importProfile = importProfile;
	}
}

*Config*
<jaxrs:server address="/">
		<jaxrs:schemaLocations>
			<jaxrs:schemaLocation>classpath:xsd/incident.xsd</jaxrs:schemaLocation>
		</jaxrs:schemaLocations>
		<jaxrs:serviceBeans>
			<bean class="com.ba.sysman.services.events.CreateIncident"></bean>
		</jaxrs:serviceBeans>
		<jaxrs:features>
			<cxf:logging/>
		</jaxrs:features>
</jaxrs:server>

When I am sending a POST request to the service with an xml that does not
conform with the xsd defined in the jaxrs:schemaLocation tag the Incident
object is populated with no xsd errors or exceptions.

What is wrong with my configuration?

Thanks



--
View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Validate JAXB Object with xsd schema

Posted by Sergey Beryozkin <sb...@gmail.com>.
I've experimented a bit locally, setting the schema location property 
without registering the providers explicitly works for me.

I'm not sure why you had no validation errors reported after you saw the 
WARNING messages (related to loading the schema resources) gone.

Can you remove the provider registration block from beans.xml and put 
few breakpoints in a (default) JAXBElementProvider in methods where 
Schema is used ? The fact the WARNING messages have gone clearly 
indicates that a schema resource has been loaded - it is difficult to 
figure out why the actual validation does not work afterwards (unless 
the JAXB provider is explicitly  registered).

So either debug (simply download a CXF source) and let me know what 
you've found or create a test case and I'll investigate further
Sergey

On 08/12/14 14:48, Sergey Beryozkin wrote:
> I'll have a look why it does not work without a registered provider,
> might be a regression (FYI, the same would work by just registering a
> CXF JAXB providder without extending it - tat was only needed to confirm
> a custom Schema is available).
>
> Not 100% sure about the actual validation issue (it is not a CXF issue)
> in this specific case it appears to be the XML instance is not qualified
> with a namespace
>
> Cheers, Sergey
> On 08/12/14 14:30, nikosdim wrote:
>> Hi
>>
>> Here is the update
>>
>> I registered the provider
>> <bean id="jaxbElementProvider"
>> class="com.ba.sysman.providers.MyJAXBElementProvider"></bean>
>>
>> and now it goes through validation of the xsd. Without the provider it
>> doesn't and I have not put any logic in the privider. Just overrided
>> getSchema(Class<?> cls) and put a breakpoint to see if it is called.
>> Is this a bug with the spring configuration of cxf ?
>>
>>
>> After having registered the provider I send a request to the service
>> with an
>> xml but I get this
>>
>> *JAXBException occurred : cvc-elt.1: Cannot find the declaration of
>> element
>> 'incident'.. cvc-elt.1: Cannot find the declaration of element
>> 'incident'..
>> *
>>
>>
>>
>> *My xml:*
>>
>> <incident>
>>     <eventTitle>Test Title from wrapper</eventTitle>
>>     <eventDescription>Test description from BAwrapper</eventDescription>
>>     <affectedUserName>U88sdfs888</affectedUserName>
>>          <affectedUserTelephone>+440-98772345nj</affectedUserTelephone>
>>     <reportingUserName>U88888</reportingUserName>
>>     <eventCategoryName>INCIDENT</eventCategoryName>
>>     <eventSeriousness>4</eventSeriousness>
>>     <serviceDepartmentName>NETTECHS</serviceDepartmentName>
>>     <affectedServiceName>ASSYST</affectedServiceName>
>>     <affectedAssetName>LXVIRT910</affectedAssetName>
>> </incident>
>>
>>
>> *My xsd:*
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsd:schema
>>     xmlns="http://www.mydomain.com/schema/Wrapper/incident"
>>     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>     targetNamespace="http://www.mydomain.com/schema/Wrapper/incident"
>>     elementFormDefault="qualified">
>>
>>     <xsd:element name="incident">
>>         <xsd:complexType>
>>             <xsd:sequence>
>>                 <xsd:element name="eventTitle">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:minLength value="1"></xsd:minLength>
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="eventDescription">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:minLength value="1"></xsd:minLength>
>>                             <xsd:maxLength value="890"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="affectedUserName">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>s
>>                 </xsd:element>
>>                 <xsd:element
>>                     name="affectedUserTelephone"
>>                     minOccurs="0">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">s
>>                             <xsd:maxLength value="30"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element
>>                     name="reportingUserName"
>>                     minOccurs="0">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="eventCategoryName">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="eventSeriousness">
>>                     <xsd:simpleType>
>>                         <xsd:union memberTypes="empty">
>>                             <xsd:simpleType>
>>                                 <xsd:restriction base="xsd:integer">
>>                                     <xsd:pattern
>> value="[1|2|3|4]"></xsd:pattern>
>>                                 </xsd:restriction>
>>                             </xsd:simpleType>
>>                         </xsd:union>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="serviceDepartmentName">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="15"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="affectedServiceName">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element name="affectedAssetName">
>>                     <xsd:simpleType>
>>                         <xsd:restriction base="xsd:string">
>>                             <xsd:maxLength value="254"></xsd:maxLength>
>>                         </xsd:restriction>
>>                     </xsd:simpleType>
>>                 </xsd:element>
>>                 <xsd:element
>>                     name="attachments"
>>                     minOccurs="0">
>>                     <xsd:complexType>
>>                         <xsd:sequence maxOccurs="10">
>>                             <xsd:element name="attachment">
>>                                 <xsd:complexType>
>>                                     <xsd:sequence>
>>                                         <xsd:element
>>                                             name="name"
>>
>> type="xsd:string"></xsd:element>
>>                                         <xsd:element
>>                                             name="description"
>>
>> type="xsd:string"></xsd:element>
>>                                         <xsd:element
>>                                             name="fileName"
>>
>> type="xsd:string"></xsd:element>
>>                                         <xsd:element
>>                                             name="fileExtension"
>>                                             type="xsd:string"
>>                                             default="txt"></xsd:element>
>>                                         <xsd:element
>>                                             name="binary"
>>
>> type="xsd:base64Binary"></xsd:element>
>>                                     </xsd:sequence>
>>                                 </xsd:complexType>
>>                             </xsd:element>
>>                         </xsd:sequence>
>>                     </xsd:complexType>
>>                 </xsd:element>
>>             </xsd:sequence>
>>         </xsd:complexType>
>>     </xsd:element>
>>     <xsd:simpleType name="empty">
>>         <xsd:restriction base="xsd:string">
>>             <xsd:length value="0"></xsd:length>
>>         </xsd:restriction>
>>     </xsd:simpleType>
>> </xsd:schema>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783p5752054.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>


OAuth2 AccessTokenValidator interface change

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I've updated OAuth2 AccessTokenValidator interface to accept an extra 
parameter, a multivalued map of properties. This change has been done on 
the 3.1.0-SNAPSHOT trunk only.
It is needed for the custom token validators be capable of validating a 
token if the validation input requires some extra properties in addition 
to those found in HTTP Authorization header (client ip address, custom 
headers, URI properties, etc). The interface already accepts 
MessageContext which may be sufficient when extra properties are 
required in a local validation case but it does not work if RS (resource 
server) and AS (Authorization Server) are not collocated.

The reason I'm sending this email to the users list is that I'm keen to 
push this change to CXF 3.0.4-SNAPSHOT (but not to CXF 2.7.15-SNAPSHOT) 
and would like to ask: has someone working with CXF OAuth2 implemented a 
custom AccessTokenValidator and works with CXF 3.0.0-3.0.3 ? Let me know 
please

Thanks, Sergey



[1] 
https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AccessTokenValidator.java

Re: Validate JAXB Object with xsd schema

Posted by Sergey Beryozkin <sb...@gmail.com>.
I'll have a look why it does not work without a registered provider, 
might be a regression (FYI, the same would work by just registering a 
CXF JAXB providder without extending it - tat was only needed to confirm 
a custom Schema is available).

Not 100% sure about the actual validation issue (it is not a CXF issue) 
in this specific case it appears to be the XML instance is not qualified 
with a namespace

Cheers, Sergey
On 08/12/14 14:30, nikosdim wrote:
> Hi
>
> Here is the update
>
> I registered the provider
> <bean id="jaxbElementProvider"
> class="com.ba.sysman.providers.MyJAXBElementProvider"></bean>
>
> and now it goes through validation of the xsd. Without the provider it
> doesn't and I have not put any logic in the privider. Just overrided
> getSchema(Class<?> cls) and put a breakpoint to see if it is called.
> Is this a bug with the spring configuration of cxf ?
>
>
> After having registered the provider I send a request to the service with an
> xml but I get this
>
> *JAXBException occurred : cvc-elt.1: Cannot find the declaration of element
> 'incident'.. cvc-elt.1: Cannot find the declaration of element 'incident'..
> *
>
>
>
> *My xml:*
>
> <incident>
> 	<eventTitle>Test Title from wrapper</eventTitle>
> 	<eventDescription>Test description from BAwrapper</eventDescription>
> 	<affectedUserName>U88sdfs888</affectedUserName>
>          <affectedUserTelephone>+440-98772345nj</affectedUserTelephone>
> 	<reportingUserName>U88888</reportingUserName>
> 	<eventCategoryName>INCIDENT</eventCategoryName>
> 	<eventSeriousness>4</eventSeriousness>
> 	<serviceDepartmentName>NETTECHS</serviceDepartmentName>
> 	<affectedServiceName>ASSYST</affectedServiceName>
> 	<affectedAssetName>LXVIRT910</affectedAssetName>
> </incident>
>
>
> *My xsd:*
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> 	xmlns="http://www.mydomain.com/schema/Wrapper/incident"
> 	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> 	targetNamespace="http://www.mydomain.com/schema/Wrapper/incident"
> 	elementFormDefault="qualified">
>
> 	<xsd:element name="incident">
> 		<xsd:complexType>
> 			<xsd:sequence>
> 				<xsd:element name="eventTitle">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:minLength value="1"></xsd:minLength>
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="eventDescription">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:minLength value="1"></xsd:minLength>
> 							<xsd:maxLength value="890"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="affectedUserName">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element
> 					name="affectedUserTelephone"
> 					minOccurs="0">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="30"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element
> 					name="reportingUserName"
> 					minOccurs="0">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="eventCategoryName">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="eventSeriousness">
> 					<xsd:simpleType>
> 						<xsd:union memberTypes="empty">
> 							<xsd:simpleType>
> 								<xsd:restriction base="xsd:integer">
> 									<xsd:pattern value="[1|2|3|4]"></xsd:pattern>
> 								</xsd:restriction>
> 							</xsd:simpleType>
> 						</xsd:union>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="serviceDepartmentName">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="15"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="affectedServiceName">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element name="affectedAssetName">
> 					<xsd:simpleType>
> 						<xsd:restriction base="xsd:string">
> 							<xsd:maxLength value="254"></xsd:maxLength>
> 						</xsd:restriction>
> 					</xsd:simpleType>
> 				</xsd:element>
> 				<xsd:element
> 					name="attachments"
> 					minOccurs="0">
> 					<xsd:complexType>
> 						<xsd:sequence maxOccurs="10">
> 							<xsd:element name="attachment">
> 								<xsd:complexType>
> 									<xsd:sequence>
> 										<xsd:element
> 											name="name"
> 											type="xsd:string"></xsd:element>
> 										<xsd:element
> 											name="description"
> 											type="xsd:string"></xsd:element>
> 										<xsd:element
> 											name="fileName"
> 											type="xsd:string"></xsd:element>
> 										<xsd:element
> 											name="fileExtension"
> 											type="xsd:string"
> 											default="txt"></xsd:element>
> 										<xsd:element
> 											name="binary"
> 											type="xsd:base64Binary"></xsd:element>
> 									</xsd:sequence>
> 								</xsd:complexType>
> 							</xsd:element>
> 						</xsd:sequence>
> 					</xsd:complexType>
> 				</xsd:element>
> 			</xsd:sequence>
> 		</xsd:complexType>
> 	</xsd:element>
> 	<xsd:simpleType name="empty">
> 		<xsd:restriction base="xsd:string">
> 			<xsd:length value="0"></xsd:length>
> 		</xsd:restriction>
> 	</xsd:simpleType>
> </xsd:schema>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783p5752054.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

Re: Validate JAXB Object with xsd schema

Posted by nikosdim <ni...@gmail.com>.
Hi 

Here is the update

I registered the provider 
<bean id="jaxbElementProvider"
class="com.ba.sysman.providers.MyJAXBElementProvider"></bean>

and now it goes through validation of the xsd. Without the provider it
doesn't and I have not put any logic in the privider. Just overrided
getSchema(Class<?> cls) and put a breakpoint to see if it is called.
Is this a bug with the spring configuration of cxf ? 


After having registered the provider I send a request to the service with an
xml but I get this

*JAXBException occurred : cvc-elt.1: Cannot find the declaration of element
'incident'.. cvc-elt.1: Cannot find the declaration of element 'incident'..
*



*My xml:*

<incident>
	<eventTitle>Test Title from wrapper</eventTitle>
	<eventDescription>Test description from BAwrapper</eventDescription>
	<affectedUserName>U88sdfs888</affectedUserName>
        <affectedUserTelephone>+440-98772345nj</affectedUserTelephone>
	<reportingUserName>U88888</reportingUserName>
	<eventCategoryName>INCIDENT</eventCategoryName>
	<eventSeriousness>4</eventSeriousness>
	<serviceDepartmentName>NETTECHS</serviceDepartmentName>
	<affectedServiceName>ASSYST</affectedServiceName>
	<affectedAssetName>LXVIRT910</affectedAssetName>
</incident>


*My xsd:*
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
	xmlns="http://www.mydomain.com/schema/Wrapper/incident"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://www.mydomain.com/schema/Wrapper/incident"
	elementFormDefault="qualified">

	<xsd:element name="incident">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="eventTitle">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:minLength value="1"></xsd:minLength>
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="eventDescription">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:minLength value="1"></xsd:minLength>
							<xsd:maxLength value="890"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="affectedUserName">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element
					name="affectedUserTelephone"
					minOccurs="0">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="30"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element
					name="reportingUserName"
					minOccurs="0">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="eventCategoryName">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="eventSeriousness">
					<xsd:simpleType>
						<xsd:union memberTypes="empty">
							<xsd:simpleType>
								<xsd:restriction base="xsd:integer">
									<xsd:pattern value="[1|2|3|4]"></xsd:pattern>
								</xsd:restriction>
							</xsd:simpleType>
						</xsd:union>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="serviceDepartmentName">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="15"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="affectedServiceName">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element name="affectedAssetName">
					<xsd:simpleType>
						<xsd:restriction base="xsd:string">
							<xsd:maxLength value="254"></xsd:maxLength>
						</xsd:restriction>
					</xsd:simpleType>
				</xsd:element>
				<xsd:element
					name="attachments"
					minOccurs="0">
					<xsd:complexType>
						<xsd:sequence maxOccurs="10">
							<xsd:element name="attachment">
								<xsd:complexType>
									<xsd:sequence>
										<xsd:element
											name="name"
											type="xsd:string"></xsd:element>
										<xsd:element
											name="description"
											type="xsd:string"></xsd:element>
										<xsd:element
											name="fileName"
											type="xsd:string"></xsd:element>
										<xsd:element
											name="fileExtension"
											type="xsd:string"
											default="txt"></xsd:element>
										<xsd:element
											name="binary"
											type="xsd:base64Binary"></xsd:element>
									</xsd:sequence>
								</xsd:complexType>
							</xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:simpleType name="empty">
		<xsd:restriction base="xsd:string">
			<xsd:length value="0"></xsd:length>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>




--
View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783p5752054.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Validate JAXB Object with xsd schema

Posted by Sergey Beryozkin <sb...@gmail.com>.
Can you temporarily register a custom CXF JAXBElementProvider extension 
(as a provider) and override its getSchema(Class) method and check if it 
is called ?

A simpler option is to set the schema locations property directly on 
JAXBElementProvider, there was an issue long time ago when the schem,a 
locations property was not set on the provider if it was configured the 
way you do it now but I believe it was fixed...

I guess there's also a way to configure JAXB or Xerces to log the schema 
validation process

You can get the CXF source and put a breakpoint in CXF JAXRS 
AbstractJaxbProvider in the code where Unmarshaller is created to 
confirm the schema is activated

Cheers, Sergey
On 03/12/14 10:06, nikosdim wrote:
> Yes, you are right, there were warnings which i didn't see.
> I changed my configuration to
> <jaxrs:schemaLocation>classpath:../../xsd/incident.xsd</jaxrs:schemaLocation>
> and WARINGS are gone but still when I send an invalid xml, the JAXB object
> is getting created without errors or exceptions.
>
> How can I check if the xml input is checked against the xsd? What am I
> suppose to get back when an invalid xml is given?
>
> My project structure is shown below.
>
> --webapps
>      |--MyProject
>          |--WEB-INF
>              |--classes/
>              |--beans.xml
>              |--web.xml
>          |--xsd
>              |--incident.xsd
>
>
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783p5751833.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>


Re: Validate JAXB Object with xsd schema

Posted by nikosdim <ni...@gmail.com>.
Yes, you are right, there were warnings which i didn't see. 
I changed my configuration to 
<jaxrs:schemaLocation>classpath:../../xsd/incident.xsd</jaxrs:schemaLocation>
and WARINGS are gone but still when I send an invalid xml, the JAXB object
is getting created without errors or exceptions. 

How can I check if the xml input is checked against the xsd? What am I
suppose to get back when an invalid xml is given?

My project structure is shown below. 

--webapps
    |--MyProject
        |--WEB-INF
            |--classes/
            |--beans.xml
            |--web.xml
        |--xsd
            |--incident.xsd


Thanks



--
View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783p5751833.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Validate JAXB Object with xsd schema

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Have a look please if a warning is being displayed about a schema 
resource not found when the server starts

Cheers, Sergey
On 02/12/14 16:51, nikosdim wrote:
> Hi
>
> I have written a JAXRS service with accepts xml as input in the body of a
> POST request. The xml is converted to an JAXB Object automatically. Below is
> my code and configuration
>
> Using CXF 3.0.1, tomcat 7.0.42, java 1.7.0_55
>
> *Service*
> @Path("incident")
> public class CreateIncident {
> 	@POST
> 	@Consumes({ MediaType.APPLICATION_XML})
> 	public Response createIncident(Incident incident) {
> 			//code
> 	}
> }
>
> *JAXB Object*
> @XmlRootElement(name = "incident")
> @XmlAccessorType(XmlAccessType.FIELD)
> public class Incident extends Event {
> 	public Incident() {
> 		super("incident");
> 	}
> 	
> 	private String importProfile;
> 	
> 	public String getImportProfile() {
> 		return importProfile;
> 	}
>
> 	public void setImportProfile(String importProfile) {
> 		this.importProfile = importProfile;
> 	}
> }
>
> *Config*
> <jaxrs:server address="/">
> 		<jaxrs:schemaLocations>
> 			<jaxrs:schemaLocation>classpath:xsd/incident.xsd</jaxrs:schemaLocation>
> 		</jaxrs:schemaLocations>
> 		<jaxrs:serviceBeans>
> 			<bean class="com.ba.sysman.services.events.CreateIncident"></bean>
> 		</jaxrs:serviceBeans>
> 		<jaxrs:features>
> 			<cxf:logging/>
> 		</jaxrs:features>
> </jaxrs:server>
>
> When I am sending a POST request to the service with an xml that does not
> conform with the xsd defined in the jaxrs:schemaLocation tag the Incident
> object is populated with no xsd errors or exceptions.
>
> What is wrong with my configuration?
>
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Validate-JAXB-Object-with-xsd-schema-tp5751783.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>