Posts

Showing posts from May, 2015

Spring WS - Part 5

Spring WS provides an easy integration with various WS-Security features with the help of interceptors like Wss4jSecurityInterceptor, XwsjSecurityInterceptor. We are going to explore here very basic feature of WS-SECURITY i.e. implementing Security using with UserNameTokenAuthentication We are going to use Wss4jSecurityInterceptor as it is very easy to configure. We are going to use configure two interceptors: 1) One for the Server End. 2) Other for the Client End. For Server End The configuration for Wss4jSecurityInterceptor is as follows: @Bean public Wss4jSecurityInterceptor wss4jSecurityInterceptor() { /** * The SecurementActions for UsernameToken is commented, as the * UsernameToken is to be added by the client, the server-side * interceptor would only validate that. * */ Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor(); wss4jSecurityInterceptor.setValidationActions("UsernameToken");

Spring WS - Part 4

Another interesting and essential feature is the attachment part. Now I found two things out here. The attachment can be inline within the SOAP message body (suitable as long as the attachment size is not too long) or we can enable MTOM feature within the marshaller and leverage the MTOM-XOP feature. For the attachment to be inline with the SOAP message body, no actual configuration are required, everything is being taken care by the Spring WS framework, except the following: &ltxs:element name="getCountryRequest"&gt &ltxs:complexType&gt &ltxs:sequence&gt &ltxs:element name="name" type="xs:string"/&gt &ltxs:element name="file" type="xs:base64Binary" xmime:expectedContentTypes="application/octet-stream"&gt&lt/xs:element&gt &lt/xs:sequence&gt &lt/xs:complexType&gt &lt/xs:e

Spring WS - Part 3

Now let's go into little details of the whole App So from the Client Controller, we invoke the service with the help of WebServiceTemplate after contructing appropiate request model. The configuration for WebServiceTemplate can be found in SpringWSApplicationConfig.java . It can be seen that in the request model we are attaching a file. We have used MTOM here for the attachment purpose, which we will discuss in detail in upcoming posts. So the requuest before reaching the specified endping, which is being determined by EndpintMapping implementation passes through a series of interceptors configured in SpringWSApplicationConfig.java in addInterceptors bean. I have used here two Spring WS in-built interceptors: 1) SoapEnvelopeLoggingInterceptor.java 2) PayloadLoggingInterceptor.java They are basically logging interceptors and one Custom interceptor i.e. CountryInterceptor.java The code for Custom interceptor is already provided above. Now to use Custom inter

Spring WS - Part 2

The Service endpoint class is: @Endpoint public class CountryEndpoint { static final Logger log = LoggerFactory.getLogger(CountryEndpoint.class); private static final String NAMESPACE_URI = "http://spring.io/guides/gs-producing-web-service"; private CountryRepository countryRepository; /*@Autowired public CountryEndpoint(CountryRepository countryRepository) { this.countryRepository = countryRepository; }*/ @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest") public void getOriginalDetails(@RequestPayload GetCountryRequest request) throws Exception { log.debug("***** Web Service Endpoint is Hit ****** "); DataHandler fileDataHandler = request.getFile(); log.debug("The DataHandler is {}",fileDataHandler); log.debug("The ContentType {}, {}-----> {}",fileDataHandler.getContentType(),fileDataHandler.getDataSource().getClass(),fileDataHandler.getAllCommands().toString()); InputSt

Spring WS - Part 1

So lets start..... My configurations files are as follows: 1) SpringWSApplicationInitializer.java 2) SpringWSApplicationConfig.java Instead of web.xml I am using WebApplicationInitializer public class SpringWSApplicationInitializer implements WebApplicationInitializer { static final Logger log = LoggerFactory.getLogger(SpringWSApplicationInitializer.class); public void onStartup(ServletContext servletContext) throws ServletException { // TODO Auto-generated method stub log.debug(" ********* Spring WS Application StartUP in Progress............ ********** "); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(SpringWSApplicationConfig.class); /** * Configuring MessageDispatcherServlet for Spring Web Services * */ ServletRegistration.Dynamic dispatcherWS = servletContext.addServlet("springws", new MessageDispatcherServlet(context)); dispatcherWS.setIni

Spring Web Services

Recently I was trying to explore Web Services using Spring i.e. Spring WS. So I went through the official documentation of Spring WS and after traversing it a bit I found it quite easy to configure and the concept of Contract First Web Services makes it more interesting keeping in mind all the real time situations. So I decided to prepare a demo application to get an idea about its various features and believe me starting from configuring to testing my first Spring-based web services was really cool except in some places where I got stuck like the endpoint url for invoking the Web Services as the service endpoint url for invoking the web services and the one present in the generated WSDL are not identical, so I had a little hard time in figuring the right endpoint url for invoking the service. The WSDL generated here from a xsd with the help of a Spring injected (in Configuration File SpringWSApplicationConfig.java ) bean seems to me more of a request response format fo