Reputation: 1
My camel(2.20.2) route is not working with soap. Then requirement says we need to validate soap request against xsd. I try adding validator component:
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>
Student Id only allow int. if request, id with only Int others will throw error
Upvotes: 0
Views: 171
Reputation: 7005
I rearranged your route code to spot the try/catch better.
Because of your try/catch block in the route, it doesn't matter if validation fails or not. In both cases you move on to .to("stream:out")
It should be like this
.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()
Upvotes: 1