### Specifying report running properties in the session

When designing integration and security with your application, compared to putting all information in the URL, setting sensitive information in the session and letting the server fetch them when running reports is a more secure way.

JReport provides a key word JReport _running_parameter for holding property variables in the session. Users can set a string with this key word in the session before calling JReport services. The string should take the query string format used in URLs of running reports/dashboards and obey application/x-www-form-urlencoded format and be encoded by UTF-8.

When running reports or dashboards, JReport gets information first from URL and then picks up provided information from the session using the key words. For information that exists in both the URL and the session, the session setting overrides the URL settings.

#### For running reports via server JSP

For properties both in the URL and the session, the properties in the session will override those in the URL.

For properties only in the session, the properties will be appended to the URL to run the report.

Examples:

- Set parameter value in the session:

  HttpSession.setAttribute("JReport_running_parameter", "jrs.param$parameter1=xxx&jrs.param$parameter2=xxx...");

- Set dynamic connection in the session:

  HttpSession.setAttribute("JReport_running_parameter", "jrs.jdbc_driver=com.mysql.jdbc.Driver&jrs.jdbc_url=jdbc:mysql://IP:3306/test&jrs.db_user=xxx&jrs.db_pswd=xxx");

#### For running web reports via JSON

The following rules apply when merging each object from the session and from the URL:

- jrd_report
  Session overrides URL. Once this object is specified in the session, only the specified report can be run whenever the URL submits to run any report.
- jrd_catalog
  Session overrides URL.
- jrd_param$
  Session overrides the same-name parameters and appends the other parameters to the URL.
- jrd_userinfo
  Session overrides the properties in the object.
- jrd_datasources
  It should contain an object array and use "ds" as the key. The session overrides the objects with the same key and appends the other objects to the array.

Examples:

- Set parameter value in the session (JSON format):

  HttpSession.setAttribute("JReport_running_parameter", "jrd_param$={\"parameter1\":\"xxx\", \"parameter2\":\"xxx\"}");

- Set dynamic connection in the session (JSON format):

  HttpSession.setAttribute("JReport_running_parameter", "jrd_datasources=[{\"ds\":\"Data Source 1\", \"uid\":\"xxx\", \"pwd\":\"xxx\", \"type\":\"0\", \"url\":\"jdbc:mysql://IP:3306/test\", \"driver\":\"com.mysql.jdbc.Driver\"}]");

#### For running dashboards via JSON

The following rules apply when merging each object from the session and from the URL:

- jrd_resext
  For single properties, session overrides the properties in the URL and adds those not in the URL.
- reslst
  It should contain an object array and use "name" as the key. The objects with the same key plus dsh_params and dsh_datasources settings in the session will be appended to the object in the URL. Other objects from the session will be added to the array in the URL.

  For example:

  jrd_resext={"active":0,"reslst":[{"name":"/USERFOLDERPATH/admin/Dashboard1.dsh","dsh_params":[{"jrd_params":{"P_StartDate":"01/01/2006"}}]}]}

  Dashboard1.dsh will run with the parameter P_StartDate="01/01/2006".

  A user can set "JReport_running_parameter" in the session as:

  jrd_resext={"active":0,"reslst":[{"name":"/USERFOLDERPATH/admin/Dashboard1.dsh","dsh_params":[{"jrd_params": {"P_StartDate":"01/01/2007","P_EndDate":"12/31/2007"}}]}]}

  Dashboard1.dsh will then run with P_StartDate="01/01/2007" (applies the value setting from the session) and P_EndDate="12/31/2007" (append the other parameters from the session to the URL) for all library components.

Examples:

- Set parameter value in the session for a specific library component:

  HttpSession.setAttribute("JReport_running_parameter", "jrd_resext={\"active\":0,\"reslst\":[{\"name\":\"/62309_Session/62309.dsh\", \"dsh_params\":[{\"jrd_params\":{\"parameter1\":\"xxx\",\"parameter2\":\"xxx\"}}, {\"lc_names\":[\"s13dfc53ea67\"],\"jrd_params\":{\"parameter1\":\"xxx\",\"parameter2\":\"xxx\"}}, {\"lc_names\":[\"s13dfda08c0a\"],\"jrd_params\":{\"parameter1\":\"xxx\", parameter2:\"xxx\"}}]}]}");

- Set dynamic connection in the session for specific library components:

  HttpSession.setAttribute("JReport_running_parameter", "jrd_resext={\"active\":0,\"reslst\":[{\"name\":\"/62309_Session/62309_datasource.dsh\", \"dsh_datasources\":[{\"jrd_datasources\":[{\"ds\":\"Data Source 2\", \"uid\":\"root\", \"pwd\":\"1234\", \"type\":\"0\", \"url\":\"jdbc:mysql://IP1:3306/test\", \"driver\":\"com.mysql.jdbc.Driver\"}]}, {\"lc_names\":[\"/COMPONENT_LIB/62309_Session/62309_datasource.lc\"], \"jrd_datasources\":[{\"ds\":\"Data Source 2\", \"uid\":\"root\", \"pwd\":\"1234\", \"type\":\"0\", \"url\":\"jdbc:mysql://IP2:3306/test\", \"driver\":\"com.mysql.jdbc.Driver\"}]}, {\"lc_names\":[\"s13e0cdc04f2\"], \"jrd_datasources\":[{\"ds\":\"Data Source 2\", \"uid\":\"root\", \"pwd\":\"1234\", \"type\":\"0\", \"url\":\"jdbc:mysql://IP3:3306/test\", \"driver\":\"com.mysql.jdbc.Driver\"}]}]}]}");