简体   繁体   English

使用@SchemaValidation的WebLogic中的JAX-WS验证架构

[英]JAX-WS Validate Schema in WebLogic with @SchemaValidation

I wasn't able to find the solution and I found more people stuck in the same problem so I will post it here. 我找不到解决方案,发现更多人陷入同一问题,因此我将其发布在这里。


By default a JAX-WS server (at least for WebLogic) will not validate the message received with its associated schema. 默认情况下,JAX-WS服务器(至少用于WebLogic)将不验证通过其关联模式接收到的消息。

This can lead to a lot of problems since any invalid value (wrong xsd:dateTime format, letters on a number field, etc) will result in a null value in the Java object, including mandatory fields. 由于任何无效值(错误的xsd:dateTime格式,数字字段中的字母等)都将导致Java对象(包括必填字段)中的值,从而导致许多问题。

What I need to do is a simple validation that should be provided by the server. 我需要做的是服务器应提供的简单验证。

import com.sun.xml.internal.ws.developer.SchemaValidation;

@Stateless
@WebService(portName="ValidatedService")
@SchemaValidation
public class ValidatedService {

    public void operation(@WebParam(name="request") ValidatedRequest request) {

        /* do stuff */
    }
}

For some reason when I was trying to use the provided schema validation I was getting the following exception: 由于某些原因,当我尝试使用提供的架构验证时,出现以下异常:

Caused By: javax.xml.ws.WebServiceException: Annotation @com.sun.xml.internal.ws.developer.SchemaValidation(handler=class com.sun.xml.internal.ws.server.DraconianValidationErrorHandler) is not recognizable, atleast one constructor of class com.sun.xml.internal.ws.developer.SchemaValidationFeature should be marked with @FeatureConstructor

I do not wish to implement any custom validator. 我不希望实现任何自定义验证器。 The server should provided this type of service with simple and straightforward configuration. 服务器应使用简单明了的配置来提供此类服务。

The problem was: I was using the wrong package for @SchemaValidation . 问题是:我为@SchemaValidation使用了错误的包。

The correct class that worked for me is com.sun.xml.ws.developer.SchemaValidation , which is provided in the file mw_home\\modules\\glassfish.jaxws.rt_1.3.0.0_2-1-5.jar (using WLS 10.3.6). 对我mw_home\\modules\\glassfish.jaxws.rt_1.3.0.0_2-1-5.jar的正确类是com.sun.xml.ws.developer.SchemaValidation ,该文件在文件mw_home\\modules\\glassfish.jaxws.rt_1.3.0.0_2-1-5.jar (使用WLS 10.3)中提供。 6)。

In the previous code segment I was referencing the wrong package: com.sun.xml. 在上一个代码段中,我引用了错误的包:com.sun.xml。 internal ... but using the one provided by WebLogic worked instantly. 内部 ...但是使用WebLogic提供的功能可以立即工作。

If you are using Maven and using the bundled JAR as dependency you might not have this library in the classpath, which led me to the problem. 如果您正在使用Maven并将捆绑的JAR用作依赖项,则可能在类路径中没有此库,这导致了我的问题。 You need to add it to your classpath via dependency ( provided scope only) and reference the correct package for that class name in your JAX-WS WebService class (an abstract class won't do it). 您需要通过依赖关系(仅provided作用域)将其添加到类路径中,并在JAX-WS WebService类中引用该类名称的正确包(抽象类不会这样做)。

More information in the Enabling Schema Validation on the Server page. “服务器”页面上的启用架构验证”中的更多信息。

This schema validation is enough for me at the moment since I do not need any custom behavior. 由于我不需要任何自定义行为,因此此模式验证对我而言已经足够。

In my case: Maven project with many modules. 就我而言:具有许多模块的Maven项目。 I got the next error when was trying to deploy application into tomcat: 尝试将应用程序部署到tomcat时出现下一个错误:

failed to parse runtime descriptor: javax.xml.ws.WebServiceException: Annotation @com.sun.xml.ws.developer.SchemaValidation(handler=class com.sun.xml.ws.server.DraconianValidationErrorHandler) is not recognizable, at least one constructor of class com.sun.xml.ws.developer.SchemaValidationFeature should be marked with @FeatureConstructor 无法解析运行时描述符:javax.xml.ws.WebServiceException:注释@ com.sun.xml.ws.developer.SchemaValidation(handler = class com.sun.xml.ws.server.DraconianValidationErrorHandler)无法识别,至少一个com.sun.xml.ws.developer.SchemaValidationFeature类的构造函数应使用@FeatureConstructor标记

I resolved problem by don't including jaxws-rt.jar in WEB-INF/lib. 我通过不在WEB-INF / lib中包含jaxws-rt.jar解决了问题。 It appears that this library already exists in the tomcat/lib folder. 看来该库已经存在于tomcat / lib文件夹中。

Just tuned up pom.xml, setted provided scope for this dependency entry. 刚刚调优pom.xml,设置此依赖项条目的作用域。 Now all works fine. 现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM