DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. Direct Web Remoting tips

Direct Web Remoting tips

Wayne Adams user avatar by
Wayne Adams
·
Oct. 05, 11 · Interview
Like (0)
Save
Tweet
Share
6.71K Views

Join the DZone community and get the full member experience.

Join For Free

We use DWR (http://www.directwebremoting.org) a lot where I'm working now. It's a Java library used to integrate JavaScript-based web development with Java middleware. In addition to providing a servlet that creates a nice JavaScript library (that delegates to your server-side Java beans), it also does server push (reverse Ajax) in a variety of flavors and situations. I'm really happy with it; you kind of just put it in your application and it works without a lot of trouble.

I recently had to dig a little into the source to learn how to do something I think might be generally useful (how to change, in real time, parameters which are typically only set via init-params in web.xml), so that's the topic here. If you aren't a DWR user, this might not be very interesting!

In my case, I needed to change DWR's maxWaitAfterWrite parameter, a DWR servlet init-param. Normally you set this once in web.xml, with:

<init-param>
<param-name>maxWaitAfterWrite</param-name>
<param-value>5000</param-value>
</init-param>
(maxWaitAfterWrite refers to the amount of time DWR waits, after output has occurred, before closing the browser connection). DWR has an org.directwebremoting.Container class which is used to inject properties, including this one, but no immediately obvious API for changing it during an active deployment.

As it turns out, DWR's IoC container is accessible from its org.directwebremoting.ServerContext, and this is the path to changing this parameter, at least. The Container holds a number of beans. Some of these are java.lang.Strings (for example, the initial value of maxWaitAfterWrite) and are read-only, but some of these are DWR classes with APIs that you can use to your advantage.

As I mentioned, the value of maxWaitAfterWrite from web.xml is injected into a Container bean of type java.lang.String and named maxWaitAfterWrite. However, this parameter is itself injected at deployment time into any DWR class which extends org.directwebremoting.dwrp.BasePollHandler. You can iterate over the beans in Container and find (on my deployment, at least) two beans which are instances of BasePollHandler. Below is some code which gets a reference to the Container and iterates over its beans, outputting the details on the maxWaitAfterWrite bean and any instances of BasePollHandler:
package com.adamsresearch;

import java.util.*;
import org.directwebremoting.*;
import org.directwebremoting.dwrp.*;

public class JavaEndpoint
{
 public JavaEndpoint()
 {
   ServerContext sc = ServerContextFactory.get();
   Container cont = sc.getContainer();
   Collection beanNamesColl = cont.getBeanNames();
   Iterator beanNames = beanNamesColl.iterator();
   while (beanNames.hasNext())
   {
     String nextBeanName = beanNames.next();
     if (nextBeanName.equals("maxWaitAfterWrite"))
     {
       System.out.println("Bean name:  '" + nextBeanName + "'");
       String staticBean = (String)cont.getBean(nextBeanName);
       System.out.println("  Class:  java.lang.String");
       System.out.println("  Value:  '" + staticBean + "'");
     }
     else
     {
       Object nextBean = cont.getBean(nextBeanName);
       if (nextBean instanceof BasePollHandler)
       {
         System.out.println("Bean name: '" + nextBeanName + "'");
         System.out.println("  Class:  " + nextBean.getClass().getName());
       }
     }
   }
 }
}

If you add a method to this Java bean and invoke it from DWR, when the constructor is called, you should see output like the following:
 Bean name:  'maxWaitAfterWrite'
   Class:  java.lang.String
   Value:  '500'
 Bean name: 'url:/call/htmlpoll/'
   Class:  org.directwebremoting.dwrp.HtmlPollHandler
 Bean name: 'url:/call/plainpoll/'
   Class:  org.directwebremoting.dwrp.PlainPollHandler

As subclasses of BasePollHandler, HtmlPollHandler and PlainPollHandler inherit the method setMaxWaitAfterWrite(). For my particular situation, then, I just grab all BasePollHandlers from the DWR Container (via their bean names, as output above) and set the parameter as needed.

This isn't rocket science, but it took me 2 or 3 hours to learn this, and there aren't any hits on the subject AFAIK. So, hopefully this will be useful to someone out there!

 

From http://wayne-adams.blogspot.com/2011/10/direct-web-remoting-tips.html

Bean (software) Spring Framework

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Are the Different Types of API Testing?
  • gRPC on the Client Side
  • OpenVPN With Radius and Multi-Factor Authentication
  • MongoDB Time Series Benchmark and Review

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: