使用 SOAPHandler 验证 SOAP 请求 [英] validating SOAP-Request with a SOAPHandler

查看:53
本文介绍了使用 SOAPHandler 验证 SOAP 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 WSDL 中定义的架构验证 SOAP 请求.我正在使用带有 SOAP-Handler-Chain 的 SOAPHandler.它起作用的唯一问题是,当我验证请求时,我收到此错误消息:

I'm trying to validate a SOAP-Request against the Schemas defined in the WSDL. I'm using a SOAPHandler with a SOAP-Handler-Chain. It works the only problem is that when I'm validating the request, I get this error message:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'v1:latitude'. One of '{"http://schemas.domain.com/wsdl/fuelprice/v1/model":latitude}' is expected.

WSDL 如下所示:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      mlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      mlns:http="http://schemas.xmlsoap.org/wsdl/http/"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tns="http://schemas.domain.com/wsdl/fuelprice/v1"
      xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model"
      xmlns:exception="http://schemas.domain.com/wsdl/fuelprice/v1/exception"
      targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1">
<wsdl:types>
    <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1" elementFormDefault="qualified">
        <xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" schemaLocation="common.xsd"/>
        <xsi:import namespace="http://schemas.domain.com/wsdl/fuelprice/v1/exception" schemaLocation="exception.xsd"/>
        <xsi:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>
        <xsi:element name="GetAreaFuelStationsRequest">
            <xsi:complexType>
                <xsi:sequence>
                    <xsi:element name="area" type="model:Area"/>
                </xsi:sequence>
                <xsi:attribute name="provider" type="xsi:string" use="optional"/>
                <xsi:attribute name="prices" type="xsi:boolean" use="required"/>
            </xsi:complexType>
        </xsi:element>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" xmlns:model="http://schemas.domain.com/wsdl/fuelprice/v1/model" targetNamespace="http://schemas.domain.com/wsdl/fuelprice/v1/model" elementFormDefault="qualified">
<xsi:complexType name="FuelStation">
    <xsi:complexType name="Area">
        <xsi:sequence>
            <xsi:element name="center" type="model:GeoLocation"/>
            <xsi:element name="radius" type="xsi:float"/>
        </xsi:sequence>
    </xsi:complexType>
    <xsi:complexType name="GeoLocation">
        <xsi:sequence>
            <xsi:element name="latitude" type="xsi:double"/>
            <xsi:element name="longitude" type="xsi:double"/>
        </xsi:sequence>
        <xsi:attribute name="ellipsoid" type="xsi:string" use="required"/>
    </xsi:complexType>

源代码片段:

    try {
        context.getMessage().getSOAPPart().getEnvelope();
        schemas = getSchemas(new URL(wsdlURI.toString().concat(wsdl)));
        schema = factory.newSchema(schemas);
        validator = schema.newValidator();
        validator.validate(new DOMSource(xml));
    }

请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://schemas.domain.com/wsdl/fuelprice/v1" xmlns:mod="http://schemas.domain.com/wsdl/fuelprice/v1/model">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:GetAreaFuelStationsRequest provider="ep1" prices="true">
         <v1:area>
            <mod:center ellipsoid="false">
                 <v1:latitude>49.8385</v1:latitude>
                 <v1:longitude>8.5014</v1:longitude>
            </mod:center>
            <mod:radius>10</mod:radius>
         </v1:area>
      </v1:GetAreaFuelStationsRequest>
   </soapenv:Body>
</soapenv:Envelope>

有人能看出这里有什么问题吗?我已经设置了

Can anybody see what is wrong here? I have set

elementFormDefault="qualified"

但是没有用.

推荐答案

我做了什么让它工作:

  1. 我将肥皂/信封模式导入到 wsdl 中
  2. 我获得了请求正文元素并从中创建了一个文档作为文档根
  3. 我向 body-元素添加了soap/envelope 命名空间

这篇关于使用 SOAPHandler 验证 SOAP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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