MoreMotionRequest Class

Top  Previous  Next

When we develop services or other types of classes for MoreMotion environment we use org.moremotion.servlet.MoreMotionRequest class very often. MoreMotionRequest implements the javax.http.servlet.HttpServletRequest interface so it provides all the methods that HttpServletRequest provides and more.

Request Parameter Decoding

When a request is sent to the server the parameters existing in the request are encoded by the browsers using an encoding, e.g. ISO-8859-1. When an application server receives a request, it decodes these parameters and prepare a request object to pass to the Servlet.

If the application server does not use the same encoding that the browser used to encode the parameters during the decoding, the request parameters can get corrupted. Unfortunately this is the case for Tomcat. Tomcat always decode the request parameters using ISO-8859-1.

MoreMotion solves this problem with the help of a request parameter called _enc. This parameter should contain the encoding that was used in encoding the request parameters.

If you are getting the value of a request parameter from the MoreMotionRequest object, the parameters are converted using the value supplied with this _enc parameter.

  package mypack;
 
  import org.moremotion.servlet.*;
  import org.moremotion.action.*;
 
  public class MyActionService implements ActionService {
 
    public void doService(ActionServiceContext asc)
    throws ServiceException, java.io.IOException {
 
      MoreMotionRequest request = asc.getRequest();
      String name = request.getParameter("name",null);
      //..
    }
  } 

The name string will get the converted value of the "name" parameter.

However, some application servers can nicely guess the case and reads request parameters correctly. In that case you should disable the character conversion by setting a sysinfo.xml parameter to false.

Here is the section that you have to change:

  <param name="enableParameterConversion">true</param>

 

HttpServletResponse Objects

Since an MoreMotion programmer does not need to write directly to the HttpServletResponse, this object is not passed as a separate parameter to the other MoreMotion Classes. Most of the time you will have only MoreMotionRequest which contains all the necessary objects in it.

  import org.moremotion.servlet.*;
  import org.moremotion.action.*;
 
  class MyService implements ActionService {
 
    public void doService(ActionServiceContext asc) throws ServiceException, java.io.IOException {
 
      MoreMotionRequest request = asc.getRequest();
 
    } 

  }

 

MoreMotionRequest Methods

 
All the required objects can be accessed via the methods supplied by the MoreMotionRequest object.

 
Accessing to the HttpServletRequest object

HttpServletRequest hsr = request.getHttpServletRequest();

 

Accessing to HttpServletResponse object

HttpServletResponse response = request.getResponse();

 

 

Accessing to ServletContext object

ServletContext context = request.getContext();

MoreMotionRequest is one of the most important classes of the MoreMotion API since it provides a rich set of methods to perform the common tasks of a MoreMotion Service. See the examples below.
 

 

  // Accessing to the Request Parameters

  String name = request.getParameter("name","defvalue");

  int age = request.getParameterAsInt("age",22);

  boolean retired = request.getParameterAsBoolean("retired",false);

 

  // Accessing to the HttpServlet Objects 

  HttpServletResponse response = request.getResponse();

  HttpServletRequest httpRequest = request.getHttpServletRequest();

  ServletContext context = request.getContext();

 

  // Managing Cookies

  String val = request.getCookieValue("cookiename");

 

  int oneMonth = 60 * 60 * 24 * 30;

  request.setCookieValue("cookiename","cookievalue",oneMonth);

 

  // Creating Multi-lingual Messages (Creating Message ADOMs)

  request.createMessage("myunit","MY_MESSAGE",

                        new String[]{"argument1", "argument2"}, ex);

 

  // Displaying Pages

  request.generatePage("mypage");

  request.generateDefaultErrorPage(); 

 

 

  // Resolving MScript Functions

  String resolvedStr = request.resolve("Name is : @vof(name)"); 

 

  // Accessing Existing ADOMs

  ADOM adom = request.getSessionADOM("adomname");     

  ADOM adom = request.getApplicationADOM("adomname"); 

 

  // Creating new ADOMs

  ADOM adom = request.newRequestADOM("adomname");     

  ADOM adom = request.newSessionADOM("adomname");     

 

  // Removing ADOMs

  request.removeSessionADOM("adomname");