All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.tornado.brap.spring.SpringProxyServlet Maven / Gradle / Ivy

package no.tornado.brap.spring;

import no.tornado.brap.servlet.ProxyServlet;
import no.tornado.brap.servlet.ServiceWrapper;
import no.tornado.brap.modification.ModificationManager;
import no.tornado.brap.modification.ChangesIgnoredModificationManager;
import no.tornado.brap.auth.AuthenticationNotRequiredAuthenticator;
import no.tornado.brap.auth.AuthenticationRequiredAuthorizer;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * This SpringProxyServlet is configured from web.xml for each service you wish
 * to expose as a remoting service.
 * 
 * You must refer to a bean in your applicationContext that provides the complete
 * ServiceWrapper.
 *
 * 

web.xml example of exposing a remoting service:

*
 *  <servlet>
 *      <servlet-name>hello</servlet-name>
 *      <servlet-class>no.tornado.brap.servlet.ProxyServlet</servlet-class>
 *      <init-param>
 *          <param-name>beanName</param-name>
 *          <param-value>helloRemoteService</param-value>
 *      </init-param>
 *      <load-on-startup>1</load-on-startup>
 *  </servlet>
 *  <servlet-mapping>
 *      <servlet-name>hello</servlet-name>
 *      <url-pattern>/remoting/hello</url-pattern>
 *  </servlet-mapping>
 * 
* *

applicationContext.xml example:

*
 *   <bean id="helloRemoteService" class="no.tornado.brap.servlet.ServiceWrapper">
 *       <property name="service" ref="helloService"/>
 *       <property name="authenticationProvider" ref="authenticationProvider"/>
 *       <property name="authorizationProvider" ref="authorizationProvider"/>
 *   </bean>
 *
 *   <bean id="authenticationProvider" class="no.tornado.brap.auth.SingleUsernamePasswordAuthenticator">
 *       <property name="username" value="john"/>
 *       <property name="password" value="secret"/>
 *   </bean>
 *
 *  <bean id="authorizationProvider" class="no.tornado.brap.auth.AllowAllAuthorizer"/>
 *
 *   <bean id="helloService" class="no.tornado.brap.test.service.HelloService"/>
 * 
* */ public class SpringProxyServlet extends ProxyServlet { private ApplicationContext applicationContext; public void createServiceWrapper() { applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext()); if (applicationContext == null) throw new RuntimeException("No WebApplicationContext found. Did you forget to add the ContextLoaderListener to web.xml?"); String beanName = servletConfig.getInitParameter("beanName"); if (beanName == null) throw new RuntimeException("You must provide the \"beanName\" init-param to the SpringProxyServlet."); serviceWrapper = (ServiceWrapper) applicationContext.getBean(beanName); if (serviceWrapper.getAuthenticationProvider() == null) serviceWrapper.setAuthenticationProvider(new AuthenticationNotRequiredAuthenticator()); if (serviceWrapper.getAuthorizationProvider() == null) serviceWrapper.setAuthorizationProvider(new AuthenticationRequiredAuthorizer()); if (serviceWrapper.getModificationManager() == null) serviceWrapper.setModificationManager( new ChangesIgnoredModificationManager()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy