Application Server


1) How can I get access to the properties of my running WebLogic server that have been set inside the weblogic.properties file? In particular I am after the document root of my server.
In WebLogic 5.1, to gain access to the weblogic properties, you can use the ConfigServicesDef interface which is accessible from the T3Client. The particular property that you are after is :
 weblogic.httpd.documentRoot
You may need to pre-pend the following properties to get the full path
 weblogic.system.home
 weblogic.system.name
The following is some sample code that should get you going
import weblogic.common.*;
public class SimpleT3Client {
public static void main(String[] argv) throws Exception {
T3Client t3 = new T3Client("t3://localhost:7001");
t3.connect();
String prop = t3.services.config()
.getProperty("weblogic.httpd.documentRoot");
t3.disconnect();
}
}
2) What is the difference between WebLogic Express server and WebLogic server?

WebLogic Express is a "cut-down" version of the WebLogic Server and contains the JDBC connection pool and Servlet functionality but amongst others, does not contain an EJB Container or transcation services.

3) What are the tradeoffs between using a single JRE versus running multiple, separate instances of the JVM for a complex application like an application server?
One of the major problems with JVM is garbage collection. When running small, short-lived applications there are not significant problems with Garbage Collection.
However, in the case of an Application Servers, which must service clients for long durations, memory usage is high and the amount of work required by the Garbage Collector is in turn high. This can lead to the following problems: Slow Garbage Collection or the Garbage Collector taking large amounts of time/resources to complete its' cycles.
So, for scalability, it is better to run multiple VMs - making each VM use only 100 - 200 megs of memory.
4) How do I configure my Application Server to show a different Error page upon an exception from a JSP or Servlet?
There should be one answer to this question that works for all 2.2 compliant servlet containers. The answer is to edit the web.xml deployment descriptor for your web app and add an error-page tag. The error-page tag tells the container the location of a page to return when an exception or error occurs. You can use the same mechanism to return customized error pages based either on a specific exception that is thrown, or based on the HTTP status code that is returned. The tag looks like this:

java.lang.NullPointerException
myPage.html

Or

500
myPage.html

5) When are stubs & skeletons created for my EJB components? is it at development time, deployment time or run time?
The time of creation of stubs and skeletions for EJB components varies from server to server.
The creation of stubs and skeletons for the popular servers is outlined below:
Inprise Application Server 4.x
The stubs and skeletons can be created during development time, for development and testing with the command line utility of with JBuilder. The stubs and skeletons for the EJB can also be created during deployment using the IAS Console. There is also an option to create a Client Jar file. The Client Jar file contains the necessary stubs and interfaces for the EJB which a client requires to invoke the EJB.
WebLogic Server 4.5.x, 5.x
The stubs and skeletons are created at deployment time using the command line utility called weblogic.ejbc. In WebLogic 5.x, there is also a Deployer Tool available that will invoke the ejbc utility automatically.
jBoss Server
In jBoss, the stubs and skeletons are not required to be generated by the developer or deployer. The Server takes care of the creation and downloading of stubs.
6) What are the features/limitations of Container Managed Persistnce with Weblogic 5.x. Are there any recommendations when using it?
 You can't specifiy storage of objects. For instance, Oracle 8i does support storage of objects, i.e Blobs and Clobs.
 You are limited to the String objects and a few other primitive types. (For storage of arrays of values, you may need to find a work around. )
 An Entity Bean can only map to one table, if more complex joins are required, you may require a more complex persistence manager( such as CocoBase or TopLink)
7) In WebLogic 4.51 and 5.x, what is the weblogic.system.executeThreadCount used for? What is its maximum and recommended value(s)?
The weblogic.system.executeThreadCount property is used to configure the number of execute threads inside the execute thread pool that service requests made to the WebLogic server. The maximum value for this parameter is operating system dependent and recommended setting will vary upon your application behavior.
A general strategy for determining the optimal value for your system is to monitor your CPU utilization whilst running a test application.
If the WebLogic server is not responding to requests made from a client, and the CPU utilization is not at least 75% +, then you should increase the value and re-run the test.
8) Is there an example of writing a WebLogic CMP EJB that has a user-defined finder method with multiple parameters?
For Weblogic 5.1 the finder method is written as follows:
findByAccount(String str,String str1)
For the above finder method we write in the deployment descriptor:

findByAccount

java.lang.String
java.lang.String


< ! [CDATA[(& (= name $0) (= address $1))]]>

9) What is a weblogic.properties file? How can I create a new one?
The weblogic.properties file is used to configure the Weblogic server. It is used in versions 5.x and previous. In version 6.0, it has been deprecated and replaced with an xml file (config.xml).
The weblogic.properties file is a plain text file that follows the standard Java property file format - see this FAQ for more details. All configuration information for the Weblogic server is placed inside this file, including:
 Deployments of EJB's and Servlets
 Definitions of JDBC Connection Pools and DataSources
 System configuration - Port and Address settings
 Security and Access Control List definitions
An example of a property from a weblogic.properties file is as follows:
weblogic.system.listenPort=7001
To create a new weblogic.properties file, simply create a new text file with the name weblogic.properties.
10) In WebLogic 5.x, how can I turn off logging to the console window?
You can do this by setting the following property in your weblogic.properties file
weblogic.system.enableConsole=false
11) What is a third party tool?
First party tools would be something you create yourself. Second party tools would be tools you buy from a vendor, like an IDE. Third party tools are tools for use with second party tools that aren't from the second party vendor. Think of them as add-ons to make second party tools more useful.
12) How do you deploy EJB components inside the iPlanet Application Server?
The iPlanet deployment tool, is in my opinion, the simplest way to deploy EJBs. However, for a more flexible and faster way using command line, the process is the following:
Example assumes bean called Foo
1. Compile your source files: Foo.java, FooHome.java,
2. 2. Generate the stubs using ejbc.exe. The format is: usage (typical): EJBC
usage (RMIC mode): EJBC -rmic
options:
-sl Compile as stateless session bean
-sf Compile as stateful session bean
-cmp Compile as CMP entity bean
-iiop Generate additional CORBA classes
-gs Generate java source files
-d Output directory
-help Show this message
-rmic Generate RMIC code (see usage)
-cp Set classpath
-javaccp Prefix to javac classpath
3. Place your files and the compiled stubs in a directory along with the XML descriptors in a Jar compliant directory structure.
4. Generate a jar file (Foo.jar) that contains the descriptors, the stubs, your class files and the manifest.
5. Execute ejbreg as follows: ejbreg Foo.jar

This will register the bean. You will still need to make sure that the jar file is in iPlanet's classpath (kregedit for NT, edit kjs in Unix)
13) In WebLogic, How I can set my own property name and value in the weblogic.properties file and read that properties from a my code?
To do this, prepend your property with java.system.property.
and access your property using the System class. For example, if we have a property called "website" then we would add it to our property file as follows:
java.system.property.website=www.jguru.com
The code used to access this property would be as follows:
String s = System.getProperty("website");
14) In Weblogic, where do you find the classes for the javax.naming and javax.sql packages?
In WebLogic 5.1, these packages are located in
\lib\weblogicaux.jar
In WebLogic 6, they are located in
\lib\weblogic.jar
15) In WebLogic 5.1, what options are there for Session Persistence? How do they compare in relation to performance, and level of fail-over?
There are four different implementations of session persistence:
1. Memory (single-server, non-replicated)
2. File system persistence
3. JDBC persistence
4. In-Memory replication (across a cluster)

For customers who want the highest in servlet session persistence, JDBC-based persistence is the best choice.
For customers who want to sacrifice some amount of session persistence in favor of drastically better performance, in-memory replication is the appropriate choice.
JDBC-based persistence is noticeably slower than in-memory replication. In some cases, in-memory replication has outperformed JDBC-based persistence for servlet sessions by a factor of eight.
16) When calling an EJB from another EJB should they both be packaged in same JAR?. Are the any preferences for Weblogic or any other servers?
Definitely not. You can use any object published in JNDI by looking up it by name, obtain reference to it and narrowing this reference. As far as I know this can be done with any J2EE compatible server.
The only possible catch is to have the client classes available to the calling bean.
17) Which WebLogic 4.5x/5.x property is used to control the number of queued requests inside the WebLogic server?

The property that you are looking for is weblogic.system.acceptBacklog

18) When I try load *.jsp files, I see the source code of each JSP files in my browser, what is wrong?
You can only load a JSP file through you webserver, if you open them by hand the browser will show the Java code inside the HTML file. By starting you Tomcat (or an other JSP / Servlet engine) the server will compile the JSP and will send a 'normal' HTML file to you browser that will behave as you coded it in the Java code between the HTML tags.
If you did start the JSP / Servlet engine but you are still seeing the JSP code then the server mappings are wrong. The engine does not know that it should compile the JSP file that is requested and simple shows the complete file. In the Tomcat engine this is specified in the server.xml file in the conf directory. The server.xml should contain this:


jsp


org.apache.jasper.runtime.JspServlet


-2147483646


This piece of XML tells the Tomcat server that it must use the JspServlet class when a JSP file is requested. The JspServlet then checks if the JSP file is compiled or not.
19) What can I do if my Servlet is receiving a NullPointerException when accessing init parameters via the ServletConfig object in WebLogic?

Make sure that your Servlet calls super.init(config) inside the init() method.
e.g.

public void init(ServletConfig config) {
...
super.init(config);
...
}
20) How are Servlets and JSP's deployed inside WebLogic?
Place all your Servlet Class files in the following directory weblogic/myserver/servletclasses/ Add the following lines in your weblogic.properties file
weblogic.httpd.register.servlets=weblogic.servlet.ServletServlet
and weblogic.httpd.servlet.classpath= /weblogic/myserver/servletclasses/
Place all your JSP's in the following directory weblogic/myserver/public_html
21) In a Weblogic CMP EJB, how to obtain the maximum value in the specified database column? In WLQL is there something similar to MAX() function in SQL?
dont know how to write in WLQL. Another solution is to write the query using SQL inside the weblogic-cmb-rdbms-jar.xml file.






findByOrgn


java.lang.String
orgnCode


SQL

< ! [ CDATA[SELECT * FROM Asn_Goal_M WHERE ( orgn_code = #orgnCode and DELETE_FLAG='N') ] ] >



22) When using JavaBeans from my JSP inside WebLogic, where should I place the JavaBean classes?

You should place these inside of a Web Application
If you are using an older version of WebLogic, you can place these classes on your Servlet Classpath.
23) What is the difference between an Application server and a Portal server?
A "portal server" is just an application server running a portal sofware or a portal application (Microsoft Sharepoint Portal Server is an example).
An application server is a system that provides the execution environment that is at the core of network computing or web-based architectures, providing a full set of services.
24) How do I use an EJB to handle simple authentication to an LDAP directory?
My recommendation would be to create a session bean that acquires an LDAP /JNDI context in the setSession() method. A subsequent call to authenticate would pass in a user and password. The following code shows how to authenticate the passed values:
env.put(Context.InitialContextFactory, "com.sun.jndi.ldap.LdapCtxFactory"); // I added this line myself
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
A failure in authentication will cause this code to throw a javax.naming.AuthenticationException
You may want to store the actual LDAP tree that contains the users you are authenitcating so youi can dynamically set it without recoding, so the actual code may look like this if you store the LDAP tree name in JNDI as "myUserLDAPTree" (ou=NewHires, o=JNDITutorial):
env.put(Context.InitialContextFactory, "com.sun.jndi.ldap.LdapCtxFactory"); // I added this line myself
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=" + passedUserName + "," + (String)new InitialContext().lookup("myUserLDAPTree"));
env.put(Context.SECURITY_CREDENTIALS, passedPassword);
// Create the initial context
DirContext ctx = new InitialDirContext(env);
The simply return a true, or a false if a javax.naming.AuthenticationException is thrown.
26) I want to set some user defined properties to be used in my application running in WebLogic appserver. In WebLogic 5.1, I was able to do this by setting them as System properties inside the weblogic.properties file like:

java.system.property.myproperty=myvalue

How do I achieve the same in WebLogic 6 ?
To be WebLogic 6 and J2EE compliant, you should use environment entries inside your xml descriptors for both EJB application archives and web application archives and use the JNDI environment naming context (ENC) to retrieve the values.

27) Differences in obtaining connection pools I'm trying to understand the difference between two ways to get a connection from a Weblogic 6.0 connection pool.
What are the two ways and is either method preferable to the other? Or does it not matter?

The two different ways that we can get a connection from a pool are listed as follows(taken from the original posting from the author).

1. Have a connection pool manager with a getConnection method that uses the following code:
Connection conn = null;
Driver myDriver =(Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance();
Properties props = new Properties();
props.put("connectionPoolID","PoolName");
conn = myDriver.connect("jdbc:weblogic:pool", props);

2. Using JNDI and providing a URL (such as PROVIDER_URL below) for the machine the connection pool is on. The following code could be used in a ConnectionPoolManager class too:
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://hostname:port");

try {
ctx = new InitialContext(ht);
javax.sql.DataSource ds =(javax.sql.DataSource) ctx.lookup("myJtsDataSource");
java.sql.Connection conn = ds.getConnection();
} catch (Exception ex) {}
The underlying result is the same. However, using a DataSource is the newer and much preferred method as the developer does not tie themselves to a particular driver or connection pool. There is also the added flexibility of changing connection pool properties without modifying the code.
27) Is there a simple example of how to use web application security in WebLogic?

Following is an example for WebLogic 6.x that protects all URLs that begin with /secure:
WEB-INF/web.xml - Define a constraint and a role





SecurePages
Security constraint for resources in the secure directory
/secure/*
POST
GET



only let the admin role access the pages
admin



SSL not required
NONE





BASIC


A role to access the secured pages
admin


WEB-INF/weblogic.xml - Map the admin role to the system user in WebLogic.





admin
system





28) What is a Multipool used for inside WebLogic?
You can think of a Multipool as a "pool of pools". WebLogic 6.x allows you to create a Multipool and have it mapped to a DataSource.
Multipools support two mutually exlusive algorithms:
1. Load Balancing - where requests are shared amongst the pools and,
2. High Availability - where the first pool is used until a fatal exception occurs, then control is passed to the second pool. Note that transaction information is not saved in the event of an error.
The client program is un-aware that a Mutlipool is being used, so there are no coding changes required, it is simply an administration change. Multipools work well with database failover products such as Oracle Parallel Server.
1) What are the valid values for the Session Descriptor inside the weblogic.xml file for WebLogic 6.1?
A list of valid parameter names for the Session Descriptor in webLogic 6.1 are as follows:
 CacheSize
 ConsoleMainAttribute
 CookieComment
 CookieDomain
 CookieMaxAgeSecs
 CookieName
 CookiePath
 CookiesEnabled
 IDLength
 InvalidationIntervalSecs
 JDBCConnectionTimeoutSecs
 PersistentStoreCookieName
 PersistentStoreDir
 PersistentStorePool
 PersistentStoreType
 SwapIntervalSecs
 TimeoutSecs
 TrackingEnabled
 URLRewritingEnabled
Each should be enclosed within a separate tag as follows:


URLRewritingEnabled
True


CookiesEnabled
True



2) How can I setup a Startup Class in WebSphere 3.5
IBM WebSphere provides the GUI where the option is there to set wether the server wants a particular Servlets is to be invoked upon start up. This will updated the XML as follows:

Auto-Generated - File Serving Servlet
com.ibm.servlet.engine.webapp.SimpleFileServlet

true
false



true


3) Could you please help me??? What is the difference between Production mode and Development mode in WebLogic 6.1?
Placing the WebLogic server in Production mode will disable automatic deployment. This is the feature that allows you to automatically deploy an EJB, WAR or EAR file into the server by placing it into your configuration/applications directory.
This is turned off in production to reduce the overhead of continually polling the directory for updates.
4) Retrieving user name from inside each bean.
Inside an EJB you may retrieve the "Caller" name, that is the login id by invoking:
sessionContext.getCallerIdentity().getName()
where sessionContext is the instance of "SessionContext" (setSessionContext) passed to the Session Bean, or the instance of "EntityContext" (setEntityContext) passed to the Entity Bean.
5) How can I use Connection Pool?
Additional info:
I am using Oracle 9ias server. I have given max-connections to 50 in data-sources.xml file. And the class i am using is "oracle.jdbc.pool.OracleConnectionCacheImpl". I have also tried with OracleConnectionPoolDataSource class in data-sources.xml. But i feel that connection pool is not utilised, because in the middle of the retrieval, the server hangs as there will no be connections left for opening...
In entity beans, I have created connections in setEntityContext and releasing them in unsetEntityContext...
Do not get the connection in the setEntityContext. Get the connection only when you need it.
If you get the connection in setEntityContext with the pool of 50 connections and you retrieve 50 different entity beans each bean will hang on to the connection and you will hang.
So, get the connection when you need it and release the connection as soon as you have no need for it any longer.
There is no reason to get the connection in setEntityContext.
6) Are there any tools for porting EJB Applications from one Application Server to another?
In theory, you should not need any tools for that task.
If you have developed a fully compliant J2EE application, you will be able to deploy it on any Application Server that follows Sun J2EE Specifications. That is one of the biggest advantages of using standards and following the spceifications.
Maybe, then, you will probably have to spend some time in tuning and fixing the configuration of the specific server.

No comments: