Apache Gump

Gump is Apache’s continuous integration tool. It is written in python and fully supports Apache Ant, Apache Maven and other build tools. Gump is unique in that it builds and compiles software against the latest development versions of those projects.

“Gump is a python- and xml-based continuousintegration framework implementing novel graphalgorithms to deliver unparalleled intelligence andefficiency enabling coping with unprecedentedcomplexity. Through a model-driven modular pluginarchitecture and a clear focus on the utilization ofproven interoperability patterns it ensures delivery of…”(a kitchen sink experience the likes of which you’venever seen.)

Introducing Continuous integration (CI)
• Get yourself a beefy server
• Automate all project builds
• Automate all project tests
• Generate reports and statistics
• Make it all part of your developmentprocess (i.e. send yourself e-mail)

Apache MyFaces

Apache MyFaces is a project of the Apache Software Foundation, and hosts several sub-projects relating to the JavaServer(tm) technology. If you want to know more about how JavaServer(tm) Faces works, take a look at the MyFaces introduction to JSF

The Apache MyFaces project provides:
- a JavaServer(tm) Faces implementation (MyFaces API, MyFaces Impl modules)
- several component libraries containing UI widgets for building web-applications with JSF (e.g. MyFaces Tomahawk, MyFaces Trinidad, MyFaces Tobago)
- extension packages to JavaServer(tm) Faces (e.g. MyFaces Orchestra)
- integration modules to other technologies and standards (e.g. MyFaces Portlet Bridge for integration with the portlet-standard)

Quickstart
Make sure to have a look at our component libraries examples. For Tomahawk, you can find a working distribution here. The source-code is available as part of the MyFaces Tomahawk project.
Find instructions on installing them yourselves in our Getting Started section. For additional information, you can refer to our WIKI

JSF & MVC
Over the last decade or so, the development of applications with graphical user interfaces has pretty much standardised. Whether you are developing with Gnome, KDE, MFC, VisualBasic, Delphi, or any similar library the process is the same:

•a tree of widgets is built, either by code or by loading a configuration file

•callbacks are attached to the widgets

•the GUI framework is left to render and manage the user interface.

When the user activates a widget (clicks a button, chooses a menu option, etc) the appropriate callback is invoked. This callback inspects the requested action, and may choose to report an error, or to update some kind of data-structure according to the user input. Then control is either returned to the UI framework with the same set of widgets, or a new set of widgets (a new “screen” is built).

The data-structure here is the “model”; it may be a model of a building, of an economy, of a text-document, etc. The logic which decides whether to update the model or report an error, and whether to redisplay the same set of widgets (same screen) or a different set (new screen) is the “controller”. And the widgets themselves (which may have custom drawing logic) are the “view”.

This approach has been vastly successful in systems where all the processing is on one physical computer system. However in our internet-connected world, accessing remote systems in interactive ways is becoming more and more common. Having to deploy applications onto client systems is becoming more and more clumsy.

One solution is the Java WebStart approach, where client logic is dynamically downloaded. The client can then be implemented much like a traditional MVC application, with the addition of communication back to the original host. However downloading logic to the client computer is not generally popular; it requires significant computer power and memory on the client side, and a large startup delay as the logic is transferred.

JSF instead is a different way to bring the successful MVC programming approach to the internet. It is designed to assume that the client has some software capable of rendering a reasonable range of graphical widgets, and of transmitting information back to the server about changes in the state of those widgets. JSF does not assume, however, that it can download any kind of logic to the remote system other than a basic description of the screen layout. Of course there is a widely-spread application that fits the description of a JSF client perfectly: the Web Browser.

Like the previous MVC frameworks (Gnome, KDE, MFC, etc) JSF is based around defining a tree of widgets (“components” in JSF terminology), where some of these components have callbacks associated with them. JSF ensures that when data is received back from the remote client the appropriate callbacks are invoked, without (in most cases) user code having to deal with things like HTML forms or urls. Instead, controller code simply responds to events, updates data-models, and then builds an appropriate view to render the new application state.

In practice, JSF component trees (widget trees) are almost always defined via a “template file”, and the most popular template file formats happen to be JSP and XHTML files. Purists will limit themselves to defining only widgets in such files, but many people also take the opportunity to encode fragments of traditional HTML or XHTML in such files, and JSF implementations traditionally merge the two to generate the output that is actually sent to the remote client.

