Dwr3.0 pure comments of pure Java Code configuration configuration and application

  • 2020-05-09 18:38:12
  • OfStack


//Annotation configuration dwr servletprivate void initializeDwrServlet(ServletContext container) 
{DwrServlet dwrServlet = new DwrServlet();
ServletRegistration.Dynamic dynamic = container.addServlet("dwr-invoker", dwrServlet    );
dynamic.setLoadOnStartup(2);
dynamic.setInitParameter("debug", "true");
dynamic.setInitParameter("pollAndCometEnabled", "true");
dynamic.setInitParameter("activeReverseAjaxEnabled", "true");
dynamic.setInitParameter("maxWaitAfterWrite", "1800000");
dynamic.setInitParameter("disconnectedTime", "60000");
dynamic.setInitParameter("classes", dwrAnnotationClasssConfiguration());
dynamic.addMapping("/dwr/*");}
// Configure Dwr Annotation Classes,comma separatedprivate String dwrAnnotationClasssConfiguration() {
StringBuffer config = new StringBuffer();
config.append("com.g360.bean.reconsole.opcost.AnnualOpCostRequestController");
config.append(",");config.append("com.g360.bean.security.SessionExpiredParam");
return config.toString();}

My configuration above is based on the annotated version of Dwr Servlet configuration (converting servlet configuration in web.xml to pure Java code configuration), as well as the classes where the front end and back end interact directly (

com. g360. bean. reconsole. opcost. AnnualOpCostRequestController, com. g360. bean. security. SessionExpiredParam

) also use annotation configuration (Dwr annotation configuration, including @RemoteProxy, @RemoteMethod), which may be easy to understand for students who have some basis of annotation configuration. For those who don't understand for the first time, please leave me a message.

com. g360. bean. security. SessionExpiredParam annotation configuration is as follows:


@Component("sessionExpiredParam")
@RemoteProxy(creator = SpringCreator.class, scope = ScriptScope.APPLICATION, name = "remote", creatorParams = @Param(name = "beanName", value = "sessionExpiredParam"))
 public class SessionExpiredParam{ 
private static final Logger LOGGER = LoggerFactory.getLogger(SessionExpiredParam.class); 
public boolean isSessionExpire (String sessionId) { 
return null == ConstantCacheService.getCacheConstant(sessionId); }
 @RemoteMethod public void setEnableDwrUpdate(String sessionId) {
  ScriptSession scriptSession = WebContextFactory.get().getScriptSession(); 
 String jsessionId = scriptSession.getHttpSessionId(); 
String dwrSessionId = scriptSession.getId(); 
LOGGER.info(String.format("set jsessionId = [%s],dwrsession = [%s] push enabled",jsessionId,dwrSessionId)); 
ConstantCacheService.putCacheConstant(Constants.PUSH_ID+jsessionId, dwrSessionId); 
} }

This is equivalent to the dwr.xml configuration file as follows:


<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd"><dwr> 
<allow> <create creator="new" javascript="remote" scope="application">  
 <param name="class" value="com.g360.bean.security.SessionExpiredParam"/> 
 </create> </allow></dwr>

For com. g360. bean. reconsole. opcost. 1 sample AnnualOpCostRequestController speaking truth, there is not much to do that;

For using DwrServlet to use pure annotation configuration (1. Do not use the dwr xml) need to pay attention to in the initialization parameter is set to 1 configuration classes this parameter, and the parameter is the full path name of the annotation class, there are multiple words separated by a comma, this is particularly important, because Dwr3. 0 as scanning does not support package, don't know what is the need to configure or what, can only be achieved if any guys just see, also just know 1, please leave a message tell grateful! You are welcome to leave a message at any time if you don't understand something or if you have something wrong.



Related articles: