Configuring Apache HTTP Server with SSL is very easy. This post assumes that you already have a certificate file generated and signed. I will not discuss here how to generate your own one using the open source OpenSSL. This guide is intended for people who already have signed certificates from a security certificate company to be used in their websites.

First off, you must download the binary of Apache HTTP Server with SSL. Install/extract it to your desired folder. Now it’s time for some configuration. Go to the folder conf/ in your Apache folder and open the file httpd.conf . Look for this string LoadModule ssl_module modules/ and remove the # sign to uncomment it.

Next, place these lines anywhere in the file.

<IfModule mod_ssl.c>
  Include conf/httpd-ssl.conf

The file httpd-ssl.conf (or ssl.conf) is found in the extra/ folder in your conf/ folder. You can either move this file to your preferred directory or have it stay as is. You would have to change the path in the above tag to point it to the right path.

Now, let’s open up httpd-ssl.conf. Look for the following strings:

Change the path to where you stored your .crt file and .key file. Sometimes your host provider may require you to also set a certificate chain file in order for SSL to work. Just look for the string SSLCertificateChainFile and change the path. The file usually has a substring of the word “bundle”.

Next, we set the DocumentRoot, ServerName, and ServerAdmin values. Look for this string VirtualHost and change the values. Your DocumentRoot must be the same path as the DocumentRoot path in httpd.conf if you wish to have the same pages in SSL. Your ServerName should point to your domain url e.g. ServerAdmin can be left out as it is.

Save the files and restart Apache and point your site to https://domain:443/

If in case your server doesnt start because of this error:
Error: Init: SSLPassPhraseDialog builtin is not supported on Win32

Copy your encrypted key file using this command:
openssl rsa -in file1.key -out file2.key

file2.key will contain your unencrypted key. Use that key file in your httpd-ssl.conf settings.

Database connection pooling is not a new concept. Typically, one would want to apply this concept into their application when dealing with database connections. The old style of creating database connections from scratch, maintaining them and closing them upon finishing the request is a very expensive process and takes a heavy load on the server itself.

Apache Tomcat supports connection pooling. One advantage of pooling is that it reduces the garbage collection load. Using connections objects that are in the pool, we do not need to worry about memory leaks of sort.

Once we request a connection and close it, the connection object will be sent back to the pool and wait for other requests. Hence, we are actually going to use existing connection objects. If the pool has ran out of connection objects, it will create a new one and adds it up to the total number of connections inside the pool.

To enable connection pooling in java, you only need to add this tag in the context.xml in the conf/ folder of apache tomcat’s working folder.

<Resource name="jdbc/dbname"

This tag must be inside the <context> tag.

To use this connection, you can have a method that looks similar to this

public static Connection getConnection() throws Exception {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/dbname");

And use that same method to get a connection object from the pool:

Connection con = getConnection();

When you close this connection object after use, it will not close the object and garbage collect. Rather, it puts it back in the pool for the next use.

Please note that this sample code uses the MySQL Database. If you use other databases, check the appropriate driver class for the JDBC driver and make sure that you include the JDBC driver library in Apache Tomcat’s lib/ folder.

There are many tools and/or libraries to use if you want to parse html pages. In java, one of the popular ones is called HTML Parser, which is what i use. It is not an application but a java library that you can plug into your classpath when compiling and executing your application using it. Go over to their site and download it. When you extract the archive file, it contains the JAR file library , samples and documentation.

I mainly use HTML Parser for extraction purposes. However, you can also use it for transformation. Some cool features include having filters which help immensely in getting the html tags that you only need.

Here is a sample code that uses the HasAttributeFilter class to filter out only tags that contain this attribute. I use the FilterBean class in this example to access the site page’s content. You can also use the Parser class to do the same thing. Using either is up to your preference.

try {
  NodeFilter[] nff = {new HasAttributeFilter("id", "spoof")};
  FilterBean fb = new FilterBean();
  fb.setFilters (nff);
  NodeList pageNodeList = fb.getNodes();
} catch (Exception e) { }

Suppose our link page contains the following html contents:

<p id="spoof">This is a sample paragraph</p>
<p id="officeid">Office id is 000123</p>

Once you execute that code, the output for System.out would be:

<p id="spoof">This is a sample paragraph</p>

the NodeList class is patterned after the Vector class and can be broken into separate tags. You just need to loop them. The documentation API contains all the classes of HTML Parser that you can use in your parsing needs. Take another filter as example, the TagNameFilter. if you replace HasAttributeFilter in the code with this

new TagNameFilter("p")

System.out will output as one string:
<p id="spoof">This is a sample paragraph</p>
<p id="officeid">Office id is 000123</p>

if you need to acecss each <p> tag separately you need to loop the pageNodeList object like this:

for (int i=0; i<pageNodeList.size(); i++) {
  System.out.println(((Node) pageNodeList.elementAt(i)).toHtml());

There you have it. HTML Parsing is so easy when using this helper library. It saves you the time and trouble of creating your own parser. Feel free to comment out if you have questions and/or problems.

Related Posts Plugin for WordPress, Blogger...