Apr
22
2010
I encountered a situation where I needed some simple Strings accessible to all my applications in glassfish. If you need environment variables in a single web app, it’s as easy as editing web.xml. However I’ve separated my application into several web and ejb modules for manageability concerns, thus I needed to set variables in the application server. I decided to create a Factory that returns a Hashtable of properties one can set in the application server. For this I run on Glassfish 2.1.1; I have not tested it with any other container though I do not see why it wouldn’t work.
Required Files
First the files. You’ll need the following jar. Save it in your application server’s lib directory. On my machine that is C:\sun\appserver\lib.
JNDIObjectFactory.jar
There are two classes in this jar:
com.ebleenterprises.naming.HashtableFactory
com.ebleenterprises.naming.StringFactory
Continue reading
2 comments | tags: J2EE, JAVA, JNDI | posted in Software
Feb
11
2010
Here is a quick piece of JQuery JavaScript code I had to write today to filter the rows shown in a table. Search terms are seperated by a space. The code should be self explanatory. Comments welcome.
Click here to see the code below in action.
<html>
<head>
<script src="jquery-1.4.1.min.js"></script>
<script>
$(document).ready(function() {
$("#searchInput").keyup(function(){
//hide all the rows
$("#fbody").find("tr").hide();
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $("#fbody").find("tr");
//Recursively filter the jquery object to get results.
$.each(data, function(i, v){
jo = jo.filter("*:contains('"+v+"')");
});
//show the rows that match.
jo.show();
//Removes the placeholder text
}).focus(function(){
this.value="";
$(this).css({"color":"black"});
$(this).unbind('focus');
}).css({"color":"#C0C0C0"});
});
</script>
</head>
<body>
<input id="searchInput" value="Type To Filter"><br/>
<table>
<thead>
<tr><th>Column1</th><th>Column2</th></tr>
</thead>
<tbody id="fbody">
<tr><td>cat</td><td>one</td></tr>
<tr><td>dog</td><td>two</td></tr>
<tr><td>cat</td><td>three</td></tr>
<tr><td>moose</td><td>four</td></tr>
<tr><td>mouse</td><td>five</td></tr>
<tr><td>dog</td><td>six</td></tr>
</tbody>
</table>
</body>
</html>
UPDATE:
To make this be insensitive to case, you need to modify it slightly.
The following code creates a custom jquery selector for case-insensitive matching:
$.expr[':'].containsIgnoreCase = function(e,i,m){
return jQuery(e).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
The complete code would then be:
<html>
<head>
<script src="jquery-1.4.1.min.js"></script>
<script>
$(document).ready(function() {
//Declare the custom selector 'containsIgnoreCase'.
$.expr[':'].containsIgnoreCase = function(n,i,m){
return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
$("#searchInput").keyup(function(){
$("#fbody").find("tr").hide();
var data = this.value.split(" ");
var jo = $("#fbody").find("tr");
$.each(data, function(i, v){
//Use the new containsIgnoreCase function instead
jo = jo.filter("*:containsIgnoreCase('"+v+"')");
});
jo.show();
}).focus(function(){
this.value="";
$(this).css({"color":"black"});
$(this).unbind('focus');
}).css({"color":"#C0C0C0"});
});
</script>
</head>
<body>
<input value="Type To Filter"><br/>
<table>
<thead>
<tr><th>Column1</th><th>Column2</th></tr>
</thead>
<tbody>
<tr><td>cat</td><td>one</td></tr>
<tr><td>dog</td><td>two</td></tr>
<tr><td>cat</td><td>three</td></tr>
<tr><td>moose</td><td>four</td></tr>
<tr><td>mouse</td><td>five</td></tr>
<tr><td>dog</td><td>six</td></tr>
</tbody>
</table>
</body>
</html>
3 comments | tags: JavaScript, JQuery | posted in Software
Nov
10
2009
The sample code attached below is a complete example for uploading multiple files using flash cs3 and java. After much searching I could not find a complete Flash File uploading tutorial that utilized java; most if not all are for php. This flash interface provides progress for each file independently, and upon completion can notify a javascript function. The files are sent to a simple JAVA servlet where they are saved to the local file system.

For the java servlet there are two library requirements:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
They are included in the web/WEB-INF/lib folder. The source files are saved as a Netbeans 6.7 project with Glassfish set as the target server. It is simple to open the project and change the target server. Both the compiled flash and source file are in the web folder.
I extracted two settings to variables listed in the index.html file so that this could be used without recompiling/editing the flash file. The first variable url is the address of the java servlet to send the files to. The second variable is f and is the name of the javascript function to call when each file is uploaded. f is optional. These variables need to be set 3 times in the index.html file. See the file for further documentation.
I expect to update the source code slightly over the next couple weeks. I will replace the zip file with the latest as updates are completed.
source files
1 comment | tags: AS3, CS3, Flash, Glassfish, JAVA | posted in Software
Aug
26
2009
I am going to go over setting up Glassfish Enterprise v2.1 in a windows clustered high availability environment. For this we will be using two Windows 2003 servers with two network interface cards (NIC) in each server that are network loadbalanced, 2 instances of IIS as the web container and 4 instances of glassfish with HADB behind IIS. You may ask why, and the reason is simply those were the technologies I had to work with; my task was to move from JBOSS to Glassfish. I will attempt to go over this setup in great detail, so as anyone with a basic understanding of these technologies should be able to get this running. For all of the images in the post, click on them for a full size version.
Continue reading
1 comment | tags: Cluster, Glassfish, HADB, IIS, JAVA, NLB, Server, windows | posted in Software
Aug
13
2009
Just a quick note about a simple but annoying error I encountered when porting an app to glassfish; The code in question was as follows:
...
Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(str));
SecretKeySpec key = new SecretKeySpec( KEY_BASE, "DES" );
private static Cipher ecipher = Cipher.getInstance( "DES");
ecipher.init( Cipher.ENCRYPT_MODE, key );
byte[] enc = ecipher.doFinal( bbuf.array() );
...
The code above just converts a string (stored as str here) to UTF-8 then encrypts it using DES. Equivalently you could use str.getBytes() for the UTF conversion. The code above worked fine on JBOSS, and worked fine stand alone. It even worked on my glassfish test server, however when deployed on glassfish enterprise I started getting the following stacktrace: Continue reading
5 comments | tags: Glassfish, JAVA, JBoss, Security | posted in Software
Aug
2
2009
First day out on Hoosier R-Compound Tires. More Later.
no comments | posted in Events, Racing
Jul
18
2009
There are many reasons you may want some of your content outside of the application server root. Perhaps you wish to share the content between applications or even webservers, or maybe you temporarily write data from a database to be served. Regardless, serving static content in glassfish is extremely easy. There are two ways to accomplish this; at the server level and at the application level.
Server level
First we will look at the server level, this will make your information available server wide, outside of any application context. Lets say you have images you wish to serve in the directory C:\media. In the glassfish admin console expand configuration > http service > virtual servers. Select ‘server’ then scroll to the bottom and select ‘add property’.
For name use: alternatedocroot_1, for value use: from=/media/* dir=C:/
Keep in mind that glassfish expects the directory in the URL pattern to exist, so the from= is not just the URL pattern, but it is also the path relative to the dir=.
Continue reading
5 comments | tags: Glassfish, JAVA, Server, virtual directory | posted in Software
Jul
12
2009
The third race of the season was today. The event started with Mike calling me as he was leaving for the race to say my oil disposal container with nearly 7 quarts of oil in it from the last oil change of the vette was leaking all over the garage. The actual race however was fun… I am getting rather good at maintaining control of the car through slides, guess I just need to learn to drive better so I slide less and get better times. New tires probably wouldn’t hurt either. What wasn’t fun is that I put my phone in my glove box so it wouldn’t fly around in the car. Well, at some point when I was breaking hard it managed to fly through a little gap in the back of the glove box. So it is now somewhere buried in the car; I don’t know where, I can only hear it. If you try to call me my car will ring and I will not answer (obviously), but maybe the car will? Have a couple pictures from the event, but they are on my phone, which is in the car… literally.
no comments | posted in Events, Racing