You will of course have noticed that while the effect is similar to older web-application frameworks like Apache Struts, the approach is somewhat different. The HTML and Web are abstracted away to a great extent. This allows a number of nice features, like being able to simply change configuration to render HTML, XHTML, WML, and potentially things like PDF or Mozilla-XUL.

Another nice feature that results from this design is that it is easy to add more types of components (widgets). Simply add a library into the classpath, update your views to reference some of these new components, and if necessary attach callbacks to handle the actions that these components can trigger. The MyFaces Tomahawk, Trinidad and Tobago libraries are component collections that can be used in exactly this way to enhance your JSF applications, and there are more libraries available from many sources.

One of the issues that people notice when moving from more html-centric frameworks to JSF is that there is some loss of control over exactly what urls are generated, what appears in the query parameters, etc. Part of this is due to handing over of control of these aspects to a framework rather than directly managing it; other parts are due to the fact that JSF is still a reasonably young technology and still has a few rough edges. And partly it is due to the fact that JSF is optimized for very interactive applications; it can do things that are extremely complex to do with other approaches, but does not always perform quite as elegantly in the simpler cases.

Tomcat Interview Questions

How do you create multiple virtual hosts?
If you want tomcat to accept requests for different hosts e.g., www.myhostname.com then you must

0. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/www.myhostname.com

1. add a host entry in the server.xml file

2. Create the the following file under conf/Catalina/www.myhostname.com/ROOT.xml

Add any parameters specific to this hosts webapp to this context file

3. put your war file in ${catalina.home}/www/deploy

When tomcat starts, it finds the host entry, then looks for any context files and will start any apps with a context

To add more sites just repeat and rinse, all webapps can share the same war file location and appbase

How will you load properties file?

* Use a ResourceBundle. See the Java docs for the specifics of how the ResourceBundle class works. Using this method, the properties file must go into the WEB-INF/classes directory or in a jar file contained in the WEB-INF/lib directory.
* Another way is to use the method getResourceAsStream() from the ServletContext class. This allows you update the file without having to reload the webapp as required by the first method. Here is an example code snippet, without any error trapping:

// Assuming you are in a Servlet extending HttpServlet
// This will look for a file called “/more/cowbell.properties” relative
// to your servlet Root Context
InputStream is = getServletContext().getResourceAsStream(“/more/cowbell.properties”);
Properties p = new Properties();
p.load(is);
is.close();

Can I set Java system properties differently for each webapp?
No. If you can edit Tomcat’s startup scripts, you can add “-D” options to Java. But there is no way to add such properties in web.xml or the webapp’s context.

How do I configure Tomcat to work with IIS and NTLM?
Follow the standard instructions for when the isapi_redirector.dll

Configure IIS to use “integrated windows security”

In server.xml, make sure you disable tomcat authentication:

How can I access members of a custom Realm or Principal?
When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your webapp code, you’ll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server’s classloader, and you are trying to access it through you webapp’s classloader. While the classes maybe otherwise exactly the same, different (sibling) classloaders makes them different classes.

This assumes you created a My“Principal class, and put in Tomcat’s server/classes (or lib) directory, as well as in your webapp’s webinf/classes (or lib) directory. Normally, you would put custom realm and principal classes in the server directory because they depend on other classes there.

Here’s what you would like to do, but it throws ClassCastException:

MyPrincipal p = request.getUserPrincipal();
String emailAddress = p.getEmailAddress();
Here are 4 ways you might get around the classloader boundary:

1) Reflection

Principal p = request.getUserPrincipal();
String emailAddress = p.getClass().getMethod(“getEmailAddress”, null).invoke(p, null);
2) Move classes to a common classloader

You could put your custom classes in a classloader that is common to both the server and your webapp – e.g., either the “common” or bootstrap classloaders. To do this, however, you would also need to move the classes that your custom classes depend on up to the common classloader, and that seems like a bad idea, because there a many of them and they a core server classes.

3) Common Interfaces

Rather than move the implementing custom classes up, you could define interfaces for your customs classes, and put the interfaces in the common directory. You’re code would look like this:

public interface MyPrincipalInterface extends java.security.Principal {
public String getEmailAddress();
}

public class MyPrincipal implements MyPrincipalInterface {

public String getEmailAddress() {
return emailAddress;
}
}

public class MyServlet implements Servlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MyPrincipalInterface p = (MyPrincipalInterface)request.getUserPrincipal();
String emailAddress = p.getEmailAddress();

}
Notice that this method gives you pretty much the webapp code you wanted in the first place

4) Serializing / Deserializing

You might want to try serializing the response of ‘request.getUserPrincipal()’ and deserialize it to an instance of [webapp]MyPrincipal.

How do I override the default home page loaded by Tomcat?
After successfully installing Tomcat, you usually test it by loading http://localhost:8080 . The contents of that page are compiled into the index_jsp servlet. The page even warns against modifying the index.jsp files for this reason. Luckily, it is quite easy to override that page. Inside $TOMCAT_HOME/conf/web.xml there is a section called and it looks like this:

index.html
index.htm
index.jsp

The default servlet attempts to load the index.* files in the order listed. You may easily override the index.jsp file by creating an index.html file at $TOMCAT_HOME/webapps/ROOT. It’s somewhat common for that file to contain a new static home page or a redirect to a servlet’s main page. A redirect would look like:

This change takes effect immediately and does not require a restart of Tomcat.

How do I enable Server Side Includes (SSI)?
Two things have to be done for tomcat to aknowledge SSI scripts:

1. Rename $CATALINA_BASE/server/lib/servlets-ssi.renametojar to $CATALINA_BASE/server/lib/servlets-ssi.jar.

2. Uncomment the section of web.xml found in $CATALINA_BASE/conf/web.xml that deals with SSI. it looks like this when it is uncommented:

ssi

org.apache.catalina.ssi.SSIServlet

buffered
1

debug
0

expires
666

isVirtualWebappRelative
0

4

How do I use DataSources with Tomcat?
When developing J2EE web applications, the task of database connection management can be daunting. Best practice involves using a J2EE DataSource to provide connection pooling, but configuring DataSources in web application servers and connecting your application to them is often a cumbersome process and poorly documented.

The usual procedure requires the application developer to set up a DataSource in the web application server, specifying the driver class, JDBC URL (connect string), username, password, and various pooling options. Then, the developer must reference the DataSource in his application’s web.xml configuration file, and then access it properly in his servlet or JSP. Particularly during development, setting all of this up is tedious and error-prone.

With Tomcat 5.5, the process is vastly simplified. Tomcat allows you to configure DataSources for your J2EE web application in a context.xml file that is stored in your web application project. You don’t have to mess with configuring the DataSource separately in the Tomcat server.xml, or referencing it in your application’s web.xml file. Here’s how:

Install the JDBC Driver
Install the .jar file(s) containing the JDBC driver in Tomcat’s common/lib folder. You do not need to put them in your application’s WEB-INF/lib folder. When working with J2EE DataSources, the web application server manages connections for your application.

Create META-INF/context.xml
In the root of your web app directory structure, create a folder named META-INF (all caps). Inside that folder, create a file named context.xml that contains a Resource like this:

This example shows how to configure a DataSource for a SQL Server database named mytest located on the development machine. Simply edit the Resource name, driverClassName, username, password, and url to provide values appropriate for your JDBC driver.

Access the DataSource in Your Application
From a Servlet
Here’s how you might access the data in a servlet:

InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(“java:comp/env/jdbc/WallyDB”);
Connection c = ds.getConnection();

c.close();
Notice that, when doing the DataSource lookup, you must prefix the JNDI name of the resource with java:comp/env/

Introduction to Lucene

Lucene is an extremely rich and powerful full-text search library written in Java. You can use Lucene to provide full-text indexing across both database objects and documents in various formats (Microsoft Office documents, PDF, HTML, text, and so on). In this tutorial, we’ll go through the basics of using Lucene to add full-text search functionality to a fairly typical J2EE application: an online accommodation database. The main business object is the Hotel class. In this tutorial, a Hotel has a unique identifier, a name, a city, and a description.

Roughly, supporting full-text search using Lucene requires two steps: (1) creating a lucence index on the documents and/or database objects and (2) parsing the user query and looking up the prebuilt index to answer the query. In the first part of this tutorial, we learn how to create a lucene index. In the second part, we learn how to use the prebuilt index to answer user queries.

