Tuesday, September 27, 2011
i18n - Creating Property files
In order to support multiple language(internationalization), it is required to have separate label property files for each of the supported language in the application. Here I have detailed how you can create the property file for an additional language.
· Copy the contents of the english property file to an excel sheet.
· Have key and English label in two different columns.
· Add a new column for Japanese label
· Send this excel sheet to customer and ask them to fill in the Japanese label column with the Japanese equivalent for each English label. Customer would be happy to type the labels in an Excel sheet than in any other format.
· Once you receive the updated sheet from the customer remove the English label column.
· Add an equal to (=) symbol between the key and Japanese label columns. Add a new column in the sheet for this.
· Now save this sheet as Unicode Text. Select this as the file type in the Save As popup in Excel sheet.
· Now close excel sheet, open the file in Notepad++ and examine the file. Please make any corrections if you find any and save. (You will be seeing other language text as squares when you open it in notepad++). Change the encoding type to UTF-8 from the Format menu before saving.
· Open command prompt.
· Execute the command native2ascii to convert the native characters to Unicode characters. Eg: native2ascii -encoding UTF-8 propertyfile.txt propertyfile.properties. (please set the path to jdk/bin folder if you are unable to locate the command native2ascii.
· The generated file will contain the Unicode characters and you can directly use it in the application for supporting Japanese language.
· Copy the contents of the english property file to an excel sheet.
· Have key and English label in two different columns.
· Add a new column for Japanese label
· Send this excel sheet to customer and ask them to fill in the Japanese label column with the Japanese equivalent for each English label. Customer would be happy to type the labels in an Excel sheet than in any other format.
· Once you receive the updated sheet from the customer remove the English label column.
· Add an equal to (=) symbol between the key and Japanese label columns. Add a new column in the sheet for this.
· Now save this sheet as Unicode Text. Select this as the file type in the Save As popup in Excel sheet.
· Now close excel sheet, open the file in Notepad++ and examine the file. Please make any corrections if you find any and save. (You will be seeing other language text as squares when you open it in notepad++). Change the encoding type to UTF-8 from the Format menu before saving.
· Open command prompt.
· Execute the command native2ascii to convert the native characters to Unicode characters. Eg: native2ascii -encoding UTF-8 propertyfile.txt propertyfile.properties. (please set the path to jdk/bin folder if you are unable to locate the command native2ascii.
· The generated file will contain the Unicode characters and you can directly use it in the application for supporting Japanese language.
Labels: i18n
Wednesday, September 29, 2010
Axis2 1.5 ConnectionPoolTimeoutException & Solution
We use axis2 1.5.1 for webservices. We used to get the below exception when multiple users are connected to the application simultaneously. Once you get this exception the webservice becomes unresponsive and the application goes down.
Caused by: org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)
The reason for this exception is that Axis2 keeps an Http Connection Pool in the configuration context which is used for making webservice calls. This pool is maintained by axis and its default size is two. If more than two webservice calls are made at the same time, then axis2 will throw this exception after waiting for some time.
This exception is likely to happen in any application that uses Axis2 1.5.1 when concurrent users are accessing the system.
Solution for this is to set the context properties REUSE_HTTP_CLIENT and AUTO_RELEASE_CONNECTION to true for releasing and reusing the used connections. And set the HttpClient as shown below.
import org.apache.axis2.client.Stub;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
private void setContextProperties(Stub stub) {
ConfigurationContext context = stub._getServiceClient().getServiceContext().getConfigurationContext();
context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
context.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true);
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(20); //Set this value as per your need.
multiThreadedHttpConnectionManager.setParams(params);
HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
}
You may refer the link http://osdir.com/ml/axis-user-ws.apache.org/2010-01/msg00135.html for more details.
Caused by: org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:199)
The reason for this exception is that Axis2 keeps an Http Connection Pool in the configuration context which is used for making webservice calls. This pool is maintained by axis and its default size is two. If more than two webservice calls are made at the same time, then axis2 will throw this exception after waiting for some time.
This exception is likely to happen in any application that uses Axis2 1.5.1 when concurrent users are accessing the system.
Solution for this is to set the context properties REUSE_HTTP_CLIENT and AUTO_RELEASE_CONNECTION to true for releasing and reusing the used connections. And set the HttpClient as shown below.
import org.apache.axis2.client.Stub;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
private void setContextProperties(Stub stub) {
ConfigurationContext context = stub._getServiceClient().getServiceContext().getConfigurationContext();
context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
context.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true);
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setDefaultMaxConnectionsPerHost(20); //Set this value as per your need.
multiThreadedHttpConnectionManager.setParams(params);
HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
}
You may refer the link http://osdir.com/ml/axis-user-ws.apache.org/2010-01/msg00135.html for more details.
Labels: Axis2, ConnectionPoolTimeoutException, Webservice
Saturday, February 13, 2010
Architecture/Design Guidelines
Below is a few points which need to be considered while arhitecting or designing an enterprise application
1. Use multi tiered architecture
2. Reduce coupling between components
3. Increase component cohesion
4. Identify areas of expected high frequency changes and design to facilitate maitenance
5. Identify the reusable components
6. Documentthe architecural goals and constraints
7. Avoid using platform/vendor specific components
8. Avoid using third party components unless there are specific reasons
9. Identify interfaces to external device or applications
10. Define the projected data volume from the business requirements for an extended time period.
11. Identify all the specific hardware and software needs
12. Define the performance benchmark and design accordingly. Plan for continuous performance tests during development.
13. Address all the non functional requirements at the time of design.
14. Concurrency, Security and Transaction management are to be addressed.
15. Follow standard OOAD guidelines
16. Follow standard Design Patterns to avoid common problems.
1. Use multi tiered architecture
2. Reduce coupling between components
3. Increase component cohesion
4. Identify areas of expected high frequency changes and design to facilitate maitenance
5. Identify the reusable components
6. Documentthe architecural goals and constraints
7. Avoid using platform/vendor specific components
8. Avoid using third party components unless there are specific reasons
9. Identify interfaces to external device or applications
10. Define the projected data volume from the business requirements for an extended time period.
11. Identify all the specific hardware and software needs
12. Define the performance benchmark and design accordingly. Plan for continuous performance tests during development.
13. Address all the non functional requirements at the time of design.
14. Concurrency, Security and Transaction management are to be addressed.
15. Follow standard OOAD guidelines
16. Follow standard Design Patterns to avoid common problems.
Labels: Architecture, Design
Wednesday, February 10, 2010
Data Archival Mechanisms
The first step in planning a data archival is to decide on a data retention period. It is always better to select the retention period such that no data is required from the archival db and live db together for any of the operations in the application. The user should also be prevented from entering old dates before the retention period in the report selection screens.
Common Archival mechanisms used are
CDC (Change Data Capture)
Oracle Streams(built on top of CDC)
CDC - When any insert/update/delete event happens in the prod db, it allows us to update the info in another db. It is possible to write scripts to catch the event, process the data and update in the archive db.This will not affect the performance of the prod db much as its not done synchronously like triggers. When we write script to copy the data to archive db, we need to exclude the delete events. Another scheduled job will have to be written to remove the old data from the live db.
Oracle Streams - is built on top of CDC. It does the propagation of data to the archival db automatically. Here we can copy all the data changes from live db excluding the delete events through some configurations. The scripts for deleting old data from live db will have to be written and run as a scheduled job.
Both these methods keeps archived data as well as the operational data in the archive db. Production db will have only the operational data. There may be a slight delay in synchronizing the production db and archive db which is neglegible.
These features[CDC/Streams] are not available in all the version/edition of oracle. So before deciding upon a archival method, need to ensure that the feature is available in the oracle version used.
Another method for archiving is to write scripts to move the data to archive db and run the script as a scheduled job.
There may be a situation where the customer have a requirement which needs data from both production db as well as archival db. for eg: statistical reports. In case of CDC or Streams the archival db contains the entire data ie the production data plus the old data. In this case for statistical reports which requires old data, can connect to the archive db to show the reports. The db connection can be selected on the basis of the date range entered in the screen to achieve this.
When the sql script method is used for archival, we will have to connect to both the dbs, when generating reports with a date range selection. Instead of connecting to both dbs from the application we can create views which takes a union of data from the production db and archive db. Parameterized views can be used to increase performance in such a scenario.
Labels: Data Archival, Oracle
Friday, February 5, 2010
Observer Pattern
Observer Pattern
Participants : Observer,Subject
An observer listens to the changes that happen to an observable subject.
Observer pattern is useful when a notification is to be sent to a group of objects when any state change happens to a subject.
Objects which listen to the state changes of a subject is called Observer.
Java provides the following classes to implement a Observer design pattern
java.util.Observable - The subject should extend this class
java.util.Observer - The observer/listener class should extend this class
useful methods are
java.util.Observable
addObserver - to add a new observer
deleteObserver - to delete an observer
setChanged - to mark the subject as changed
notifyObservers - to notify the observers about state change
java.util.Observer
update - called whenever the observed method is changed
Participants : Observer,Subject
An observer listens to the changes that happen to an observable subject.
Observer pattern is useful when a notification is to be sent to a group of objects when any state change happens to a subject.
Objects which listen to the state changes of a subject is called Observer.
Java provides the following classes to implement a Observer design pattern
java.util.Observable - The subject should extend this class
java.util.Observer - The observer/listener class should extend this class
useful methods are
java.util.Observable
addObserver - to add a new observer
deleteObserver - to delete an observer
setChanged - to mark the subject as changed
notifyObservers - to notify the observers about state change
java.util.Observer
update - called whenever the observed method is changed
Labels: Design Pattern, Observer
Saturday, January 30, 2010
Architecture
Definition of Architecture
1. An architecture is the set of significant decisions about the organization of a software system, the selection of the structural elements and their interfaces by which the system is composed, together with their behavior as specified in the collaborations among those elements, the composition of these structural elements and behavioral elements into progressively larger subsystems, and the architecture style that guides this organization these elements and their interfaces, their collaborations, and their composition.
2. The fundamental organization of a system, embodied in its components, their relationships to each other and the environment, and the principles governing its design and evolution.
3. A formal description of a system, or a detailed plan of the system at component level to guide its implementation.
4. The structure of components, their inter-relationships, and the principles and guidelines governing their design and evolution over time.
Labels: Architecture
Thursday, September 10, 2009
Embeddable Google Document Viewer
Embeddable Google Document Viewer: "Google Docs offers an undocumented feature that lets you embed PDF files and PowerPoint presentations in a web page. The files don't have to be uploaded to Google Docs, but they need to be available online.
Here's the code I used to embed the PDF file:
<iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
but you should replace the bold URL with your own address. As I mentioned, the document viewer works for PDF and PPT files.
Some other sites that offer similar features: Zoho Viewer, PdfMeNot.
Here's the code I used to embed the PDF file:
<iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
but you should replace the bold URL with your own address. As I mentioned, the document viewer works for PDF and PPT files.
Some other sites that offer similar features: Zoho Viewer, PdfMeNot.
Subscribe to Posts [Atom]