Wednesday, May 29, 2013

Invalid chunk'=true' ignored warning message in Spring application.


Issue:

WARNING: Parameters: Invalid chunk '=true' ignored. is getting logged in the web application.

We have a web application developed using Spring, Struts2 & hibernate framework.

When we navigate from one tab to another tab within the application we get the below message logged in the log file. 
We have used the log4j for logging information within the application.


The warning message in the log file is mentioned below.

May 29, 2013 9:18:34 AM org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Invalid chunk '=true' ignored.



Resolution:

This message was logged in our application because we didn't have the name attribute for a hidden field.

code snippet that cased the warning message:

 <s:hidden id = "testid" value="true"></s:hidden>

to fix, we added the name attribute to this tag as

<s:hidden id="testid" name="testid" value="true"></s:hidden>


Though this is a warning message, sometime we don't want this warning message to be logged. The above solution can be applied.

refer the below link also for more explanation.

Friday, May 24, 2013

command to view the running process in Linux/Unix

In most of the web application deployed in linux/unix machine.

we may some time need to know, whether the process is running or not.

For example:
our application is deployed in Linux system and runs in tomcat server.
we use tomcat scripts to deploy the application (start/stop shell script).

it would always be good to verify whether the application is deployed and running in the server.

command to use

$ ps -ef

Note: ps - provide the snapshot of process status running in Linux/ unix os

- e and -f are generally known as switch for the command or options or selection.
            -e will select all the process running
            -f  will provide full format listing of the process.

there are more number of options for "ps" command use the below command to explore it

$ man ps

or

$ ps -help

On executing the command

Command #1
$ ps -ef

sample out put:

UID      PID     PPID C   STIME     TTY     TIME      CMD
root      1170  1139   0     09:42       pts/0    00:00:00   su - user1

user1     6021  1171  0    13:35        pts/0    00:00:00    ps -ef
user2     6022  1171  0    13:35        pts/0    00:00:00  -ksh

The Command #1 can output can be piped to grep to filter specific line to be displayed.

Example
Command #2
$ ps -ef | gerp user2

sample out put

user2     6022  1171  0    13:35        pts/0    00:00:00  -ksh

only returns the line that contains user2 (as we are greping for it in linux).

additionally use the below command combination to get the header also

Command #3
$ ps -ef | grep -e user2 -e PID

sample out put 
UID      PID     PPID C   STIME     TTY     TIME      CMD
user2     6022  1171  0    13:35        pts/0    00:00:00  -ksh

If the process needs to be killed we should use the PID number of the process. PID stands for process-id, every process in Linux has an process-id. For more information, we need to understand the Linux OS structure.

to kill the running process use the below command 

$ kill -9 6022

kill - command to kill the process
-9 is the option which force kills
PID process id which should be killed, in this case its 6022.

Note: always be cautious on using the kill command when killing a process. 


Tuesday, May 21, 2013

oracle query to return null when query returns no rows to return

Assume there is employee table (oracle 11g)

employee
empolyee_num   employeeName  department

10001                 ABC1                Sales
10002                ABC2                Accounts
10003                ABC3                Sales


