骆驼验证不适用于肥皂弹簧靴

时间:2019-09-05 10:38:38

标签: spring-boot validation soap apache-camel url-scheme

我的骆驼(2.20.2)路线无法使用肥皂。然后需求说我们需要针对xsd验证soap请求。我尝试添加验证器组件:

from("direct:start").routeId("ValidatorRouter")
    .doTry()
        .to("validator:file:src/main/resources/student-details.xsd")
        .to("stream:out")
    .doCatch(ValidationException.class)
        .to("stream:out");
    <xs:element name="GetStudentDetailsRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name= "id" type="xs:int" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>  
        </xs:complexType>
    </xs:element>
     <dependency>
        <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.20.2</version>
        </dependency>

2019-09-05 16:02:05.849  INFO 20096 --- [  restartedMain] o.a.c.i.DefaultRuntimeEndpointRegistry   : Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000)
2019-09-05 16:02:05.922  INFO 20096 --- [  restartedMain] o.a.camel.spring.SpringCamelContext      : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2019-09-05 16:02:05.995  INFO 20096 --- [  restartedMain] o.a.camel.spring.SpringCamelContext      : Route: ValidatorRouter started and consuming from: direct://start
2019-09-05 16:02:05.995  INFO 20096 --- [  restartedMain] o.a.camel.spring.SpringCamelContext      : Total 1 routes, of which 1 are started.
2019-09-05 16:02:05.996  INFO 20096 --- [  restartedMain] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.19.2 (CamelContext: camel-1) started in 0.258 seconds
2019-09-05 16:02:06.043  INFO 20096 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2019-09-05 16:02:06.049  INFO 20096 --- [  restartedMain] ngBootTutorialSoapWebServicesApplication : Started SpringBootTutorialSoapWebServicesApplication in 7.332 seconds (JVM running for 8.694)
2019-09-05 16:03:00.288  INFO 20096 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'messageDispatcherServlet'
2019-09-05 16:03:00.288  INFO 20096 --- [nio-8080-exec-1] o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet 'messageDispatcherServlet': initialization started
2019-09-05 16:03:00.305  INFO 20096 --- [nio-8080-exec-1] o.s.ws.soap.saaj.SaajSoapMessageFactory  : Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
2019-09-05 16:03:00.362  INFO 20096 --- [nio-8080-exec-1] o.s.w.t.http.MessageDispatcherServlet    : FrameworkServlet 'messageDispatcherServlet': initialization completed in 74 ms
2019-09-05 16:03:01.020  INFO 20096 --- [nio-8080-exec-1] c.i.s.s.w.s.e.s.StudentDetailsEndpoint   : GetStudentDetailsRequest [id=0]

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stud="http://in28minutes.com/students">
   <soapenv:Header/>
   <soapenv:Body>
      <stud:GetStudentDetailsRequest>
         <stud:id>bbbbbbggfrty</stud:id>
      </stud:GetStudentDetailsRequest>
   </soapenv:Body>
</soapenv:Envelope>

学生ID仅允许int。如果有请求,则只有Int的ID会引发错误

1 个答案:

答案 0 :(得分:1)

我重新排列了您的路线代码,以更好地发现尝试/捕获。

由于路由中的try / catch块,验证是否成功无关紧要。在这两种情况下,您都转到.to("stream:out")

应该是这样

.doTry()
    .to("validator:file:src/main/resources/student-details.xsd")
    .to("stream:out")
.doCatch(ValidationException.class)
    [do someting else when the XML is not schema valid]
.end()