Multi module communication in DWR frame work

Hi Mikewse,
I have multiple module having different dwr.xml.
while calling DWR interface from module 1 to Module 2 . The p._path value is not setting in the DWR interface in dwr 3.0.0 -final version , but the p._path is setting in dwr.3.0.0-RC3 version.
please let me know any changes need to do it in engine.js

First please read the discussion about p._path in this thread:

and then get back and tell us if there is still something you need to solve.

Hi Mikewse,
can you explain me how i can override the p._path variable in the request , I don’t want globally setting in web.xml. because in my scenario module 1 is call the same path like module1 path . few cases only call the modlue 2 path.
if you provide the sample code for set p._path override in the request it self.

This will helpful for my requirement.

This is how you set the _path field on your DWR interface before making a call:

<script src="dwr/interface/Demo.js"></script>
  Demo._path = "/my/custom/path";
  Demo.sayHello(a, b); 

It is still not clear to me if this is the right thing to do in your case. If you have multiple DWR modules (as described on the interface proxy objects from the different modules already use the correct path by default. Please post relevant parts of your code to illustrate what you are trying to do.

Hi Team, we are migrating from 3.0.0-RC3 to 3.0.0 FINAL version. we have multiple modules in our project.
Individual modules are working fine.
Inter module communication is not working.
example :
module 1 calling the module 2 of dwr interface vice versa .
this scenario dwr call is failing we are getting SEVERE: Class not found: ‘YYYYYYY_XXXX’.
The ‘YYYYYYY_XXXX’ interface is available in module 2.
While debugging engine.js dwr.engine._pathToDwrServlet having path of module1 instead of module2 due to this we are getting Class not found: ‘YYYYYYY_XXXX’.
Please provide any suggestions or solutions

Please try to use the correct name of things. DWR modules never call DWR modules. Javascript code in pages make calls to DWR interfaces, and DWR interfaces belong to DWR modules.

Maybe you are saying that you have a page whose code makes calls to interfaces belonging to multiple DWR modules?

Hi Mikewse,
Yes your right ! mikewse, I have page and calling multiple dwr modules
The dwr.engine._pathToDwrServlet is not modifying in dwr-3.0.0-final version.
previously dwr 3.0.0.-RC3 version inter module communication work fine.


Please stop referring to this as “inter module communication” as you are confusing everybody, including myself. There is never any communication between DWR modules.

The scenario with one page doing <script> includes of DWR resources from multiple modules was never supposed to work, but accidentally worked in some DWR versions. It has never been supported. The problem is that each DWR module is a standalone DWR instance with its own engine.js. You need to include the engine.js from each DWR module, but with <script> tags they will use the global namespace and overwrite each other.

You can hack this by only including one module’s engine.js and then setting _path on the interface proxies from the other module. But this is still not a supported setup and the risk is that you will hit some other problems further down the road.

My main suggestion is that you try to simplify your app to use only one DWR module per page.
If that doesn’t work, and you still need to use multiple DWR modules in one page, then you must use a script inclusion technique that doesn’t use the global namespace so you can include both engine.js without interference. One solution is to load DWR resources using an AMD script loader, and here is a discussion about exactly that:

Hi mikewse.
as you said , I’m setting the path p._path value , call going through dwr interface. but the respone we are getting the dwr.engine.remote.handleBatchException({ name:‘java.lang.SecurityException’, message:‘CSRF Security Error (see server log for details).’ }, ‘1’);
becuase i have enable the crossDomainSessionSecurity falg is true in web.xml

please give any suggestion for this issue.


Is this error happening for calls to both DWR instances or just on the one where you override p._path?

Please check your log and give us the stacktrace corresponding to the “CSRF Security Error” exception you’re getting.

Hi Mikewse,
This issue is resolved .

Hi Mikewse,
previous dwr -3.0.0 -RC3 jar version is working with out setting path variable . The one page is calling with different module dwr call it was working . after migrating dwr 3.0.0 -Final version is failing . i have around 700 different module dwr call are available .So it is difficult to set the p._path variable for each dwr call , Please let me know comman place to set the p._path variable or other way i can do it.


First let me know what is resolved, and what problems remain, if any. Also tell us how your problems were resolved so other people may benefit. If you want free help on this forum then you need to put an effort into describing your problems in as much detail as possible.

Hi Mikewse,
we are using the engine.js and XX.js both having the same content some modules are using engine.js loading ,some modules are using the xx.js is inclueded in jsp .some other modules are using both js files . if fist load the engine.js after that XX.js loading this time we will get the error from server dwr.engine.remote.handleBatchException({ name:‘java.lang.SecurityException’, message:‘CSRF Security Error (see server log for details).’ }, ‘1’);.
for this issue fix we are loading only engine,js file instead of xx.js file . now this issue got resolved.

So are you saying that XX.js is a copy you made of engine.js? As I said above you shouldn’t include two copies of engine.js in the same namespace as they will interfere with each other, so it makes sense that things are working better now.

Again, the correct way would be to use something that isolates the two DWR instances from each other, such as the AMD/require.js multiversion feature:

There are many ways to solve this, but remember that you will still be running an unsupported configuration when you use _path hacking to target another DWR instance.

Javascript solution (easiest)

You don’t have to set _path before every call, it’s enough to do once in one html or script file. F ex:

<script src="/dwr1/engine.js"></script>
<script src="/dwr1/interface/A.js"></script>
<script src="/dwr1/interface/B.js"></script>
<script src="/dwr2/interface/C.js"></script>
<script src="/dwr2/interface/D.js"></script>
    C._path = "/dwr2";
    D._path = "/dwr2";

Java solution (a bit more complexity)

You can implement the old behaviour by plugging in your own Remoter instance in web.xml that adds the _path assignment to every interface file. Code below is just a sketch and you need to fine tune the details yourself:


class MyRemoter extends DefaultRemoter {
    public String generateInterfaceJavaScript(String scriptName, String indent, 
            String assignVariable, String contextServletPath) throws SecurityException {
            super.generateInterfaceJavaScript(scriptName, indent, assignVariable, 
            assignVariable + "._path = '" + getPathToDwrServlet(contextServletPath) + "';";

Hi Mikewse,
it is difficulty to set the path for 700 dwr calls and testing all 700 dwr calls . i’m new to exisiting project , So it is difficulty to test the 700 dwr calls.
i have create the one js file and added the few interfaces
please let me know where i can update or modify only one place for example engine.js or any comman place . this will help reduce the testing effort .


If you don’t already have tests for all the functionality in your product/site then that’s a totally different problem domain and something you need to work on in your development process. There’s no framework tweaking that will help you with that.

It seems to me you are new to both your project, to Javascript development and to web development best practices. My previous post contains all the information you need to continue using DWR in the unsupported way you have chosen, both with a Java and a Javascript solution. This forum is not going to do your work for you so if you can’t find your way using these instructions then I recommend that you hire some help. Someone experienced with Javascript and web development would easily be able to find several different alternatives for you using my instructions.