You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sivan Yogev <si...@expand.com> on 2010/08/05 08:16:40 UTC

problem validating response with schema for rest services (jaxrs)

Hi-

I tried to post this in the cxf forum, but I keep seeing that the message is in status 'pending',
So I am sending it manually.
I am trying to implement CXF framework for REST services (jaxrs) without spring.
I followed the examples, and managed to receive xml message in the request, and then validate the xml according to a schema defined in web.xml file, and get the correct object in the service.
Now I have 2 problems:

1) I also want to enable schema validation on the response object (java to xml),
Can you please show me how to do that?
Can this somehow be done in the javax.ws.rs.core.Response object?
I couldn't find solution for this anywhere...

2) For the incoming xml message I have 2 schemas - one depends on the other
(Registration.xsd uses tags that is located in EVGeneralSchema.xsd).
I defined both of them in web.xml:
<init-param>
      <param-name>jaxrs.schemaLocations</param-name>
      <param-value>
        classpath:/schemas/Registration.xsd
        classpath:/schemas/EVGeneralSchema.xsd
      </param-value>
     </init-param>

I added the 'import' tag in Registration.xsd, but I keep getting the following exception:

Aug 4, 2010 9:43:43 AM org.apache.cxf.jaxrs.utils.schemas.SchemaHandler createSchema
WARNING: Validation will be disabled, failed to create schema : src-resolve.4.2: Error resolving component 'evns:ip'. It was detected that 'evns:ip' is in namespace 'EVGeneralSchema.xsd', but components from this namespace are not referenceable from schema document 'null'. If this is the incorrect namespace, perhaps the prefix of 'evns:ip' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'null'.

Any ideas?

Thanks a lot
Sivan

Sivan Yogev
Software Engineer - ExpandView Team

EXPAND NETWORKS | SMARTER NETWORKS, FASTER APPLICATIONS(tm)

6 Hanechoshet Street | Tel Aviv, Israel 69710
V: +972.3.766.8050 | F: +972.3.766.8001 | M: +972.52.386.9139
sivan.yogev@expand.com<ma...@expand.com> | http://<http://www.expand.com/>www.expand.com<http://www.expand.com/>

Gartner Report:
Expand Networks Positioned in the Leaders Quadrant of Gartner's Magic Quadrant <http://www.expand.com/newsletters/newCollateral-registration.aspx?promotion=gartner07>

Learn More About Expand Networks' WAN Optimization Through Our New Videos:
Optimizing Citrix and RDP<http://www.expand.com/video/player.aspx?loc=citrix> | Server Consolidation<http://www.expand.com/video/player.aspx?loc=sc> | Optimizing Satellite Communications<http://www.expand.com/video/player.aspx?loc=satellite2>


Re: problem validating response with schema for rest services (jaxrs)

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

On Mon, Aug 9, 2010 at 3:40 PM, sivany [via CXF] <
ml-node+2268924-572176640-81415@n5.nabble.com<ml...@n5.nabble.com>
> wrote:

>
> Hi Sergey
>
> Thanks for the fast reply.
>
> was not that fast this time, sorry :-)


>
> >> 1) I also want to enable schema validation on the response object (java
> >> to
> >> xml),
> >> Can you please show me how to do that?
> >> Can this somehow be done in the javax.ws.rs.core.Response object?
> >> I couldn't find solution for this anywhere...
> >>
> >>
> > Not possible at the moment : you may want to try extending
> > JAXBElementProvider and override its createMarshaller method and then
> > setup
> > the Marshaller to do the validation - let us know please if you can make
> > it
> > work and then JAXBElementProvider can get enhanced accordingly
> >
>
> The overriding of createMarshaller method will not be a good solution for
> me,
> because this is done while the response is written to the stream.
> I was looking for validations before the marshalling operation,
> maybe in the setters of the returned object (by using the schema
> annotations)?
> Is this possible?
>
>
At this stage I can only suggest adding a ResponseHandler filter and get the
object from the input Response and validate it somehow.


>
>
> >> Aug 4, 2010 9:43:43 AM org.apache.cxf.jaxrs.utils.schemas.SchemaHandler
> >> createSchema
> >> WARNING: Validation will be disabled, failed to create schema :
> >> src-resolve.4.2: Error resolving component 'evns:ip'. It was detected
> >> that
> >> 'evns:ip' is in namespace 'EVGeneralSchema.xsd', but components from
> this
> >> namespace are not referenceable from schema document 'null'. If this is
> >> the
> >> incorrect namespace, perhaps the prefix of 'evns:ip' needs to be
> changed.
> >> If
> >> this is the correct namespace, then an appropriate 'import' tag should
> be
> >> added to 'null'.
> >>
> >> Any ideas?
> >>
> > Please list the self-contained schemas first, listing EVGeneralSchema.xsd
> > first should fix it
> >
>
> I solved it - The problem was wrong path in the import tag,
> I am using tomcat and I thought the relative path is from 'WEB-INF'
> directory,
> but it is from tomcat 'bin' dir.
>
> good, thanks for the confirmation

Sergey


> Thanks
>
>
> ______________________________________
> This email was sent by sivany (via Nabble)
> Your replies will appear at
> http://cxf.547215.n5.nabble.com/problem-validating-response-with-schema-for-rest-services-jaxrs-tp2264992p2268924.html
> To receive all replies by email, subscribe to this discussion:
> http://cxf.547215.n5.nabble.com/template/NodeServlet.jtp?tpl=subscribe_by_code&node=2268924&code=dXNlcnNAY3hmLmFwYWNoZS5vcmd8MjI2ODkyNHwtMTA5NTcxOTE5Nw==
>

Re: problem validating response with schema for rest services (jaxrs)

Posted by "sivany [via CXF]" <ml...@n5.nabble.com>.
Hi Sergey

Thanks for the fast reply.



>> 1) I also want to enable schema validation on the response object (java
>> to
>> xml),
>> Can you please show me how to do that?
>> Can this somehow be done in the javax.ws.rs.core.Response object?
>> I couldn't find solution for this anywhere...
>>
>>
> Not possible at the moment : you may want to try extending
> JAXBElementProvider and override its createMarshaller method and then
> setup
> the Marshaller to do the validation - let us know please if you can make
> it
> work and then JAXBElementProvider can get enhanced accordingly
> 

The overriding of createMarshaller method will not be a good solution for
me,
because this is done while the response is written to the stream.
I was looking for validations before the marshalling operation, 
maybe in the setters of the returned object (by using the schema
annotations)?
Is this possible?



>> Aug 4, 2010 9:43:43 AM org.apache.cxf.jaxrs.utils.schemas.SchemaHandler
>> createSchema
>> WARNING: Validation will be disabled, failed to create schema :
>> src-resolve.4.2: Error resolving component 'evns:ip'. It was detected
>> that
>> 'evns:ip' is in namespace 'EVGeneralSchema.xsd', but components from this
>> namespace are not referenceable from schema document 'null'. If this is
>> the
>> incorrect namespace, perhaps the prefix of 'evns:ip' needs to be changed.
>> If
>> this is the correct namespace, then an appropriate 'import' tag should be
>> added to 'null'.
>>
>> Any ideas?
>>
> Please list the self-contained schemas first, listing EVGeneralSchema.xsd
> first should fix it
> 

I solved it - The problem was wrong path in the import tag,
I am using tomcat and I thought the relative path is from 'WEB-INF'
directory,
but it is from tomcat 'bin' dir.

Thanks


______________________________________
This email was sent by sivany (via Nabble)
Your replies will appear at http://cxf.547215.n5.nabble.com/problem-validating-response-with-schema-for-rest-services-jaxrs-tp2264992p2268924.html
To receive all replies by email, subscribe to this discussion: http://cxf.547215.n5.nabble.com/template/NodeServlet.jtp?tpl=subscribe_by_code&node=2268924&code=dXNlcnNAY3hmLmFwYWNoZS5vcmd8MjI2ODkyNHwtMTA5NTcxOTE5Nw==

Re: problem validating response with schema for rest services (jaxrs)

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

sorry for a delay...

On Thu, Aug 5, 2010 at 7:16 AM, Sivan Yogev <si...@expand.com> wrote:

> Hi-
>
> I tried to post this in the cxf forum, but I keep seeing that the message
> is in status 'pending',
> So I am sending it manually.
> I am trying to implement CXF framework for REST services (jaxrs) without
> spring.
> I followed the examples, and managed to receive xml message in the request,
> and then validate the xml according to a schema defined in web.xml file, and
> get the correct object in the service.
> Now I have 2 problems:
>
> 1) I also want to enable schema validation on the response object (java to
> xml),
> Can you please show me how to do that?
> Can this somehow be done in the javax.ws.rs.core.Response object?
> I couldn't find solution for this anywhere...
>
>
Not possible at the moment : you may want to try extending
JAXBElementProvider and override its createMarshaller method and then setup
the Marshaller to do the validation - let us know please if you can make it
work and then JAXBElementProvider can get enhanced accordingly


> 2) For the incoming xml message I have 2 schemas - one depends on the other
> (Registration.xsd uses tags that is located in EVGeneralSchema.xsd).
> I defined both of them in web.xml:
> <init-param>
>      <param-name>jaxrs.schemaLocations</param-name>
>      <param-value>
>        classpath:/schemas/Registration.xsd
>        classpath:/schemas/EVGeneralSchema.xsd
>      </param-value>
>     </init-param>
>
> I added the 'import' tag in Registration.xsd, but I keep getting the
> following exception:
>
> Aug 4, 2010 9:43:43 AM org.apache.cxf.jaxrs.utils.schemas.SchemaHandler
> createSchema
> WARNING: Validation will be disabled, failed to create schema :
> src-resolve.4.2: Error resolving component 'evns:ip'. It was detected that
> 'evns:ip' is in namespace 'EVGeneralSchema.xsd', but components from this
> namespace are not referenceable from schema document 'null'. If this is the
> incorrect namespace, perhaps the prefix of 'evns:ip' needs to be changed. If
> this is the correct namespace, then an appropriate 'import' tag should be
> added to 'null'.
>
> Any ideas?
>
> Please list the self-contained schemas first, listing EVGeneralSchema.xsd
first should fix it

cheers, Sergey


> Thanks a lot
> Sivan
>
> Sivan Yogev
> Software Engineer - ExpandView Team
>
> EXPAND NETWORKS | SMARTER NETWORKS, FASTER APPLICATIONS(tm)
>
> 6 Hanechoshet Street | Tel Aviv, Israel 69710
> V: +972.3.766.8050 | F: +972.3.766.8001 | M: +972.52.386.9139
> sivan.yogev@expand.com<ma...@expand.com> | http://<
> http://www.expand.com/>www.expand.com<http://www.expand.com/>
>
> Gartner Report:
> Expand Networks Positioned in the Leaders Quadrant of Gartner's Magic
> Quadrant <
> http://www.expand.com/newsletters/newCollateral-registration.aspx?promotion=gartner07
> >
>
> Learn More About Expand Networks' WAN Optimization Through Our New Videos:
> Optimizing Citrix and RDP<
> http://www.expand.com/video/player.aspx?loc=citrix> | Server
> Consolidation<http://www.expand.com/video/player.aspx?loc=sc> | Optimizing
> Satellite Communications<
> http://www.expand.com/video/player.aspx?loc=satellite2>
>
>