You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Richard Senior <ri...@gmail.com> on 2013/03/20 14:59:30 UTC

Schema validation errors on publish.... "top level elements may not have a 'use'"

Hello,

This is a pretty random question...

I create some service code from a WSDL using the maven codegen tool.
Then I use the jaxws:endpoint tag to create a service endpoint..
All compiles and builds ok...
But when I try to deploy I get :

org.apache.ws.commons.schema.XmlSchemaException: Top-level attributes may
not have a 'use'

Now.. it seems that one of the XSD's used by the wsdl has an attribute named
'use' in it, this is a legitimate attribute that specifies whether something
is required or not.
I think somehow this is getting confused with the wsdl 'use' attribute which
has to do with 'document literal' etc.

I created my own bean that creates an EndpointImpl and calls publish
manually but I get the same error.

This is sensitive so I cannot really publish the wsdl here.. but if someone
can help I should be able to provide something..

Here's hoping someone knows straight away what the problem is...




--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Glen Mazza <gm...@talend.com>.
On 03/20/2013 01:57 PM, Richard Senior wrote:
> Sorry if that was a bit long winded...
> Two short questions :
> 1) Why is it that cxf-codegen-plugin produces valid classes without
> complaint but at runtime, schema validation fails.

I would guess validation is done then because validation also takes into 
account the values passed into the SOAP messages, and those aren't known 
at compile time.

> 2) Why is schema validation occuring at runtime at all... when instantiating
> a jaxws:endpoint since the classes are already generated?

It can normally be shut off ( 
http://www.jroller.com/gmazza/entry/soap_xml_schema_validation), but I 
don't know whether this particular error you're getting is a rule that 
would always be checked regardless (if it's done by the Oracle JAXB jar 
that CXF uses but does not have much control over, for example).

> 3) does the schema prohibit the 'use' attribute when it is used on a any
> subobject of 'complex type'
> So to be clear, it is used in my case on a simplecontent object that is
> buried within a complex type.
>

Best way is to just test it with a minimal WSDL.

Glen



>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5724892.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
Thank you for your continued patience..

Maven codegen produced an interface.. I implement that interface (eclipse
automatically copies the annotations from the interface, so the @WebService,
@XmlSeeAlso, @SoapBinding ... and the method annotations WebResult and
WebMethod)

My spring config is like this :

<bean id="blahServiceImpl" class="com.blah.blahImpl">
	    <property name="businessLogicBean" ref="businessLogicBean />
    </bean>
   
    <jaxws:endpoint id="myService" address="/1.0" wsdlLocation="">        
        <jaxws:implementor><ref
local="blahServiceImpl"/></jaxws:implementor>
    </jaxws:endpoint>

So, In the implementation class (com.blah.blahImpl), I inject my business
logic bean (which I have no annotated with @XmlTransient)
In the webmethod method I do :
*call business logic
*compile and return response object

Am I doing this right?
If I strip the annotations off my implementation class it all deploys and
works.. but that also doesn't seem right? I think this stops the service
from appearing in the weblogic console also?
Do I need some sort of abstraction (a wrapper I believe it's called?) or can
I just create a spring bean from my implementation as I am doing?



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725032.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Daniel Kulp <dk...@apache.org>.
On Mar 22, 2013, at 9:46 AM, Richard Senior <ri...@gmail.com> wrote:

> The wsdl is valid because the maven codegen tool produces the classes without
> error?

Not necessarily.   There are a bunch of things we don't validate there.  You can pass the -validate flag to wsdl2java which will do MORE validation than the default, but still doesn't validate everything.

> The annotations I understand, but CXF appears to be trying to reflect upon
> my spring injected business logic beans which are unrelated to the operation
> of the service itself.

How are you deploying the service?   There is a way to specify the endpointInterface to use just that and not the actual implementation.  (or fill in the endpointInterface attribute on the @WebService annotation)

> So for example I'm using HttpCommons to create a client for an old jaxrpc
> service, and CXF is complaining about the inner workings of HttpCommons..
> 
> Is there any way to mark a member variable on a bean such that CXF does not
> try to reflect upon it?

If it's on a JAXB bean, then @XmlTransient

Dan


> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725013.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
The wsdl is valid because the maven codegen tool produces the classes without
error?
The annotations I understand, but CXF appears to be trying to reflect upon
my spring injected business logic beans which are unrelated to the operation
of the service itself.

So for example I'm using HttpCommons to create a client for an old jaxrpc
service, and CXF is complaining about the inner workings of HttpCommons..

Is there any way to mark a member variable on a bean such that CXF does not
try to reflect upon it?



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725013.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Daniel Kulp <dk...@apache.org>.
On Mar 22, 2013, at 8:54 AM, Richard Senior <ri...@gmail.com> wrote:

> I nulled the wsdlLocation and now things have moved into more curious
> territory..
> 
> CXF seems to be reflecting upon beans that I've injected into my service
> implementation.. This is causing all manner of curious problems...  Is this
> kind of reflection normal?

Yes.  If you don't provide a valid WSDL, we use the annotations (and JAXB) to generate a WSDL and Schema.

> Can I disable it somehow?

No.  Having a valid schema and wsdl is required.  You either have to provide one or we generate it via annotations.   

> Must I really call create the service in a static method every time?

Not sure what you mean by that.

In any case, if there is a problem with a particular schema construct, create a test case so we can look at it.   


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
I nulled the wsdlLocation and now things have moved into more curious
territory..

CXF seems to be reflecting upon beans that I've injected into my service
implementation.. This is causing all manner of curious problems...  Is this
kind of reflection normal? Can I disable it somehow?
Must I really call create the service in a static method every time?



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725005.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Daniel Kulp <dk...@apache.org>.
On Mar 20, 2013, at 1:57 PM, Richard Senior <ri...@gmail.com> wrote:

> Sorry if that was a bit long winded...
> Two short questions :
> 1) Why is it that cxf-codegen-plugin produces valid classes without
> complaint but at runtime, schema validation fails.

Honestly, not sure on that.   We may be passing the schemas directly into JAXB without processing them ourselves first.  I'd have to dig through.

> 2) Why is schema validation occuring at runtime at all... when instantiating
> a jaxws:endpoint since the classes are already generated?

If you set the wsdlLocation for the jaxws:endpoint to null, it will generate a new schema based on the JAXB objects.   For the most part though, if you want the original wsdl, then we will parse/process it and make sure everything maps up correctly and make sure it's valid.

> 3) does the schema prohibit the 'use' attribute when it is used on a any
> subobject of 'complex type'
> So to be clear, it is used in my case on a simplecontent object that is
> buried within a complex type.

We'd need a full test case.   If you can produce a test case, feel free to log a bug.   We certainly have a bunch of test cases that have the use attribute on attributes of complexTypes.   Thus, from what we have tests for, it's working.   We'd need a new test that shows what exactly is not working.


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
Sorry if that was a bit long winded...
Two short questions :
1) Why is it that cxf-codegen-plugin produces valid classes without
complaint but at runtime, schema validation fails.
2) Why is schema validation occuring at runtime at all... when instantiating
a jaxws:endpoint since the classes are already generated?
3) does the schema prohibit the 'use' attribute when it is used on a any
subobject of 'complex type'
So to be clear, it is used in my case on a simplecontent object that is
buried within a complex type.





--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5724892.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
Thank you so much for looking at this ...

