# Multi module communication in DWR frame work

**URL:** <https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174>\
**Category:** DWR users\
**Created:** [April 10, 2018, 11:51am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174 "2018-04-10T11:51:02Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 10, 2018, 11:51am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/1 "2018-04-10T11:51:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 11, 2018, 3:18pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/2 "2018-04-11T15:18:02Z")

</div>

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

> [@DWR 3 generated JS does not contain a path](https://discourse.dojo.io/t/dwr-3-generated-js-does-not-contain-a-path/154):
>
> I’m using DWR version 3.0.3-dev-665 with the AMD loader. I have multiple web components that each use DWR. The first component has no issues with DWR method calls. The second component always fails. DWR config for the second component is: \<servlet\> \<servlet-name\>dwr-invoker\</servlet-name\> \<servlet-class\>org.directwebremoting.servlet.DwrServlet\</servlet-class\> \<init-param\> \<param-name\>debug\</param-name\> \<param-value\>true\</param-value\> …

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

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 12, 2018, 6:12am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/3 "2018-04-12T06:12:09Z")

</div>

> [@DWR 3 generated JS does not contain a path](https://discourse.dojo.io/t/dwr-3-generated-js-does-not-contain-a-path/154/2):
>
> You only set p.\_path when you want to override the request path on an individual proxy.

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.  
Regards,  
madhu

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 12, 2018, 11:14am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/4 "2018-04-12T11:14:35Z")

</div>

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

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

```

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 [http://directwebremoting.org/dwr/documentation/server/configuration/servlet/multiconfig.html](http://directwebremoting.org/dwr/documentation/server/configuration/servlet/multiconfig.html)) 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.

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 12, 2018, 11:39am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/5 "2018-04-12T11:39:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 12, 2018, 12:01pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/6 "2018-04-12T12:01:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 12, 2018, 12:50pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/7 "2018-04-12T12:50:51Z")

</div>

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.

Regards,  
madhu

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 13, 2018, 2:54pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/8 "2018-04-13T14:54:32Z")

</div>

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:  
[http://dwr.2114559.n2.nabble.com/Anyone-have-DWR3-working-on-multiple-portlets-on-a-single-portal-page-tp7581141p7581143.html](http://dwr.2114559.n2.nabble.com/Anyone-have-DWR3-working-on-multiple-portlets-on-a-single-portal-page-tp7581141p7581143.html)

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 19, 2018, 10:49am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/9 "2018-04-19T10:49:59Z")

</div>

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.

Regards,  
madhu

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 23, 2018, 10:43am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/10 "2018-04-23T10:43:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 24, 2018, 6:13am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/11 "2018-04-24T06:13:42Z")

</div>

Hi Mikewse,  
This issue is resolved .  
Regards,  
madhu

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 24, 2018, 6:35am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/12 "2018-04-24T06:35:09Z")

</div>

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.

Regards,  
Madhu

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 24, 2018, 2:08pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/13 "2018-04-24T14:08:31Z")

</div>

> [@madhu](#):
>
> This issue is resolved

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.

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [April 25, 2018, 7:03am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/14 "2018-04-25T07:03:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 25, 2018, 9:29pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/15 "2018-04-25T21:29:51Z")

</div>

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:  
[http://requirejs.org/docs/api.html#multiversion](http://requirejs.org/docs/api.html#multiversion)

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [April 25, 2018, 10:11pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/16 "2018-04-25T22:11:12Z")

</div>

> [@madhu](#):
>
> 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.

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>
<script>
    C._path = "/dwr2";
    D._path = "/dwr2";
</script>

```

**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:

```
<servlet>
    ...
    <init-param>
        <param-name>org.directwebremoting.extend.Remoter</param-name>
        <param-value>my.package.MyRemoter</param-value>
    </init-param>
</servlet>

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

```

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.dojo.io/u/madhu)\
**Post date:** [May 3, 2018, 9:09am UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/17 "2018-05-03T09:09:39Z")

</div>

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 .

Regards,  
Madhu

---

<div class="post-metadata">

**Author:** ![mikewse](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mikewse](https://discourse.dojo.io/u/mikewse)\
**Post date:** [May 3, 2018, 12:50pm UTC](https://discourse.dojo.io/t/multi-module-communication-in-dwr-frame-work/174/18 "2018-05-03T12:50:06Z")

</div>

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.
