JAX-WS使用@SchemaValidation在WebLogic中验证架构 [英] JAX-WS Validate Schema in WebLogic with @SchemaValidation

查看:398
本文介绍了JAX-WS使用@SchemaValidation在WebLogic中验证架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到解决方案而且发现更多人陷入同样的​​问题所以我会在这里发布。

I wasn't able to find the solution and I found more people stuck in the same problem so I will post it here.

默认情况下,JAX-WS服务器(至少对于WebLogic)不会验证通过其关联模式接收的消息。

By default a JAX-WS server (at least for WebLogic) will not validate the message received with its associated schema.

这会导致很多问题,因为任何无效值(错误的xsd:dateTime格式,数字字段上的字母等)都会导致 null Java对象中的值,包括必填字段。

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.

我需要做的是一个应该由服务器提供的简单验证。

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.

推荐答案

问题是:我使用了错误的包 @SchemaValidation

The problem was: I was using the wrong package for @SchemaValidation.

对我有用的正确类是 com。 sun.xml.ws.developer.SchemaValidation ,在文件 mw_home \modules \ glassfish.jaxws.rt_1.3.0中提供。 0_2-1-5.jar (使用WLS 10.3.6)。

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).

在前面的代码段中,我引用了错误的软件包:com.sun.xml。内部 ...但使用WebLogic提供的软件立即工作。

In the previous code segment I was referencing the wrong package: com.sun.xml.internal... but using the one provided by WebLogic worked instantly.

如果您使用的是Maven并且使用捆绑的JAR作为依赖项,您可能在类路径中没有此库,这导致了我的问题。您需要通过依赖项(仅提供范围)将其添加到类路径中,并在JAX-WS WebService类中引用该类名的正确包(一个抽象类赢了'做它)。

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. 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).

在服务器上启用架构验证页面。

此架构验证对我来说已经足够了不需要任何自定义行为。

This schema validation is enough for me at the moment since I do not need any custom behavior.

这篇关于JAX-WS使用@SchemaValidation在WebLogic中验证架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