Is it possible to use Spring Validators to validate data from Web Services Soap requests? Or more so what should I change about the below approach to make it possible?
The precise context that I have is below:
I have a web front end using Freemarker and Controllers that works fine with validation for example using
<bean id="stockValidator" class="com.client.validator.StockValidator" />
In the dispatcher-servlet.xml
Then in the StockController the validation occurs on Post requests.
@RequestMapping(value = "/addStock", method = RequestMethod.POST)
public String addStudent(@ModelAttribute Stock stock,BindingResult result,
ModelMap model ) {
StockValidator.validate(stock, result );
if (result.hasErrors()) {
//model.addAttribute("stock", stock);
return "stock";
} else {
StockService.save(stock);
model.addAttribute("stockId", stock.getStockId());
model.addAttribute("stockCode", stock.getStockCode());
model.addAttribute("stockName", stock.getStockName());
return "result";
}
}
However my SOAP web services are Annotation based wired into the services
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import com.olympus.viewtheworld.server.dao.StockDao;
import com.olympus.viewtheworld.server.service.StockService;
import com.olympus.viewtheworld.shared.domain.Stock;
@WebService(endpointInterface = "com.server.service.StockService")
public class StockServiceImpl implements StockService{
@Autowired
StockDao stockDao;
This is mapped in the dispatcher servlet as such:
<jaxws:endpoint id="stockService"
implementorClass="com.server.service.Impl.StockServiceImpl"
implementor="#stockServiceImpl"
address="/SoapService/stock">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory"/>
</jaxws:serviceFactory>
</jaxws:endpoint>
Sorry I am a hobby developer and think that somewhere along the way I have got a bit confused in how best to approach this setup. If it is more appropriate to start again from scratch let me know.
Cheers, Rob
You might want to look into Spring Web Services (http://projects.spring.io/spring-ws/). With that you can use PayloadValidatingInterceptor to run XSD-based validation on incoming SOAP messages.
I'm just adding example of how to use @Jukka's suggested PayloadValidatingInterceptor.
You can PayloadValidatingInterceptor to intercept requests and validate it with XSD schema. E.g. (applicationContext.xml):
<sws:interceptors>
<!-- Add our validating interceptor -->
<ref bean="validatingInterceptor" />
</sws:interceptors>
<bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="schema" value="classpath:org/example/myproject/xsd/myprojectws.xsd"/>
<property name="validateRequest" value="true"/>
<property name="validateResponse" value="true"/>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With