employee_salary (employee# is foreign key)

employee_sal_id   employee_num  employee_salary
           1                   10001              1000
           2                  10002                1200

the below query

Query #1:
select es.employee_sal from employee emp, employee_salary es where emp.employee_num = es.employee_num
and emp.employee_num = 10003;

the above query will return no rows returned.

If the above query needs to return a null we can wrap the above query as below

Query #2:
select (select es.employee_sal from employee emp, employee_salary es where emp.employee_num = es.employee_num and emp.employee_num = 1000) as salary from dual;

this query will return a null instead of no row found.

If needed we can return a 0 instead of null using the nvl () function.

Query #3:
select nvl((select es.employee_salary from employee emp, employee_salary es where emp.employee_num = es.employee_num and emp.employee_num = 1000),0) as salary from dual;

Note:
There might be scenarios while working with procedures or function, if the WHERE clause condition didn't match the query possibly returns NO ROW FOUND and if i use the if clause to check for NULL the PL/SQL block would throw an error.

In my case,  i wanted to find the salary for the employee writing a procedure.
 in cursor i fetched the employee_num, then used this empolyee_num to a select query to get the salary and print in DBMS_OUT.

Create table using the below queries in ORACLE 11g


CREATE TABLE employee
(
   employee_num    NUMBER (10) CONSTRAINT pk_emp_num PRIMARY KEY,
   employee_name   VARCHAR2 (25),
   department      VARCHAR2 (20)
);




CREATE TABLE employee_salary
(
   employee_sal_id   NUMBER (10) CONSTRAINT pk_emp_sal_id PRIMARY KEY,
   employee_num      NUMBER (10),
   employee_sal      NUMBER (6, 2),
   CONSTRAINT fk_supplier FOREIGN KEY
      (employee_num)
       REFERENCES employee (employee_num)
);

Insert the values into the tables using below query:

insert into employee values(10001,'ABC1','Sales');
insert into employee values(10002,'ABC2','Accounts');
insert into employee values(10003,'ABC3','Sales');

insert into employee_salary values (1, 10001, 1000.00);
insert into employee_salary values (2, 10002, 1200.00);

Try executing the below PL/SQL block code:


DECLARE
   CURSOR cur_employee_num
   IS
      SELECT *
        FROM employee emp;

   curval1   cur_employee_num%ROWTYPE;
   salval    NUMBER (6, 2) := 0;
BEGIN
   OPEN cur_employee_num;

   LOOP
      FETCH cur_employee_num INTO curval1;

      EXIT WHEN cur_employee_num%NOTFOUND;

      IF curval1.employee_num IS NOT NULL AND curval1.employee_num > 0
      THEN
         SELECT employee_sal
           INTO salval
           FROM employee_salary
          WHERE employee_num = curval1.employee_num;

         IF salval > 0
         THEN
            DBMS_OUTPUT.put_line (
                  'Salary of employee '
               || curval1.employee_num
               || ' is = '
               || salval);
         END IF;
      END IF;
   END LOOP;

   CLOSE cur_employee_num;
END;
/


OUTPUT:
Error or exception:
ORA-01403: no data found

ORA-06512: at line 19

Salary of employee 10001 is = 1000
Salary of employee 10002 is = 1200



If i change the above PL/SQL block as below (refer the highlighted code below)

DECLARE
   CURSOR cur_employee_num
   IS
      SELECT *
        FROM employee emp;

   curval1   cur_employee_num%ROWTYPE;
   salval    NUMBER (6, 2) := 0;
BEGIN
   OPEN cur_employee_num;

   LOOP
      FETCH cur_employee_num INTO curval1;

      EXIT WHEN cur_employee_num%NOTFOUND;

      IF curval1.employee_num IS NOT NULL AND curval1.employee_num > 0
      THEN
         SELECT (SELECT employee_sal
                   FROM employee_salary
                  WHERE employee_num = curval1.employee_num)
           INTO salval
           FROM DUAL;

         IF salval > 0
         THEN
            DBMS_OUTPUT.put_line (
                  'Salary of employee '
               || curval1.employee_num
               || ' is = '
               || salval);
         END IF;
      END IF;
   END LOOP;

   CLOSE cur_employee_num;
END;
/

OUTPUT:

Salary of employee 10001 is = 1000
Salary of employee 10002 is = 1200
(there is no exception)

Query #3 can be used if a 0 to be returned instead of NULL in the highlighted query.




Tuesday, May 14, 2013

Java ResourceBundle to read properties file.

Java provide an class named ResuorceBundle to read the properties file.


Generally properties file is a simple key value file, which will be useful in software coding to extract the common code from the class files, like database connection attributes, queries, constants, etc. This will make the code easy for maintenance.

Below is a sample code piece on how to read the values from properties file using resourcebundle.


create a file named prop.properties, with the below contents

Filename  >>prop.properties<< (below are the contents in the file)

propkey1=propvalue1
propkey2=propvalue2


if using eclipse create a java project and use the below code in a class file.

File/java class name >>PropertyResourcebundEx<<

import java.util.ResourceBundle;

public class PropertyResourcebundEx {

public static void main(String args[])
{
//Below is the declaration to get the instance of the property file.
//the prop.properties file should be within the class path, as the resourcebundle can read the properties file.

//prop is the properties file name
// there is no necessity to provide the extension of the properties file as this file is within the class path.

ResourceBundle rsbundle = ResourceBundle.getBundle("prop");

//below is the code which will get the information of the prop file
//getSring() method of the resourcebundle will get the value of the key propkey1 from the property file
String PROP_VAL1 = rsbundle .getString("propkey1");
String PROP_VAL2 = rsbundle .getString("propkey2");

System.out.println("Propval1 & propval2 = " + PROP_VAL1+ " && "+ PROP_VAL2);
}
}

Output:
>> Propvalue1 & propval2 = propvalue1 && propvalue2

Note: if the prop.properties file is not within the class path, then we get the below exception:

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name prop, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.test.mail.PropertyResourcebundEx.main(PropertyResourcebundEx.java:12)

Thursday, May 9, 2013

favicon or custome icon display in web application

To display a favicon or custom icon or company logo icon on a web application.


We had an tomcat web application to include the favicon to it.

To display the icon we should use the

<link rel="icon" href="/favicon.ico">

the above should go within the html head. even if its a jsp file.

you can also use "type" attribute in the "link" tag, like below

<link rel="icon" href="/favicon.ico" type="image/x-icon">
also
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

shortcut and icon in rel attribute of the link tag identifies two relations icon and shortcut.
shortcut doesn't have a meaning.

the imgae favicon.ico : should be a 16x16 or 32x32 image. to design an icon you can use the http://www.xiconeditor.com/ 

put this the corresponding image locations in the application, provide the reference in the "href" attribute of "link" tag.

start the tomcat application after making the link reference.

clear the IE temporary files, histories, cookies. even from the favorite links.

provide the link of the application and the favicon will be displayed.

Wednesday, May 8, 2013

oracle exp (export command) for database dump

Whenever we need to export the data from oracle (version 11g) below command of oracle can be used:

Option #1:
use exp command:
> exp

in command prompt check whether the oracle exp command is configured to execute by typing exp.
the exp command will prompt for user id and password of oracle.

most of the time this won't work if the sid is not set correctly because exp could not identify the correct database.

to set the sid use the below command

> set oracle_sid=database_sid_name

Option #2:

use the parameter of exp command in command prompt:
> set oracle_sid=database_sid_name
> exp dbusername/password@dbname FILE=C:/database_dump.dmp

The above command will start exporting the database in to the file under the location mentioned in the command using FILE parameter.

output

. . exporting table         TABLENAME1          4 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
. . exporting table                      TABLENAME2       9441 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
. . exporting table             TABLENAME3       2830 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.