DWR 3 generated JS does not contain a path

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>
        </init-param>
        <init-param>
            <param-name>scriptCompressed</param-name>
            <param-value>true</param-value>         
        </init-param>
        <init-param>
            <param-name>amdDwrBaseModulePath</param-name>
            <param-value>mydwr</param-value>
        </init-param>
        <init-param>
            <param-name>amdInterfaceBaseModulePath</param-name>
            <param-value>myapp</param-value>
        </init-param>
        <init-param>
            <param-name>amdDtoBaseModulePath</param-name>
            <param-value>mydata</param-value>
        </init-param>
        <init-param>
            <param-name>generateDtoClasses</param-name>
            <param-value>dto</param-value>
        </init-param>
        <init-param>
            <param-name>activeReverseAjaxEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name>
            <param-value>org.directwebremoting.impl.PollingServerLoadMonitor</param-value>
        </init-param>
        <init-param>
            <param-name>overridePath</param-name>
            <param-value>myOverriddenPath</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>`

In my JSP, I include my required modules like so:

require(djConfig, 
      [ "dojo/parser", 
        "dojo/ready", 
        "mydwr/engine", 
        "myapp/Class1", 
        "myapp/Class2",
        "mydata/Bean1",
        "mydata/Bean2"
      ], 
function(parser, ready, terminaldwr, MyClass1, MyClass2){
    ready(function() {
        mydwr.setAsync(true);
        SomeGlobalClassName = MyClass1;
        SomeOtherGlobalClassName = MyClass2;
        ...
    });
});

When SomeGlobalClassName calls one of its remote methods, the call fails and the server replies with either a session timeout error or a TextHTML error. However, if I debug and break inside the DWR-generated JS file (/myOverriddenPath/dwr/amd/interface/MyClass1.js), I see this:

define(["mydwr/engine"], function(dwr) {
  var p;

  p = {};

  /**
   * @param {class java.lang.String} p0 a param
   * @param {class java.lang.String} p1 a param
   * @param {boolean} p2 a param
   * @param {function|Object} callback callback function or options object
   */
  p.myMethod = function(p0, p1, p2, callback) {
    return dwr.engine._execute(p._path, 'Class1', 'myMethod', arguments);
  };

  return p;
});

As we can see, the _path property of p is never set. If I break before the execution of this function and use the console to set p._path = dwr._pathToDwrServlet, then the remote call succeeds.

My question is why is this _path property not being set when the JS is generated, or is there something else I need to do in the configuration to make this work?

The generated JS is not supposed to contain a p._path assignment any more. You only set p._path when you want to override the request path on an individual proxy. When it is left undefined DWR will use the global settings.

Regarding your problem I can see that you have overridden the global path setting in web.xml:

    <init-param>
        <param-name>overridePath</param-name>
        <param-value>myOverriddenPath</param-value>
    </init-param>

This will instruct DWR to send its Ajax requests to “/myOverriddenPath” instead of to the DWR servlet’s configured contextPath/servletPath. Note that this setting will not configure DWR to actually appear on the new path but assumes you are using path rewriting in your web server setup or similar.

As things start working when you assign p._path = dwr._pathToDwrServlet (the value of the servlet’s configured contextPath/servletPath) I would guess you have a problem with your path overrides or path rewrites.

You’re absolutely right, Mike. My path should have been /myOverriddenPath/dwr. That change seems to have fixed things.

Thanks!

A post was merged into an existing topic: Multi module communication in DWR frame work