简体   繁体   English

针对Schematron验证WebService消息

[英]Validate WebService message against Schematron

I have generated a web service client using JAX-WS and wsimport. 我已经使用JAX-WS和wsimport生成了一个Web服务客户端。

This is my client code: 这是我的客户代码:

URL url = new URL("http://localhost:9999/ws/processstuff?wsdl");
QName qname = new QName("namespace", "ProcessStuffImplService");
Service service = Service.create(url, qname);
ProcessStuffInterface processStuffInterface = service.getPort(ProcessStuffInterface.class);

ProcessStuffObject processStuffObject = new ProcessStuffObject();
//Web service call
processStuffInterface.processStuff(processStuffObject);

I need to validate processStuffObject against given Schematron rules before making the web service call above. 在进行上面的Web服务调用之前,我需要根据给定的Schematron规则验证processStuffObject I have looked at libraries like ph-schematron, but it seems like validation can only made on objects like File or similar. 我看过类似ph-schematron的库,但似乎只能对File或类似对象进行验证。 Does anyone know a way to validate an object generated with JAX-WS, like my ProcessStuffObject , against Schematron rules? 有谁知道一种针对Schematron规则验证使用JAX-WS生成的对象(如我的ProcessStuffObject吗?

Update: 更新:
Now I have marshalled ProcessStuffObject to a File object that can be validated with ph-schematron, but this seems like a really stupid solution. 现在,我已经将ProcessStuffObject编组为可以用ph-schematron验证的File对象,但这似乎是一个非常愚蠢的解决方案。

JAX-WS is normally going to use JAXB to marshal objects to XML for sending over the wire and unmarshal received XML into objects. JAX-WS通常将使用JAXB将对象封送为XML,以通过有线发送并将接收到的XML封送为对象。 The JAXB API offers some useful stuff for transparently handling an object like XML without explicitly having to first marshal it to a file, String, byte array or other intermediate representation. JAXB API提供了一些有用的东西,可以透明地处理XML之类的对象,而不必先将其编组为文件,字符串,字节数组或其他中间表示形式。

The class you need is JAXBSource . 您需要的类是JAXBSource It implements the javax.xml.transform.Source interface and lets you provide an object and a JAXBContext or a Marshaller. 它实现了javax.xml.transform.Source接口,并允许您提供一个对象以及JAXBContext或Marshaller。 You can then supply it as a source for transformations or other methods that take such an instance. 然后,您可以将其作为进行转换或采用此类实例的其他方法的源。 Some of the ph-schematron methods accept a Source as input, such as this one . 一些ph-schematron方法接受Source作为输入, 例如this

If you pre-compile the Schematron files to an XSLT you could just use the Java XML transformation API and supply the Source to the transformer. 如果将Schematron文件预编译为XSLT,则可以使用Java XML转换API并将Source提供给转换器。

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

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