For your convenience, all of the code for this article’s Lucene demo is included in the lucene-tutorial.zip file. In this demo, the class Indexer in src/lucene/demo/search/Indexer.java is responsible for creating the index. The class SearchEngine in src/lucene/demo/search/SearchEngine.java is responsible for supporting user queries. The class Main in src/lucene/demo/Main.java has a test code that builds a Lucene index using a small dataset (the actual data is provided by the Hotel class stored in src/lucene/demo/business/HotelDatabase.java) and performs a simple keyword query on the data using the index. Briefly go over the two java source files, Indexer.java and SearchEngine.java, to get yourself familiar with the overall structure of the code.

1. Creating an Index

The first step in implementing full-text searching with Lucene is to build an index.
At the heart of Lucene is an Index. You pump your data into the Index, then do searches on the Index to get results out. Document objects are stored in the Index, and it is your job to “convert” your data into Document objects and store them to the Index. That is, you read in each data file (or Web document, database tuple or whatever), instantiate a Document for it, break down the data into chunks and store the chunks in the Document as Field objects (a name/value pair). When you’re done building a Document, you write it to the Index using the IndexWriter. Now let us get into details on how this is done.

1.1 IndexWriter Class: Creating Index

To create an index, the first thing that need to do is to create an IndexWriter object. The IndexWriter object is used to create the index and to add new index entries (i.e., Documents) to this index. You can create an IndexWriter as follows:

IndexWriter indexWriter = new IndexWriter(“index-directory”, new StandardAnalyzer(), true);

The first parameter specifies the directory in which the Lucene index will be created, which is index-directory in this case. The second parameter specifies the “document parser” or “document analyzer” that will be used when Lucene indexes your data. Here, we are using the StandardAnalyzer for this purpose. More details on lucene analyzers follow shortly. The third parameter tells Lucene to create a new index if an index has not been created in the directory yet.

1.2 Analyzer Class: Parsing the Documents
Most likely, the data that you want to index by Lucene is plain text English. The job of Analyzer is to “parse” each field of your data into indexable “tokens” or keywords. Several types of analyzers are provided out of the box.

1.3 Adding a Document/object to Index
Now you need to index your documents or business objects. To index an object, you use the Lucene Document class, to which you add the fields that you want indexed. As we briefly mentioned before, a Lucene Document is basically a container for a set of indexed fields. This is best illustrated by an example:

Document doc = new Document();
doc.add(new Field(“description”, hotel.getDescription(), Field.Store.YES, Field.Index.TOKENIZED));

To add a field to a document, you create a new instance of the Field class. A field is made up of a name and a value (the first two parameters in the class constructor). The value may take the form of a String, or a Reader if the object to be indexed is a file.

Log4J

Logging within the context of program development constitutes inserting statements into the program that provide some kind of output information that is useful to the developer. Inserting log statements into your code is a general method for debugging it. Examples of logging are trace statements, dumping of structures and the familiar System.out.println or printf debug statements

Log4j is a open source debugging tool developed for putting log statements into your application., written in Java, which logs statements to a file, a java.io.Writer, or a syslog daemon. Log4j offers a hierarchical way to insert logging statements within a Java program. Multiple output formats and multiple levels of logging information are available.

One of the distinctive features of log4j is the notion of inheritance in loggers. Using a logger hierarchy it is possible to control which log statements are output at arbitrarily fine granularity but also great ease. This helps reduce the volume of logged output and minimize the cost of logging.

By using a dedicated logging package, the overhead of maintaining thousands of System.out.println statements is alleviated as the logging may be controlled at runtime from configuration scripts.

It’s speed and flexibility allows log statements to remain in shipped code while giving the user the ability to enable logging at runtime without modifying any of the application binary. All of this while not incurring a high performance cost.

Logging does have its drawbacks. It can slow down an application. If too verbose, it can cause scrolling blindness. To alleviate these concerns, log4j is designed to be reliable, fast and extensible. Since logging is rarely the main focus of an application, the log4j API strives to be simple to understand and to use.

All enterprise architectures adopt a global logging framework. The logging framework provides classes/interfaces for logging messages, errors and debug statements to destinations like files, databases, e-mails and consoles throughout the system. The logged information is useful to an end-user of an application or to a system administrator. Internationalization in a logging framework is the ability to log the messages in different languages. All logging frameworks will be rated on internationalization and extensibility. The following logging frameworks are available:
• JavaTM Logging
• Jlog
• Log4j
• Protomatter
• BEA mechanism for logging (technically not a full feature framework)
• Message LFW

Apache HTTP Server

Download latest Apache HTTP Server version from HERE

Follow

Get every new post delivered to your Inbox.