So I have a WSDL which specifies a wsdl:message - wsdl:part
element='req:blahRequest'
(so it references an xsd with namespace 'req'

The request xsd in turn declares a complext type and uses
xsd:extension base="req:Request" to refer to yet another XSD

that request in turn looks like this :

<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:messageContext="http://messaging.ei.blah.net/datatypes"
targetNamespace="http://www.censored.com/common/message/Request/v1.0"
version="1.0">
	<import namespace="http://messaging.ei.blah.net/datatypes"
schemaLocation="EIMessageContext2.xsd"/>
	<complexType name="Request">
		<sequence>
			<element name="eiMessageContext2"
type="messageContext:EIMessageContext2"/>
		</sequence>
	</complexType>
</schema>

Now.. that namespace messaging.ei.blah.net/datatypes is in the original XSD
but the maven codegen tool uses the -p switch to put this into a different
package (that might have some impact?)

So finally the file that's causing the problem is the EIMessageContext2 file
which 
looks a bit like this :

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://messaging.ei.blah.net/datatypes"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://messaging.ei.tmobile.net/datatypes"
version="-UNDEFINED-">
....
...
	<complexType name="EIDescriptionElement">
	    <annotation>
		    <documentation>
                             blahblah
		    </documentation>
		</annotation>
		<simpleContent>
			<extension base="string">
				<attribute default="en" ref="tns:lang" use="optional"/>
				<attribute name="descId" type="string" use="optional"/>
			</extension>
		</simpleContent>
	</complexType>

..
..

note the 'use' attribute here which is not the same as the WSDL use
attribute, but is perfectly valid for this schema.

What I don't understand is why when spring tries to create the
<jaxws:endpoint ... bean .. the wsdls are being validated at all, since by
this time.. the wsdls have already been converted into concrete classes by
maven...
It must be something in the annotations.. but what?

Would placing the wsdls in classpath and referencing them in the maven
codegen execution help?



--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5724869.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Daniel Kulp <dk...@apache.org>.
On Mar 20, 2013, at 9:59 AM, Richard Senior <ri...@gmail.com> wrote:

> Hello,
> 
> This is a pretty random question...
> 
> I create some service code from a WSDL using the maven codegen tool.
> Then I use the jaxws:endpoint tag to create a service endpoint..
> All compiles and builds ok...
> But when I try to deploy I get :
> 
> org.apache.ws.commons.schema.XmlSchemaException: Top-level attributes may
> not have a 'use'
> 
> Now.. it seems that one of the XSD's used by the wsdl has an attribute named
> 'use' in it, this is a legitimate attribute that specifies whether something
> is required or not.
> I think somehow this is getting confused with the wsdl 'use' attribute which
> has to do with 'document literal' etc.

Well, where is that attribute?  Top level or contained in a complexType or similar.  If you look at:

http://www.w3.org/TR/xmlschema11-1/#declare-attribute

and scroll down to just before section 3.2.2.1, it specifically states:

Note: The use attribute is not allowed on top-level <attribute> elements, so this can only happen with <attribute> elements appearing within a <complexType> or<attributeGroup> element.

Thus, if the "use" is on a global attribute, the error message is correct.  It would be an invalid schema.   

Dan


> I created my own bean that creates an EndpointImpl and calls publish
> manually but I get the same error.
> 
> This is sensitive so I cannot really publish the wsdl here.. but if someone
> can help I should be able to provide something..
> 
> Here's hoping someone knows straight away what the problem is...
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
Ooops..

One more thing.. I put my design time wsdls for my service in meta-inf and
referred to it like this

@WebService(....... wsdlLocation="META-INF/wsdl/....".....

I also added wsdlLocation="META-INF/wsdl...... to the <jaxws:endpoint.. tag
in the spring beans file.





--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725161.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Schema validation errors on publish.... "top level elements may not have a 'use'"

Posted by Richard Senior <ri...@gmail.com>.
Ok so just by way of cleanup...

My problems were that :
1) An XSD referred to by my WSDL is in fact invalid, but I cannot change
it.. it's given.
2) I had let spring copy the annotations from my service interface (which
was generated by maven codegen). The annotations on your implementation
should use the "endpointInterface" attribute to refer to the interface..
3) Because of (2) the CXF bean jaxws:endpoint couldn't find the design time
wsdl, and was attempting to create a wsdl at instantiation.. it couldn't do
this because of (1).. and to compound this, it was also reflecting on beans
injected into my implementation which was causing problems. it seems that
the maven codegen tool has less strict validation than the validation used
by jaxws:endpoint

Fixes for this were 
1) Can do nothing here
2) properly specify the endpointinterface, servicename, portname and
wsdllocation in the implementation annotations
   Also add @XmlTransient to any spring injected beans in the implementation
class

This fixed my issues...

Thank you very much for your efforts..




--
View this message in context: http://cxf.547215.n5.nabble.com/Schema-validation-errors-on-publish-top-level-elements-may-not-have-a-use-tp5724860p5725157.html
Sent from the cxf-user mailing list archive at Nabble.com.