<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Factory</title>
	<atom:link href="http://www.codefactorycr.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codefactorycr.com</link>
	<description>Web Development for You</description>
	<lastBuildDate>Fri, 10 Jun 2011 20:25:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Custom Rules for JQuery Validation in Forms</title>
		<link>http://www.codefactorycr.com/custom-rules-jquery-validation.html</link>
		<comments>http://www.codefactorycr.com/custom-rules-jquery-validation.html#comments</comments>
		<pubDate>Fri, 22 Apr 2011 04:03:28 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.codefactorycr.com/?p=270</guid>
		<description><![CDATA[JQuery is one of the best Javascript libraries out there, which combines ease of use and powerful, yet simple to use plugins for almost everything you could imagine or need.  [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://jquery.com/"><img class="size-full wp-image-279 aligncenter" title="JQuery" src="http://www.codefactorycr.com/wp-content/uploads/2011/04/jquerylogo.jpg" alt="" width="228" height="72" /></a></p>
<p><a title="JQuery" href="http://jquery.com/" target="_blank">JQuery</a> is one of the best Javascript libraries out there, which combines ease of use and powerful, yet simple to use plugins for almost everything you could imagine or need.  Also, it provides a solid foundation for you to write your code for your custom needs.<span id="more-270"></span></p>
<p>When working with forms, we always need to deal with form validation.  It&#8217;s just something we can&#8217;t ignore or evade, since it&#8217;s critical for useful and friendly application.  In this sense, JQuery has a great <a title="JQuery Validation Plugin" href="http://docs.jquery.com/Plugins/validation" target="_blank">Validation Plugin</a> that deals with all your general form validation needs: required fields, dates, numeric ranges, and many more.</p>
<p>But there are times in which you need to create a custom validation rule.  Maybe because of your business or a specific rule your customer requested you.  In this case, the Validation Plugin offers a pretty simple way to extend the basic rules, by adding your very own validation methods.</p>
<p>This is achieved by adding a custom validation function using the function  <strong>$.validator.addMethod() </strong>inside the <strong>$(document).ready()</strong> function of JQuery:<strong><br />
</strong></p>
<pre class="brush: jscript; title: ; notranslate">

$(document).ready(function(){

  $.validator.addMethod(&quot;myCustomRule&quot;, function(value, element) {
    //Any code that will return TRUE or FALSE
  },
  &quot;Error message&quot;);

});
</pre>
<p>The method has 3 main parts:</p>
<ul>
<li>The rule name (called <strong>myCustomRule</strong> in this example)</li>
<li>The Javascript function that will return either <strong>TRUE</strong> or <strong>FALSE</strong>, with the actual validation you need.  If the validation goes fine, it&#8217;ll return <strong>TRUE</strong>, and if something fails it returns <strong>FALSE</strong>.</li>
<li>The error message that will be shown to the user when the validation code returns FALSE.</li>
</ul>
<p>So for example, imagine we need to add a custom validation rule that checks that a date entered by the user is higher than the current date (than today). In this case, we&#8217;ll need to add the following validation function with the <strong>$.validator.addMethod</strong> function:</p>
<pre class="brush: jscript; title: ; notranslate">

$.validator.addMethod(&quot;dateHigherThanToday&quot;, function(value, element) {
  //If false, the validation fails and the message below is displayed
  var myDate = value;
  return Date.parse(myDate) &gt; new Date();
  }, &quot;Date must be higher than current date&quot;);
</pre>
<p>After this, you only need to reference your new validation method in your form, either by defining your rules in Javascript, or by adding the validation methods in the input&#8217;s <strong>class</strong> attribute, like this:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;input id=&quot;date&quot; type=&quot;text&quot; class=&quot;required date dateHigherThanToday&quot; /&gt;
</pre>
<p>As with any other validation rules from the plugin, you can combine as many as you need to make sure you cover all your validation needs.  In this case, we&#8217;re telling that the field <strong>date</strong> is mandatory (required), must have a date format and must have a date higher than today&#8217;s date (our new custom rule).  If any of these rules fail, the form won&#8217;t be submitted and the user will receive an error message depending on the rule that failed.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/custom-rules-jquery-validation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Login with CodeIgniter in PHP</title>
		<link>http://www.codefactorycr.com/login-with-codeigniter-php.html</link>
		<comments>http://www.codefactorycr.com/login-with-codeigniter-php.html#comments</comments>
		<pubDate>Mon, 18 Apr 2011 06:14:05 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.codefactorycr.com/?p=206</guid>
		<description><![CDATA[CodeIgniter is an open source Web Application framework built in PHP designed to make your life as a programmer easier, while allowing you good speed for development, and also good [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://codeigniter.com/"><img class="alignleft size-full wp-image-213" title="codeigniter" src="http://www.codefactorycr.com/wp-content/uploads/2011/04/codeigniter.png" alt="Code Igniter logo" width="48" height="48" /></a><a title="Code Igniter" href="http://codeigniter.com/">CodeIgniter</a> is an open source Web Application framework built in PHP designed to make your life as a programmer easier, while allowing you good speed for development, and also good performance when the site is up and running.</p>
<p><span id="more-206"></span>Being a Java developer for almost 10 years now, when I had to move to PHP I chose CodeIgniter for the following reasons:</p>
<ul>
<li>Easy to install and configure (being a newbie in PHP this was crucial)</li>
<li>Clean and elegant <a title="Model View Controller" href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" target="_blank">MVC</a> implementation</li>
<li>Uses <a title="Active Record Patter" href="http://en.wikipedia.org/wiki/Active_record_pattern" target="_blank">Active Record</a> pattern for database access</li>
<li>Overall small footprint and good performance</li>
</ul>
<p>Usually when you are building a program, the login/logout functionality is a must we always have to go through, so this quick tutorial will focus on this functionality, taking advantage of the benefits of using CodeIgniter instead of doing it from scratch in PHP.</p>
<h2>Requirements</h2>
<ul>
<li><a title="CodeIgniter downloads" href="http://codeigniter.com/downloads/" target="_blank">CodeIgniter</a> framework.  By the time this tutorial was done, the latest version was <strong>2.0.2</strong></li>
<li>Any Apache/PHP/MySQL stack.  You can install the applications independently, or install one of those packages that have all of them bundled together.</li>
</ul>
<h2>Installing CodeIgniter</h2>
<p>To install CodeIgniter, you only need to uncompress the Zip file you download from the site into your <strong>htdocs</strong> directory and you&#8217;re good to go.  We&#8217;ll configure the database access later.</p>
<h2>Create the database</h2>
<p>For this tutorial, you need a MySQL database with the following table:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE `users` (
 `id` tinyint(4) NOT NULL AUTO_INCREMENT,
 `username` varchar(10) NOT NULL,
 `password` varchar(100) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
</pre>
<p>Remember also to add at least one user.  We&#8217;ll add one user called <strong>bob </strong>with password <strong>supersecret</strong>.</p>
<pre class="brush: sql; title: ; notranslate">

insert into users (username, password) values ('bob', MD5('supersecret'));
</pre>
<h2>Configure CodeIgniter</h2>
<h3>Database Access</h3>
<p>Update the file <strong>application/config/database.php</strong> in your CodeIgniter installation with your database info:</p>
<pre class="brush: php; first-line: 44; title: ; notranslate">

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'yourdbusername';
$db['default']['password'] = 'yourdbpassword';
$db['default']['database'] = 'yourdbname';
</pre>
<h3>Default Controller</h3>
<p>We need to tell CodeIgniter to land into our login page instead of the default welcome page.  Update the file <strong>application/config/routes.php </strong>in your CodeIgniter installation with you controller&#8217;s name.  We&#8217;ll call our landing controller <strong>login</strong>.</p>
<pre class="brush: php; first-line: 41; title: ; notranslate">

$route['default_controller'] = &quot;login&quot;;
</pre>
<h3>Default Libraries</h3>
<p>In the file <strong>application/config/autoload.php </strong> you can configure the default libraries you want to load in all your controllers.  For our case, we&#8217;ll load the database and session libraries, since we want to handle user sessions, and also the URL helper for internal link generation</p>
<pre class="brush: php; first-line: 55; title: ; notranslate">

$autoload['libraries'] = array('database','session');
</pre>
<pre class="brush: php; first-line: 67; title: ; notranslate">
$autoload['helper'] = array('url');
</pre>
<h3>Encryption Key</h3>
<p>When you use the <strong>session</strong> library, you need to set the <strong>encryption_key</strong> in the file <strong>application/config/config.php</strong>.</p>
<pre class="brush: php; first-line: 227; title: ; notranslate">

$config['encryption_key'] = 'REALLY_LONG_NUMBER';
</pre>
<h3>The Code</h3>
<p>Here are the actual Views, Controllers and Model we are using for the login functionality.</p>
<h4>User Model (application/models/user/php)</h4>
<pre class="brush: php; title: ; notranslate">

&lt;?php
Class User extends CI_Model
{
 function login($username, $password)
 {
   $this -&gt; db -&gt; select('id, username, password');
   $this -&gt; db -&gt; from('users');
   $this -&gt; db -&gt; where('username = ' . &quot;'&quot; . $username . &quot;'&quot;);
   $this -&gt; db -&gt; where('password = ' . &quot;'&quot; . MD5($password) . &quot;'&quot;);
   $this -&gt; db -&gt; limit(1);

   $query = $this -&gt; db -&gt; get();

   if($query -&gt; num_rows() == 1)
   {
     return $query-&gt;result();
   }
   else
   {
     return false;
   }
 }
}
?&gt;
</pre>
<h4>Login Controller (application/controllers/login.php)</h4>
<pre class="brush: php; title: ; notranslate">

&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

 function __construct()
 {
   parent::__construct();
 }

 function index()
 {
   $this-&gt;load-&gt;helper(array('form', 'url'));
   $this-&gt;load-&gt;view('login_view');
 }

}

?&gt;
</pre>
<h4>Login View (application/views/login_view.php)</h4>
<pre class="brush: php; html-script: true; title: ; notranslate">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
 &lt;head&gt;
   &lt;title&gt;Simple Login with CodeIgniter&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;h1&gt;Simple Login with CodeIgniter&lt;/h1&gt;
   &lt;?php echo validation_errors(); ?&gt;
   &lt;?php echo form_open('verifylogin'); ?&gt;
     &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;
     &lt;input type=&quot;text&quot; size=&quot;20&quot; id=&quot;username&quot; name=&quot;username&quot;/&gt;
     &lt;br/&gt;
     &lt;label for=&quot;password&quot;&gt;Password:&lt;/label&gt;
     &lt;input type=&quot;password&quot; size=&quot;20&quot; id=&quot;passowrd&quot; name=&quot;password&quot;/&gt;
     &lt;br/&gt;
     &lt;input type=&quot;submit&quot; value=&quot;Login&quot;/&gt;
   &lt;/form&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>VerifyLogin Controller (application/controllers/verifylogin.php)</h4>
<p>This controller does the actual validation of the fields and checks the credentials against the database.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLogin extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this-&gt;load-&gt;model('user','',TRUE);
 }

 function index()
 {
   //This method will have the credentials validation
   $this-&gt;load-&gt;library('form_validation');

   $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|xss_clean');
   $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this-&gt;form_validation-&gt;run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this-&gt;load-&gt;view('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', 'refresh');
   }

 }

 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this-&gt;input-&gt;post('username');

   //query the database
   $result = $this-&gt;user-&gt;login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' =&gt; $row-&gt;id,
         'username' =&gt; $row-&gt;username
       );
       $this-&gt;session-&gt;set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this-&gt;form_validation-&gt;set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}
?&gt;
</pre>
<h4>Home Controller (application/controllers/home.php)</h4>
<p>This is the private page (only authenticated users can access it).</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Home extends CI_Controller {

 function __construct()
 {
   parent::__construct();
 }

 function index()
 {
   if($this-&gt;session-&gt;userdata('logged_in'))
   {
     $session_data = $this-&gt;session-&gt;userdata('logged_in');
     $data['username'] = $session_data['username'];
     $this-&gt;load-&gt;view('home_view', $data);
   }
   else
   {
     //If no session, redirect to login page
     redirect('login', 'refresh');
   }
 }

 function logout()
 {
   $this-&gt;session-&gt;unset_userdata('logged_in');
   session_destroy();
   redirect('home', 'refresh');
 }

}

?&gt;
</pre>
<h4>Home Page View (application/views/home_view.php)</h4>
<pre class="brush: php; html-script: true; title: ; notranslate">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
 &lt;head&gt;
   &lt;title&gt;Simple Login with CodeIgniter - Private Area&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;h1&gt;Home&lt;/h1&gt;
   &lt;h2&gt;Welcome &lt;?php echo $username; ?&gt;!&lt;/h2&gt;
   &lt;a href=&quot;home/logout&quot;&gt;Logout&lt;/a&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The code is pretty easy to follow and understand.  Also, <a title="Download code here" href="http://files.codefactorycr.com/blog/codeigniter_login.tar.gz">you can download the code from here</a>, so you can install it and test it in your location.  You&#8217;ll only need a full installation of CodeIgniter 2.0.2 and the table in your MySQL database.  If you need any help, feel free to leave us a comment or shoot us an email.</p>
<p>Also, this code uses a pretty basic form validation from CodeIgniter.  If you need a more complex validation process, check <a title="CodeIgniter Form Validation" href="http://codeigniter.com/user_guide/libraries/form_validation.html" target="_blank">CodeIgniter&#8217;s Form Validation</a> docs at their site.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/login-with-codeigniter-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Glassfish behind Apache</title>
		<link>http://www.codefactorycr.com/glassfish-behind-apache.html</link>
		<comments>http://www.codefactorycr.com/glassfish-behind-apache.html#comments</comments>
		<pubDate>Mon, 11 Apr 2011 23:02:33 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.codefactorycr.com/?p=153</guid>
		<description><![CDATA[I&#8217;ve been using Glassfish Open Source 3.1 for a short while now, and I think it&#8217;s a great application server.  It has a nice Web Admin Panel and a powerful [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a title="Glassfish Open Source 3.1" href="http://glassfish.java.net/downloads/3.1-final.html" target="_blank">Glassfish Open Source 3.1</a> for a short while now, and I think it&#8217;s a great application server.  It has a nice Web Admin Panel and a powerful shell command to manage the server during runtime (without needing to tweak XML files on your own), depending if you have the Web Admin Panel port available or not at your location.<span id="more-153"></span></p>
<h2>Why set up Glassfish behind Apache?</h2>
<p>When started, <a href="http://glassfish.java.net/downloads/3.1-final.html" target="_blank">Glassfish</a> opens two HTTP ports by default: <strong>8080</strong>, which is the usual HTTP port where all your WAR applications are available, and also port <strong>4848</strong>, which lets you access the Web Admin Panel.  You don&#8217;t need an additional Web server like <a title="Apache Web Server" href="http://httpd.apache.org/" target="_blank">Apache</a> to use your Glassfish server, but eventually you&#8217;ll run into one of the following scenarios that will make you consider having your Glassfish server behind a Web Server like Apache:</p>
<ul>
<li>Port 8080 is blocked for your end users.</li>
<li>People can become suspicious when accessing an unusual domain like <em>http://www.mysuperapplication.com:8080</em></li>
<li>You need to set up several instances of Glassfish (e.g. dev and live), and need to keep each of them in its own JVM</li>
</ul>
<p>For this configuration, you&#8217;ll need the following:</p>
<ul>
<li><a href="http://www.java.com" target="_blank">JDK 1.6</a></li>
<li><a href="http://httpd.apache.org/" target="_blank">Apache</a> 2.2 up and running (default installation is fine)</li>
<li><a href="http://tomcat.apache.org/connectors-doc/" target="_blank">Tomcat mod_jk connector</a></li>
<li><a href="http://glassfish.java.net/downloads/3.1-final.html" target="_blank">Glassfish 3.1 Open Source Edition</a></li>
</ul>
<p>This configuration was successfully deployed in CentOS 5.5, but should be easily ported to other Linux distributions, or even a Windows-based server.</p>
<h2>Installing Glassfish:</h2>
<p>Installing Glassfish is just a matter of unzipping the package file (zip or tar.gz) you downloaded in any location in your server.  We recommend you create a low-privilege user in your Linux server and run Glassfish with this user. It is not a good idea to run an application server with root privileges.</p>
<p>After you unzip Glassfish, you can start the server by running this command:</p>
<pre class="brush: plain; title: ; notranslate">
$GLASSFISH_HOME/glassfish/bin/asadmin start-domain
</pre>
<p>This command will start the default domain included in the server, which is called domain1.  After a few seconds, you should be able to browse to its default page at <a href="http://server-ip:8080">http://server-ip:8080</a> or the Web Admin Panel at <a href="http://server-ip:4848">http://server-ip:4848</a>.</p>
<p>After this, we&#8217;ll use the <strong>asadmin</strong> commnad to to add an http listener called <strong>jk-connector-8009</strong>, which will listen on port <strong>8009</strong> for AJP connections.  This is the port that Apache will use to redirect requests from port 80 to Glassfish, and back to Apache.</p>
<p><strong>Create the listener:</strong></p>
<pre class="brush: plain; title: ; notranslate">
$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 create-http-listener --listeneraddress 0.0.0.0 --listenerport 8009 --defaultvs server jk-connector-8009
</pre>
<p><strong>Activate the listener:</strong></p>
<pre class="brush: plain; title: ; notranslate">
$GLASSFISH_HOME/glassfish/bin/asadmin --user admin --host localhost --port 4848 set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector-8009.jk-enabled=true
</pre>
<p>Finally, restart the Glassfish Server:</p>
<pre class="brush: plain; title: ; notranslate">
$GLASSFISH_HOME/glassfish/bin/asadmin stop-domain
$GLASSFISH_HOME/glassfish/bin/asadmin start-domain
</pre>
<h2>Configuring Apache</h2>
<p>Download the <a href="http://tomcat.apache.org/connectors-doc/" target="_blank">Tomcat mod_jk connector</a> and place the .so file in your modules directory (e.g. /etc/httpd/modules)<br />
Create a file called <strong>workers.properties</strong> and place it in a safe place (e.g. /etc/httpd/conf.d).  Put the following contents in this file:</p>
<pre class="brush: plain; title: ; notranslate">
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
</pre>
<p>Then, open your<strong> httpd.conf</strong> file and put the following contents in it (outside a <strong>VirtualHost</strong> section).  Check the path of your <strong>workers.properties</strong> file</p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">
JkWorkersFile /path/to/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel debug
JkLogStampFormat &quot;[%a %b %d %H:%M:%S %Y] &quot;
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat &quot;%w %V %T&quot;
</pre>
<p>Also, you need to add a <strong>VirtualHost</strong> section in your page, in order to map the specific domain/subdomain with the path in Glassfish you want to make visible through Apache:</p>
<pre class="brush: xml; highlight: [7]; title: ; notranslate">

&lt;VirtualHost 111.111.111.111:80&gt;
  ServerAdmin webmaster@mydomain.com
  ServerName mydomain.com

  ... other stuff

  JkMount /myapp/* worker1

  ... other stuff

&lt;/VirtualHost&gt;
</pre>
<p>The highlighted line tells Apache that all requests that go to <a href="http://mydomain.com/myapp/">http://mydomain.com/myapp/</a> will be served by <strong>worker1</strong>, which is connected to port <strong>8009</strong> of <strong>localhost</strong>, which is the port we opened before in <strong>Glassfish</strong>.  If you want Glassfish to serve all contents of mydomain.com, change the <strong>JKMount</strong> to <strong>/* worker1</strong>.</p>
<p>Finally, restart Apache and you&#8217;re all set!  Your Glassfish instance will be visible through Apache by port 80, and therefore you won&#8217;t need to open additional ports in your server, and you can use the best of both worlds.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/glassfish-behind-apache.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Tomcat and APR in a Linux Server</title>
		<link>http://www.codefactorycr.com/apache-tomcat-and-apr-in-a-linux-server.html</link>
		<comments>http://www.codefactorycr.com/apache-tomcat-and-apr-in-a-linux-server.html#comments</comments>
		<pubDate>Mon, 04 Apr 2011 21:59:03 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://php.codefactorycr.com/wordpress/?p=138</guid>
		<description><![CDATA[When you do a fresh installation of Apache Tomcat, you&#8217;ll notice the following error message in the logfile: APR stands for Apache Runtime Portable Project which provides a consistent API [...]]]></description>
			<content:encoded><![CDATA[<p>When you do a fresh installation of <a href="http://tomcat.apache.org/" target="_blank">Apache Tomcat</a>, you&#8217;ll notice the following error message in the logfile:</p>
<pre class="brush: plain; title: ; notranslate">

org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which
allows optimal performance in production environments
was not found on the java.library.path
</pre>
<p>APR stands for <a href="http://apr.apache.org/" target="_blank">Apache Runtime Portable Project</a> which provides a consistent API to the native environment where the application server is running (either Linux, Windows, etc).  This means that Tomcat itself contains this native library, but it is disabled by default, since you need to install first the APR. It is recommended to perform the following steps as root or a sudoer user, since you need access to common and restricted resources in the server</p>
<p><span id="more-138"></span></p>
<p>To install the APR, first move the Tomcat Native Library to a common location:</p>
<pre class="brush: plain; title: ; notranslate">

cp $TOMCAT_HOME/bin/tomcat-native.tar.gz /usr/local/src/
</pre>
<p>Then, download the APR library from Apache&#8217;s site and install it in /usr/local/src</p>
<pre class="brush: plain; title: ; notranslate">

cd /usr/local/src

tar -zxvf apr-1.3.9.tar.gz

cd apr-1.3.9

./configure

make all install
</pre>
<p>This will install the APR libraries at /usr/local/apr.</p>
<p>After this, install Tomcat&#8217;s native library:</p>
<pre class="brush: plain; title: ; notranslate">

cd /usr/local/src

tar -zxvf tomcat-native.tar.gz

cd tomcat-native-*-src/jni/native/

./configure --with-apr=/usr/local/apr/bin/apr-1-config

make all install
</pre>
<p>After this, you only need to tell Tomcat where to find these libraries.  One option is to use the LD_LIBRARY_PATH environment variable:</p>
<pre class="brush: plain; title: ; notranslate">

export LD_LIBRARY_PATH=/usr/local/apr/lib
</pre>
<p>Or create some symbolic links in the J DK used by Tomcat<br />
After this, restart tomcat and you should see the following message in the log file:</p>
<pre class="brush: plain; title: ; notranslate">

INFO: Loaded APR based Apache Tomcat Native library 1.1.16.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/apache-tomcat-and-apr-in-a-linux-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boda Cocoates</title>
		<link>http://www.codefactorycr.com/boda-cocoates-2.html</link>
		<comments>http://www.codefactorycr.com/boda-cocoates-2.html#comments</comments>
		<pubDate>Tue, 08 Mar 2011 15:28:43 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://php.codefactorycr.com/wordpress/?p=104</guid>
		<description><![CDATA[BodaCocoates is a wedding information website built in Joomla! for a Costa Rican couple. Services provided: Domain registry and hosting GoogleApps configuration (email, calendar, docs) Installation, configuration and customization of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.bodacocoates.com" target="_blank">BodaCocoates</a> is a wedding information website built in <a href="http://www.joomla.org/" target="_blank">Joomla!</a> for a Costa Rican couple.</p>
<p style="text-align: center;"><a rel="prettyPhoto" href="http://www.codefactorycr.com/wp-content/uploads/2011/03/bodacocoates.png"><img class="aligncenter size-medium wp-image-108" title="bodacocoates" src="http://www.codefactorycr.com/wp-content/uploads/2011/03/bodacocoates-300x196.png" alt="" width="300" height="196" /></a></p>
<p>Services provided:</p>
<ul>
<li>Domain registry and hosting</li>
<li>GoogleApps configuration (email, calendar, docs)</li>
<li>Installation, configuration and customization of Joomla!</li>
<li>Facebook Integration</li>
<li>Google Analytics and Piwik setup to track hits and favorite pages</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/boda-cocoates-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java VisualVM to profile a remote server</title>
		<link>http://www.codefactorycr.com/java-visualvm-to-profile-a-remote-server.html</link>
		<comments>http://www.codefactorycr.com/java-visualvm-to-profile-a-remote-server.html#comments</comments>
		<pubDate>Mon, 07 Mar 2011 19:06:47 +0000</pubDate>
		<dc:creator>aarias</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://php.codefactorycr.com/wordpress/?p=4</guid>
		<description><![CDATA[Since Version 1.5, Sun&#8217;s JDK includes a nice profiling tool called VisualVM, intended to be used by developers, sysadmins and any person that needs to troubleshoot and profile memory consumption [...]]]></description>
			<content:encoded><![CDATA[<p>Since Version 1.5, Sun&#8217;s JDK includes a nice profiling tool called VisualVM, intended to be used by developers, sysadmins and any person that needs to troubleshoot and profile memory consumption in Java applications and servers.  To run it, just execute the file jvisualvm located in $JAVA_HOME/bin.</p>
<p style="text-align: center;"><a rel="prettyPhoto" href="http://www.codefactorycr.com/wp-content/uploads/2011/03/aboutjavavisualvm.png"><img class="size-medium wp-image-46 aligncenter" title="aboutjavavisualvm" src="http://www.codefactorycr.com/wp-content/uploads/2011/03/aboutjavavisualvm-300x204.png" alt="" width="300" height="204" /></a></p>
<p><span id="more-4"></span></p>
<p>To profile local applications is pretty easy, since you only need to start it and it&#8217;ll detect all Java-based applications and you&#8217;ll be able to see the Heap/PermGen usage, the number of threads used, the classes loaded by the class loader and other stuff.<br />
When it comes really handy is to profile and troubleshoot remote applications (e.g. profile a Tomcat instance in a remote server).  In order to do these, you should only start the application jstatd in the remote server, open the required ports and you&#8217;re ready.  Here are the steps to do it:</p>
<p>The jstatd tool is an RMI server application that provides a interface to allow remote monitoring tools to attach to JVMs running on the local host.</p>
<p>It is located in the JDK&#8217;s bin directory, located at $JAVA_HOME/bin, and in order to run it, you need to create policy file to enable jstatd to run without security exceptions.  For this, create a file called jstatd.all.policy in $JAVA_HOME/bin and paste the following contents into it:</p>
<pre class="brush: plain; title: ; notranslate">

grant codebase &quot;file:${java.home}/../lib/tools.jar&quot; {
permission java.security.AllPermission;};
</pre>
<p>Then, just run the jstatd application from the command line, like this:</p>
<pre class="brush: plain; title: ; notranslate">

./jstatd -J-Djava.security.policy=jstatd.all.policy
</pre>
<p>After this, check the ports that need to be opened to allow the remote instance of VisualVM to connect to it. This application opens 2 ports: the default RMI port, which is 1099, and then a random port, which changes every time you start the application.  To check which ports are used by jstatd, run the following command:<br />
<strong></strong></p>
<p><strong>netstat -nlp | grep jstatd</strong></p>
<p>And you should get an output like this:</p>
<pre class="brush: plain; title: ; notranslate">
tcp        0      0 :::39779                :::*              LISTEN      28661/jstatd
tcp        0      0 :::1099                 :::*              LISTEN      28661/jstatd
</pre>
<p>The 4th column indicates the ports that are open.  In this case, the ports that need to be opened in the firewall are 1099 and 39779.  To open this, you should check IPTables documentation for how to accomplish this.</p>
<p>After all ports are opened and jstatd is running, just open VisualVM, right click on Remote and select Add Remote Host, and finally type the IP address of the remote host.  After this, you&#8217;ll be able to see all Java-based applications running in the remote server, including Tomcat, Ant, jstatd and any other.<br />
The following screenshot shows a local VisualVM profiling an instance of Tomcat running in a remote host (click to enlarge):</p>
<p style="text-align: center;"><a rel="prettyPhoto" href="http://www.codefactorycr.com/wp-content/uploads/2011/03/javavisualvm.png"><img class="aligncenter size-full wp-image-45" title="javavisualvm" src="http://www.codefactorycr.com/wp-content/uploads/2011/03/javavisualvm.png" alt="" width="686" height="416" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codefactorycr.com/java-visualvm-to-profile-a-remote-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

