Showing posts with label Resolution. Show all posts
Showing posts with label Resolution. Show all posts

Sunday, October 30, 2011

Issues with not getting the effect of code updates


Problem Statement:
Customer is not able to see the effect of latest code updates in Production Environment.

Ok, what is the bug here?
Web-server is not restarted after code deployment.

How the problem was identified?
I got a call from the customer saying that they have deployed the latest code updates.  But, they are not able to see the effects.  Then, I have compared the files of both environments (Development and Production).  Both files are matched including their timestamp.  Later, we have verified the updates in Production environment by converting the class files into java files by using decompiler.  The latest code updates are available.  Once again, I recollected the steps for the deployment of latest source code.  Then, I thought that they might be missed to restart the web-server after completion of deployment.  Then, I have restarted the web-server and verified the system.  Now, everything is fine.

Verify the result of REST web-service


Problem Statement:
Customer has given an URL and said the following information.  The URL acts as a web-service.  We need to pass a ZIP file name as an argument along with this URL.  The URL verifies that whether the specified ZIP file is available in the system or not.  If it is available, the URL will give the response as a string with the same ZIP file name.  Otherwise, it throws an exception.  

Ok, what is the difficulty here?
The system is not having any sample ZIP files.  We should not do any more testing with the URL as the URL is related to production system.  We should deliver the code that should be suitable for the requirement and the same code will be tested in live environment only once.

How did overcome the problem?
First, I have gone through the Utility packages that are available in the project source code.  I found the code that is useful to access REST web-service URL.  Now, I want to check whether the URL is related to REST web-service or Web-service.  We know that we can see the result of the REST web-service by specifying the URL in the browser.  Then, I specified it in browser.  Present browser is not displaying anything.  I felt that this might be because of proxy settings.  Then, I tried with another browser.  Then, I found “FileNotFoundException” in the browser.  Then, I confirmed that the URL is related to REST web-service but not related to web-service.  As webservice is more secured, we cannot trace the result of URL by using the browser.

Solution provided:

Quick solution provided:  -NA-

Suggested solution: 
We have implemented the code based on REST web-service access.

Issues with apostrophe symbol as part of document name


Problem Statement:
quoted string not properly terminated.

Ok, what is the bug here?
Application is not getting the documents which are related to the specific model.

How the problem was identified?
I have gone through the log files to know the origin of the problem.  Log file is getting updated with the above specified error.  Later, I have tried to replicate the same issue with a sample program.  Finally, I came to know that the issue is related to Java’s Statement interface.  If we want to use apostrophe in middle of SQL statement, we should specify another apostrophe.  If we prepare SQL statement with Java's Statement interface, we should care about this apostrophe issue.  If we use Java's PreparedStatement instead of Java's Statement, we need not worry about this issue.  Java takes care about this.

Solution provided:

Quick solution provided:
I have updated the database by removing the special character.

Suggested solution: I have updated the java code as below.

Previous Code: -
Statement stmt = con.createStatement();
String sQueryDocData = "SELECT * FROM DOC_ATTACHMENTS WHERE DOC_ID = "+ docId +" AND DOC_ATTACH_NAME = '" + sDocAttchName +"'";
ResultSet rs = stmt.executeQuery(sQueryDocData);

Updated Code: -
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM DOC_ATTACHMENT WHERE DOC_ID = ? AND DOC_ATTACH_NAME = ?");
pstmt.setInt(1, docId);
pstmt.setString(2, sDocAttchName);
ResultSet rs = pstmt.executeQuery();

For Example: - String sDocAttachName = "doc's.txt";

Issues with Connection Pooling in Tomcat/JBoss


Problem Statement:
One of the application is showing the below error message while accessing the application.  The application is raising this bug for every three or four months.

Ok, what is the bug here?
Cannot get a connection, pool exhausted error.

How the problem was identified?
First of all, I came to know that the problem is related to connection pooling, by observing the above specified error message details in log file.  I wanted to replicate the problem to identify the origin of the bug.  Then, I have gone through the project to verify the settings related to connection pooling.  I have identified an entry maxActive related to Connection Pooling as part of DB configuration settings.  The entry specifies the maximum number of connections that are available in connection pool.  To identify the bug, I have minimized its value from 200 to 5.  Then, I have tested the each and every operation at least 6 times.  Out of all operations, I found the above error at one operation.  The operation is throwing error as the operation is not getting an open connection.  So, I felt that the operation might be missed the close_connection statement. 
Then, I have gone through the code in that specific flow.  I found the closeConnection statement, but, it is referring the class/global variable.  In fact, the usage of class/global variable is very less in that java program.  Then, I removed the class/global variable and created the local variables when ever required.

Solution provided:

Quick solution provided:
*) Restart the web/application server. [and/or]
*) Enable removeAbandoned flag which is related to Connection Pooling as part of DB configuration settings.

<!-- To configure a DBCP DataSource so that abandoned dB connections are removed and recycled add the following paramater to the ResourceParams configuration for your DBCP DataSource Resource: -->

<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

<!--Use the removeAbandonedTimeout parameter to set the number of seconds a dB connection has been idle before it is considered abandoned.   -->

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value> 
</parameter>                                


Suggested solution:
Removed the class/global variable and created the local variable.

Saturday, October 29, 2011

Conflicts between Employee Names in DataBase and Web-Services


Problem Statement:
One of the end-users is not able to see the DOCs which were assigned to her.

Ok, what is the bug here?
DOCs are not appearing to them.

How the problem was identified?
I had a discussion with that specific end-user who is unable to see her DOCs.  I came to know that she is facing this problem recently after one incident, i.e. her name was slightly updated by HR department.  Before that update, she has seen all her DOCs.  First, I have verified the Database whether the DOCs are available to that person. Yes.  DOCs are available to that person.  Later, I have gone through the code to find out the origin of getting Employee names.  Database is having the employee names in the format of Emp_Name(Emp_ID).  When ever the end-user login the application, application is getting her Emp-Name and Emp-ID from two different webservices and making them in the format of Emp_Name(Emp_ID) and verifying the same with Database to identify the DOCs related to that person.  By observing the log files, I came to know that the both names are mismatching in case of this end-user.  Because, Database is having old name and web-service is giving updated name.

Solution provided:

Quick solution provided:
I have updated the Database with new name.  Now, both names are matched and end-user able to see the DOCs.

Suggested solution:
SQL statements are updated slightly from Emp_Name(Emp_ID) to %(Emp_ID).  Now, SQL statement is getting the DOCs by verifying Emp_ID instead of verifying the entire format Emp_Name(Emp_ID).

JavaScript code issues with special characters in URL


Problem Statement:
Browser is showing “Page cannot be found” error for only one document.

Ok, what is the bug here?
Browser is not able to trace the document using the specified URL.

How the problem was identified?
I have verified the database whether the specified document is available or not.  Later, I have taken the document name from database and replaced the document name from the part of the URL in the browser. Then, I can see the document in the browser. Finally, I came to know that the problem is with special characters which are the part of the document name.

Solution provided:

Quick solution provided:
I have updated the database by removing the special character.

Suggested solution:
I have updated the javascript code as below to handle special characters in URL.
Previous Code: -
location.href = “<%=url%>”;
Updated Code: -
location.href = escape(“<%=url%>”);

Thursday, June 9, 2011

How to append timestamp at end of the log4j.jar related log files, along with RollingFileAppender....?

Configure the following entry in properties file: -

log4j.appender.R=org.apache.log4j.MyDateRollingFileAppender

Compile the following program in log4j.jar folder and add the same class file to classpath: -
//  Compatible with  log4j.jar   1.0.4


package org.apache.log4j;

import java.io.File;
import java.io.FilenameFilter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.text.SimpleDateFormat;

/**
 *  Referenced classes of package org.apache.log4j:
 */
/**
 * RollingFileAppender, Layout
 */
public class MyDateRollingFileAppender extends RollingFileAppender {

public MyDateRollingFileAppender() {
}

/**
* @deprecated Method MyDateRollingFileAppender is deprecated
*/

public MyDateRollingFileAppender(Layout layout, OutputStream outputstream) {
super(layout, outputstream);
}

/**
* @deprecated Method MyDateRollingFileAppender is deprecated
*/

public MyDateRollingFileAppender(Layout layout, Writer writer) {
super(layout, writer);
}

public MyDateRollingFileAppender(Layout layout, String s, boolean flag)
throws IOException {
super(layout, s, flag);
}

public MyDateRollingFileAppender(Layout layout, String s)
throws IOException {

super(layout, s);
}


    /**
* It rollsOver each time after exceeding the MaxFileSize limit by appending
* the current time stamp to the new Log file
*
* @return void
*/
public synchronized void rollOver() { // rollOver() method has been
// overridden for customized
// functionality


try {

if (maxBackupIndex > 0) {

File[] listOfFiles = locateFile(super.fileName);

/**
* checking the condition to delete the oldest/last log file
*/
if ((listOfFiles != null) && (listOfFiles.length > 0)
&& (listOfFiles.length == (maxBackupIndex + 1))) {

File fileToBeDeleted = listOfFiles[listOfFiles.length - 1];

if (fileToBeDeleted.exists()) { // Deletes the Oldest LOG file.

fileToBeDeleted.delete();
}
}

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS");
String timeNow = dateFormat.format(new Date());

File oldFile = new File(super.fileName);
File newFile = new File(super.fileName + "." + timeNow);

closeWriterIfOurs();

                /**
* checking the condition for renaming the older file prior to
* the new file
*/
if (oldFile.exists()) { // Renames the Current working file from
// store_ext.log to store_ext.log.<TimeStamp>.

oldFile.renameTo(newFile);
}

setFile(super.fileName, false); // Creates the new working file
                           // for logging purpose.
}
} catch (Exception ex) {

System.out.println(ex.toString());
ex.printStackTrace();
}

}

/**
* locateFile groups the log file and sort based on the descending order of
* timeStamp
*
* @param strFileNameWithPath
* @return fileNames
*/

public File[] locateFile(String strFileNameWithPath) throws Exception {

File extractFile = new File(strFileNameWithPath); // Actual File
final String FILE_NAME = extractFile.getName();

/**
* create a FilenameFilter and override its accept-method
*/
FilenameFilter filefilter = new FilenameFilter() {

public boolean accept(File dirName, String fileName) {

/**
* if the file starts with file name return true, else false
*
*/
return fileName.startsWith(FILE_NAME); // To get list of files
// starts with specific  FILE_NAME
}
};

File fileNameWithPath = new File(strFileNameWithPath);
File dirName = fileNameWithPath.getParentFile();
File[] fileNames = null;

if (dirName.isDirectory()) {

/**
* Get the list of files in the directory.
*/

fileNames = dirName.listFiles(filefilter);
/**
* Sort the files in the array, based on filter.
*/
Arrays.sort(fileNames, new Comparator() {
public int compare(final Object o1, final Object o2) {
return new Long(((File) o2).lastModified())
.compareTo(new Long(((File) o1).lastModified()));
}
});

}
return (fileNames);
}
}

Thursday, March 31, 2011

Drawback of PreparedStatement.....?

select * from TABLE1 where COL_ID in ( 9489215, 9489216) 

 Here, we can not assign the values 9489215, 9489216.