Skip to main content

@SchemaValidation Problem in JAX-WS 2.1.3

20 replies [Last post]
chris__
Offline
Joined: 2007-09-11
Points: 0

Hi all,

when I switch on @SchemaValidation on the endpoint implementation the following error occurs:

javax.xml.ws.WebServiceException: org.xml.sax.SAXParseException: src-resolve.4.1: Error resolving component 'string'. It was detected that 'string' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/xxx/src/main/webapp/WEB-INF/wsdl/yyy.xsd'. If 'string' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'string' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/xxx/src/main/webapp/WEB-INF/wsdl/yyy.xsd'

The yyy.xsd looks like that snippet:

(ServerSchemaValidationTube.java:69)
at com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext.createValidationTube(ServerTubeAssemblerContext.java:212)
at com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.createServer(StandaloneTubeAssembler.java:76)
at com.sun.xml.ws.server.WSEndpointImpl.(WSEndpointImpl.java:152)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:217)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108)

Anyone could help?
Thanks

UPDATE:

I modified the yyy.xsd:

(URL.java:601)
at java.net.URL.(URL.java:464)
at com.sun.xml.ws.server.ServerSchemaValidationTube$MetadataResolverImpl.resolveResource(ServerSchemaValidationTube.java:141)
at com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper.resolveEntity(DOMEntityResolverWrapper.java:106)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntity(XMLEntityManager.java:1100)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.resolveDocument(XMLSchemaLoader.java:595)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.resolveSchema(XSDHandler.java:1671)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees(XSDHandler.java:909)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:569)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:519)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:485)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:206)
at com.sun.xml.ws.server.ServerSchemaValidationTube.(ServerSchemaValidationTube.java:67)
at com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext.createValidationTube(ServerTubeAssemblerContext.java:212)
at com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.createServer(StandaloneTubeAssembler.java:76)
at com.sun.xml.ws.server.WSEndpointImpl.(WSEndpointImpl.java:152)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:217)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108)

SCHWERWIEGEND: WSSERVLET11: failed to parse runtime descriptor: javax.xml.ws.WebServiceException: org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'base' in element 'restriction'. Recorded reason: UndeclaredPrefix: Cannot resolve 'xsd:string' as a QName: the prefix 'xsd' is not declared.
javax.xml.ws.WebServiceException: org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'base' in element 'restriction'. Recorded reason: UndeclaredPrefix: Cannot resolve 'xsd:string' as a QName: the prefix 'xsd' is not declared.
at com.sun.xml.ws.server.ServerSchemaValidationTube.(ServerSchemaValidationTube.java:69)
at com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext.createValidationTube(ServerTubeAssemblerContext.java:212)
at com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.createServer(StandaloneTubeAssembler.java:76)
at com.sun.xml.ws.server.WSEndpointImpl.(WSEndpointImpl.java:152)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:217)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108)

is this a bug?

Message was edited by: chris__

2.UPDATE:

I changed a litte the importing schemas in my wsdl... now I get the following SAXParseException:

INFO: WSSERVLET12: JAX-WS context listener initializing
09.01.2008 14:48:53 com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
SCHWERWIEGEND: WSSERVLET11: failed to parse runtime descriptor: javax.xml.ws.WebServiceException: org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'substitutionGroup' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'ogc:expression' as a QName: the prefix 'ogc' is not declared.
javax.xml.ws.WebServiceException: org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'substitutionGroup' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'ogc:expression' as a QName: the prefix 'ogc' is not declared.
at com.sun.xml.ws.server.ServerSchemaValidationTube.(ServerSchemaValidationTube.java:69)
at com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext.createValidationTube(ServerTubeAssemblerContext.java:212)
at com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.createServer(StandaloneTubeAssembler.java:76)
at com.sun.xml.ws.server.WSEndpointImpl.(WSEndpointImpl.java:152)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:217)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:253)
at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:147)
at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:108)

Caused by: org.xml.sax.SAXParseException: s4s-att-invalid-value: Invalid attribute value for 'substitutionGroup' in element 'element'. Recorded reason: UndeclaredPrefix: Cannot resolve 'ogc:expression' as a QName: the prefix 'ogc' is not declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:2529)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.reportSchemaError(XSAttributeChecker.java:1608)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes(XSAttributeChecker.java:1175)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes(XSAttributeChecker.java:996)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseGlobal(XSDElementTraverser.java:213)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseSchemas(XSDHandler.java:1258)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:579)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:519)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:485)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:206)
at com.sun.xml.ws.server.ServerSchemaValidationTube.(ServerSchemaValidationTube.java:67)

the imported schema looks like:

....

whats wrong with prefix "ogc"?
Is there a bug in prefix resolving?

Thanks

Message was edited by: chris__

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jitu
Offline
Joined: 2003-06-14
Points: 0

[code]
public class MyErrorHandler extends ValidationErrorHandler {

public void error(SAXParseException e) throws SAXException {
String response = packet.invocationProperties.get("response");
if (response == null) {
// If there is an error in Request, throw service specific exception
CheckedException e = new CheckedException()
throw new SOAPFaultException(..., e);
} else {
// If there is an error in response, throw service specific exception
CheckedException e = new CheckedException()
throw new SOAPFaultException(..., e);
}

}
..

}

In endpoint impl:
msgContext.put("response", "response");
[/code]

In the above code, if server receives an invalid request, it throws checked exception. Endpoint is not even invoked, the corresponding fault message will be sent to the client.

If endpoint receives a request means that the request is valid. Endpoint populates with a property "response". If the error handler is invoked for server's response, then throw a checked exception.

May be I should modify the schema-validation sample to show this.

alotor
Offline
Joined: 2008-02-02
Points: 0

Thanks! That's a neat solution, but is there some way of invoking the validation process before?
In our project we have an arround interceptor which starts a new transaction. After invoking the WS method we are commiting that transaction, but in some cases, we have a validation failure and so, we returned a SOAP Fault when the transaction had been commited.

Any idea of how can we validate the schema before?

jitu
Offline
Joined: 2003-06-14
Points: 0

Actually, the above won't work. We need to create a runtime exception say ValidationException. When the code throws a ValidationException with the cause checked exception, it can be converted to correct SOAP fault message.

Regarding, the transaction, I need to think more. There are two ways to do this. The runtime could start the transaction before the endpoint is called based on some annotation. When the validation happens, it could commit/rollback the transaction. Other option is to invoke a callback when the validation is successful, then the application could commit the trasaction. When there is a validation failure, the application could rollback in the ValidationErrorHandler.

alnat83
Offline
Joined: 2008-12-10
Points: 0

Hi, Jitu!

Could you help me resolving the issue with transaction?
There is a facade web service based on StatelessSessionBean. It is used for creating XA transaction. This WS delegated all calles to another service deployed in scope of JBI service asembly on GlasssfishESB after it created transactional context.

The problem is that if I throw SOAPFaultException (when request validation failed) transaction appeared to to be started to that moment. So it is roolled back (that is fine), but the message returned to the client looks like this:



S:Server
java.lang.IllegalStateException


At the same time if I call non-transactional method of the same facade WS, validation response to client looks pritty better:




S:Client.SchemaValidationError
Validation of incoming message failed
http://starlab.scartel.com/services/wsdl/AccountManagementService


cvc-complex-type.2.4.b: The content of element 'acc:GetDevicesRequest' is not complete. One of '{param}' is expected.




Could you suggested me something to avoid this behaviour? How can I return readable fault message after transaction started?

bshrom
Offline
Joined: 2004-03-04
Points: 0

What did you change in your attached example to get SchemaValidation to work?

balajiseshadri
Offline
Joined: 2008-11-06
Points: 0

Can i get an working example for including our own Checked Exception when Response or Request validation occurs.

chris__
Offline
Joined: 2007-09-11
Points: 0

Hi,

Now @SchemaValidation works fine for incoming messages.. How do I validate outgoing messages? (i.e. where to place MessageContext or sth like that?)

I use https://metro.dev.java.net/guide/Schema_Validation.html and https://jax-ws.dev.java.net/articles/MessageContext.html

regards,
chris

jitu
Offline
Joined: 2003-06-14
Points: 0

@SchemaValidation does validation for both incoming and outgoing messages on the endpoint side. For the client use, use SchemaValidationFeature.

chris__
Offline
Joined: 2007-09-11
Points: 0

Yes I see.

I want to distinguish incomming and outgoing messages.

I have 3 @WebMethods and within these methods i use MessageContext at first to see if there was an validation error on the incomming message..

MessageContext context = wsContext.getMessageContext();
Object o1 = context.get("SAXValidationError");
I catch theses error and throw my own @WebFault.

The example code throws also outgoing message validation errors and sends it to the client...
I want to catch these errors too. and send my own @WebFault, but i don't know how to do that.

regards,
chris

jitu
Offline
Joined: 2003-06-14
Points: 0

> I want to distinguish incomming and outgoing
> messages.
>
> I have 3 @WebMethods and within these methods i use
> MessageContext at first to see if there was an
> validation error on the incomming message..

Let us see first how you can do this one. You need to write your own com.sun.xml.ws.developer.ValidationErrorHandler

i.e
[code]
public class MyErrorHandler extends ValidationErrorHandler {
public void warning(SAXParseException e) throws SAXException {
throw e;
}

public void error(SAXParseException e) throws SAXException {
packet.invocationProperties.put("SomeError", e);
}

public void fatalError(SAXParseException e) throws SAXException {
packet.invocationProperties.put("SomeError", e);
}

}

Annotate the endpoint with the error handler

@SchemaValidation(handler=MyErrorHandler.class)
@WebService
public class TestEndpointImpl {
...
}

and can access the property "SomeError" from MessageContext

MessageContext context = wsContext.getMessageContext();
Object o1 = context.get("SomeError");
[/code]

chris__
Offline
Joined: 2007-09-11
Points: 0

Hi jitu, i wrote your MyErrorHandler (don't throw anything) and use it like that:

@SchemaValidation(handler=MyErrorHandler.class)
@WebService
public class TestEndpointImpl {

@Resource
WebServiceContext wsContext;

@WebMethod
public foo xxx(bar yyy) throws FaultMessage {
//validate request
MessageContext context = wsContext.getMessageContext();
Object o1 = context.get("SAXValidationError");
if (o1 instanceof SAXParseException) { throw new FaultMessage(.....

}

but how do i "catch" the SAXParseException from the outgoing server message, and send FaultMessage instead (i.e. if my server tries to send an non-valid response, i don't want to send the SAXParseException message, but my InternalServerErrorMessage)?

I think i can't do this within a @WebMethod, can I ?
I tried MessageContext.MESSAGE_OUTBOUND_PROPERTY and @SOAPMessageHandlers but without success...

Can I somehow distinguish the message direction of an non-valid message?

any help would be appreciated

regards,
chris

anyone has an idea?

Message was edited by: chris__

jitu
Offline
Joined: 2003-06-14
Points: 0

This can be done in the ErrorHandler for the response. Is your InternalServerErrorMessage a checked exception ?

chris__
Offline
Joined: 2007-09-11
Points: 0

Yes it is a checked exception.

I always want to return FaultMessage (its my @WebFault... public class FaultMessage
extends Exception) if a validation error occurs.

so how do i use this ErrorHandler?

regards,
chris

alotor
Offline
Joined: 2008-02-02
Points: 0

I'm having the same problem. Have you found any workaround for this problem?

Thanks,

kaumar
Offline
Joined: 2007-09-18
Points: 0

Hi,

I have come across this same issue with @SchemaValidation. Your suggested workaround (use JDK6) solves the issue. However this is not a valid solution for me as I'm stuck with JDK5

But the main point is that I have also found out that if I validate the same message with JAXP myself (in a JAX-WS LogicalMessageHandler) the schema is validated ok even in JDK5. So it seems this issue is not related to JAXP but JAX-WS 2.1.3 instead.

regards
Martti

chris__
Offline
Joined: 2007-09-11
Points: 0

so its definitely an JAX-WS issue?

so this issue is not fixed? https://jax-ws.dev.java.net/issues/show_bug.cgi?id=239

or maybe I'm doing something wrong ;)

testet with jetty 6.1.6rc1 and tomcat 6.0.10 on jdk 1.6 u3 (tomcat prints same errror type with an other schema... maybe tomcat gets a different sequence of the referenced schemas)

I'll try to write a simple testcase ...

regards
chris

Jitendra Kotamraju

metro@javadesktop.org wrote:
> so its definitely an JAX-WS issue?
>
> so this issue is not fixed? https://jax-ws.dev.java.net/issues/show_bug.cgi?id=239
>
> or maybe I'm doing something wrong ;)
>
> testet with jetty 6.1.6rc1 and tomcat 6.0.10 on jdk 1.6 u3 (tomcat prints same errror type with an other schema... maybe tomcat gets a different sequence of the referenced schemas)
>
> I'll try to write a simple testcase ...
>
A simple test case would help in fixing the problem.

Jitu

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

chris__
Offline
Joined: 2007-09-11
Points: 0

Hi,

I got it ... ;)

The problem seems to be additional jar loading by my maven dependency settings.

I use dom4j in my project (which depends on jaxen .. which depends on xom).
I think xom or one of its dependencies causes this problem ...

here is the depency list of xom 1.1:



xerces
xmlParserAPIs
2.6.2


xerces
xercesImpl
2.6.2


xalan
xalan
2.6.0


com.ibm.icu
icu4j
2.6.1

I attached a small testcast in which I included xom in pom.xml (simply run with mvn jetty:run)

so is this an issue or just confusing classloading stuff? :)

regards,
chris

jitu
Offline
Joined: 2003-06-14
Points: 0

May be you are running into

https://jaxp.dev.java.net/issues/show_bug.cgi?id=46

There is a workaround already in 2.1.3 and may be that's not working. What's your JDK version ?

chris__
Offline
Joined: 2007-09-11
Points: 0

I use jdk 1.6.0_01 with jax-ws 2.1.3 and jaxb 2.1.6

Its a jaxp issue? How to find out jaxp version?

Maybe the hint with jdk version 1.6.0_03 works ... I will try

Message was edited by: chris__

With jdk 1.6.0 u3 the ValidationTest works, but my problem is still unsolved ...

Message was edited by: chris__