Saturday, 21 April 2012

most Asked j2ee questions


What servlet container and JDK is used in J2EE Public Service?
Apache Tomcat, release 5.5.23 running on Java SDK version 6.
What Servlet/JSP specification versions are supported?
The supported specification versions are: Servlet 2.4 and JSP 2.0.
My webapplication uses EJB, can I host it in the J2EE Public Service?
Apache Tomcat is not an EJB server. It is a Servlet container so EJBs are not supported directly by the J2EE Public Server. 
A solution to use EJBs in the J2EE Public Service is to use OpenEJB. It is a project developed by the Apache Software Foundation which allows to use EJBs with Tomcat server (Tomcat 5 or 6 ). For more information, please visit the project website OpenEJB.
Web Application Archive (war) contains all files of a web application. In fact, it is a zip archive of application files with a specific structure. Read more here about the structure of the war file and how to create it manually.
J2EE Public Service provides a production (not development) platform and the applications should be thoroughly tested before deploying them on the service. However, there is no test machine available. The solution is straightforward: it's very simple to set up a test enviroment on your PC. Follow the instructions:
  1. Make sure you have a JDK 6 installed on your PC; if you don't, then download it from here(click "download JDK 6" ) and install it.
  2. Make sure that JAVA_HOME environment variable points to your JDK 6 installation.
  3. Download the container from here: jps-tomcat-5.5.23-oracle-jdbc-10.2.0.3.zip.
  4. Unzip it to a folder of your choice, this folder will be referred to as $CATALINA_HOME.
  5. Use:
       $CATALINA_HOME\bin\catalina.bat start -security
    or (depending on your operating system):
       $CATALINA_HOME\bin\catalina.sh start -security
    to start tomcat
  6. Simply copy your web application archive (.war) file to $CATALINA_HOME/webapps directory to deploy your application
After that, your application will be accessible on your PC on port 8080. Make sure to include -security option when you start tomcat to check, if your application works with J2EE Public Service security manager.
Follow the instructions:
  1. Make sure you have a JDK 6 installed on your PC; if you don't, then download it from here(click "download JDK 6" ) and install it.
  2. Make sure that JAVA_HOME environment variable points to your JDK 6 installation.
  3. Download the container from here: apache-tomcat-6.0.18-oracle-jdbc-10.2.0.3.zip.
  4. Unzip it to a folder of your choice, this folder will be referred to as $CATALINA_HOME.
  5. Use:
       $CATALINA_HOME\bin\catalina.bat start -security
    or (depending on your operating system):
       $CATALINA_HOME\bin\catalina.sh start -security
    to start tomcat
  6. Simply copy your web application archive (.war) file to $CATALINA_HOME/webapps directory to deploy your application
After that, your application will be accessible on your PC on port 8080. Make sure to include -security option when you start tomcat to check, if your application works with J2EE Public Service security manager.
I need to create a temporary file from a servlet/jsp. Where can I write it?
Every Tomcat container has read/write access to its temp directory. To be sure that your solution is portable, don't use any hardcoded file paths. Instead, use the following:
   java.io.File tempFile = java.io.File.createTempFile("test",".tmp");   tempFile.deleteOnExit();
If you have any further doubts, consult the API.
My application uses custom libraries. Where should I upload the jar files?
Please all jar files you use in the WEB-INF/lib/ directory in the war file. Mind you, some libraries (see below) come with the container so you don't have to (and should not to) bundle them with your application.
Can I use NICE authentication? How should I authenticate/authorize my users?
NICE authentication is the default way to go. Please see the following technical recommendation on authorization/authentication using CERN Authentication.
What libraries are available by default?
The following libraries are available by default to every application.
  • Basic runtime classes provided by the Java Virtual Machine, version 6
  • Libraries which come with Apache Tomcat, release 5.5.23:
    • commons-el.jar - Jakarta commons el, implementing the expression language used by Jasper.
    • jasper-compiler.jar - The JSP 2.0 compiler.
    • jasper-compiler-jdt.jar - The Eclipse JDT Java compiler.
    • jasper-runtime.jar - The JSP 2.0 runtime.
    • jsp-api.jar - The JSP 2.0 API.
    • naming-factory.jar - The JNDI implementation used by Tomcat 5 to resolve references to enterprise resources (EJB, connection pools).
    • naming-factory-dbcp.jar - Jakarta commons DBCP, providing a JDBC connection pool to web applications. The classes have been moved out of their default org.apache.commons package.
    • naming-resources.jar - The specialized JNDI naming context implementation used to represent the static resources of a web application. This is not related to the support of the J2EE ENC, and cannot be removed.
    • servlet-api.jar - The Servlet 2.4 API. servlet-api.jar
  • Oracle drivers, version 10.2.0.3:
    • ojdbc14.jar
    • orai18n.jar
There are three most common problems when using connection pooling:
  1. You're not closing your Connection objects.
  2. You're not closing your ResultSet, Statement, PreparedStatement or CallableStatement objects.
  3. The connection in the pool gets broken.
The first two problems lead to resource leak. 

Number 1 will block your application, as you reach the maximum number of connections. Therefore, i'ts very important to close the Connection objects, because only then are they returned to the pool and can be reused by your application. 

Number 2 makes cursors stay on the database side, which will block the entire database, when the cursor limit is hit. 

There are two useful tools that let you investigate the problems on the database side:http://service-oracle.web.cern.ch/service-oracle/help/session-manager.php and ViewDB. Use them to get a hint of a forgotten Connection/Statement/Resultset and/or review your code to fix the problem.

You can also use the following DBCP parameters to make let DBCP recover these abandoned connections (see below for more on DBCP parameters): 
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"

Number 3 is more tricky, as there can be many reasons for the connection to be broken. The symptoms are the following: you sometimes get a database error, but when you click "refresh" the error is gone.

The solution here is to configure connection pool in such a way that it checks the connection before it's used. We're recommending use of Apache Jakarta Commons DBCP, as explainedhere. Normally, setting the following DBCP parameters fixes the problem: 
testOnBorrow="true"
validationQuery="select sysdate from dual"

If these settings are not optimal for you, please check DBCP parameter documentation to choose best settings for your scenario.
We provide you two solutions depending on your requirements:
1._ DFS library: On demand (J2EE Public Service Support), we provide you a library that uses WebDAV to connect the Distributed File System (DFS). The limitation of this solution is that the source code of your java webapplication will have to be modified in order to use use this library.
2._ AFS repository: An AFS repository will be assigned to your webapplication. This AFS repository is a directory where you can store your data files and configure your webapplication to access to it as part of the file system. For more information, consult Using AFS as permanent storage solution .

No comments:

Post a Comment