6.1.3. Request Dispatch Handler

This handler delegates processing to an action that describes the process to be performed for each function of the application. This handler is mainly a function for messaging, and is used for dispatching to an arbitrary action.

In this handler, the dispatch destination action is selected based on the request path acquired by Request#getRequestPath(). The request path format assumes the following:

Request path format: /<basePath>/<className>

Each of the parts enclosed by <> in the format above have the following meanings.

Label Meaning
basePath Base path representing the dispatch target
className Class name (required)

For example, when calling the class xxx.yyy.ExampleBatchAction, if the base path is batch, specify a request path like /batch/ExampleBatchAction.

Important

Normally, the request path acquired by Request#getRequestPath() is specified by the -requestPath option when launched in the command line as described in Common Launcher.

This handler performs the following process.

  • Parses the request path and calls the handle method of the corresponding action.

The process flow is as follows.

../../../../_images/flow6.png

6.1.3.2. Module list

<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-fw</artifactId>
</dependency>

6.1.3.4. Base package and base path settings

The base package for placing the dispatch destination class of this handler, and the base path added to the request path can be configured with the properties basePackage and basePath.

An example of configuring the base package to nablarch.application and the base path to /app/action is shown below.

<component class="nablarch.fw.handler.RequestPathJavaPackageMapping">
  <property name="basePath"    value="/app/action/" />
  <property name="basePackage" value="nablarch.application" />
</component>

6.1.3.5. Dispatch to classes of multiple packages

When dispatching using this handler, multiple dispatch destination classes can be allotted by specifying the request path. At this time, specify the relative package name from the base package in the location where the class name is specified with the request path.

For example, when Base package and base path settings is configured, specify /app/action/xxx/ExampleBatchAction in the request path when dispatching to the nablarch.application.xxx.ExampleBatchAction class.

6.1.3.6. Configuration of class name prefix and suffix

If you do not want to provide a class name prefix and suffix in the request path, the specification in the request path can be omitted by configuring classNamePrefix and classNameSuffix of this handler.

For example, when following the rule that specifies XxxProject as the prefix and BatchAction as the suffix, for a class name XxxProjectXxxxBatchAction, the request path can be omitted like /app/action/Xxxx by configuring as follows:

<component class="nablarch.fw.handler.RequestPathJavaPackageMapping">
  <property name="basePath"    value="/app/action/" />
  <property name="basePackage" value="nablarch.application" />
  <property name="classNamePrefix" value="XxxProject" />
  <property name="classNameSuffix" value="BatchAction" />
</component>

6.1.3.7. Dispatch to complex packages

The method shown in Dispatch to classes of multiple packages has a constraint that “the packages where actions are placed must be grouped into sub-packages under the same package”. This handler provides a method for separately configuring the package in which actions are placed for each request path when there is a problem with such a dispatch.

Consider an example where the following request path and dispatch destination are configured.

Request path Class to be dispatched
/admin/AdminApp nablarch.sample.apps1.admin.AdminApp
/user/UserApp nablarch.sample.apps2.user.UserApp
/BaseApp nablarch.sample.base.BaseApp

To perform such a dispatch, the optionalPackageMappingEntries is configured using the JavaPackageMappingEntry class as follows.

<component class="nablarch.fw.handler.RequestPathJavaPackageMapping">
    <property name="optionalPackageMappingEntries">
      <!-- Describe the combination of the request path pattern and Java package in the order to be matched. -->
      <list>
        <component class="nablarch.fw.handler.JavaPackageMappingEntry">
          <property name="requestPattern" value="/admin//" />
          <property name="basePackage" value="nablarch.sample.apps1" />
        </component>
        <component class="nablarch.fw.handler.JavaPackageMappingEntry">
          <property name="requestPattern" value="/user//" />
          <property name="basePackage" value="nablarch.sample.apps2" />
        </component>
      </list>
    </property>
    <!-- Java package used when there is no match for optionalPackageMappingEntries -->
    <property name="basePackage" value="nablarch.sample.base" />
</component>

6.1.3.8. Lazy execution of the class to be dispatched

By default, delegation to the dispatched class is performed immediately. If you want to delegate to the dispatched class after the execution of subsequent handlers on the handler queue, set the immediate property to false by referring to the following example.

<component class="nablarch.fw.handler.RequestPathJavaPackageMapping">
  <property name="basePackage" value="${nablarch.commonProperty.basePackage}" />
  <property name="immediate" value="false" />
</component>