Posts

Runtime.exec() pretty exciting stuff

The Challenge - why i can't ignore the small stuff I have been creating batch job processes that will call EJBs. The issue with this is that the Application server process runs under a certain user id. The user id might only be accessible to a certain group that maintains the Application servers like a middle ware group. With this, any file that is written out by the EJB process in the application server will be created using the user id running the process. Security access to the output files by the process will default to the user id of the application server process. So, i want to write a file that has a different user id than the user id of an invoked java process. for example, if a java program was invoked by a user id A1234 i want the file to be written under a different user id B5678. Simple enough ? (Please take note that i am running the java process under a unix environment) My approach to the challenge I don't think there will be any utilities in Java that i can use

Google Web Toolkit -- adapting pains and issues

I have been first exposed to GWT on November 2006 and in one of our Java User group meeting. At that time we are looking to replace our ancient applet based web application. I saw the similarities on how GWT is similar to Java Swing in some of its components. Surely enough our group adapted and went with GWT. Here are the major issues that we have encountered. The issues are based on some wrong assumptions about GWT. Here is some points that our team missed about GWT. - GWT is JavaScript - JavaScript is executed in the clients Browser - GWT is not a web application framework - Be Aware of GWT Security issues GWT is JavaScript Even though GWT is coded using Java and leverages Java Tools, at the end of the day it is still JavaScript. So it is subjected to JavaScript issues like the following: - Threading - JavaScript is event driven and has single threaded model for development. So codes that are executed will be solely based on events. - Code size - even though there is no limit on how

Web Services - separation of definition and implementation

Understanding Web Services. Services has been in our desktops for years. If you have a PC , Go to Control Panel --> Administrative Tools --> Services. The web is taking an evolutionary leap to adapt this software architecture which has been very successful in our desktops. What is a web service ? In my approach in trying to understand what a web service is we go to the basics, find a definition of what a web service is. Here is the definition from the W3C web site (http://www.w3.org/TR/2004/NOTE-ws-arch-20040211/). A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. From the definition above we can infer the following: 1. intero

Java Generics - Be careful with SubTypes

In Java versions before the Tiger (Java 5.0) a Collection as we know it, will only contain Objects . The compiler knows that any Object can be put in the collection. The inability of the compiler to identify the intent of the programmer to use a collection of a particular type probably caused a lot of time spent on debugging ClassCastExceptions . Hello and Welcome Generics Generics in Java 5.0 (and versions after) will allow you to define a type for a Collection. The use of generics is not limited for typing Collections but I will only touch on this subject because it brings me great joy to know that i can express during compile time that i want a certain type of Collection. It was really a pain to experience it during runtime, specially when you need to deploy an application. Before Java 5.0 Sample code for a Java Collection before Java 5.0 Here is a sample code on how a Collection is used before Java 5.0 1 List listFoo = new ArrayList() ; 2 listFoo.add(new Foo()); 3 Foo aFoo = (Foo)

XMLBeans - Spare me the parsing and mapping !

I have been using Castor(http://www.castor.org) for a while to translate XML to JavaBeans vice versa. It was ok and reliable but our XML got complicated, it was tedious and cumbersome to maintain the XML Mapping file. Our mapping file keeps growing bigger as our objects gets more complicated. On top of that we have to maintain our XML schemas as well. So we have to maintain the XML mapping file and the XML schema. Then i stumbled upon XMLBeans. XMLBeans got me hooked just by not having to maintain a mapping file. Here are the few easy steps that i followed when i used XMLBeans. 1.) Download and Install XMLBeans (http://xmlbeans.apache.org/). I got version 2.1.0 2.) Create the XML Schema 3.) Do a SCOMP (Please refer to XMLBeans documentation) 4.) Once the XMLBeans jar for my XML Schema was created then it was ready to use. Here is a sample Code: Sample Code processing an XML Message to an Object xmlTest is the XML Message in String InstructorQualification is the root element of the XML

Java Annotations - Simple Explanation

Java 5.0 added a lot of language features to Java. One of the new features is Annotations. Annotations are tags in the source code that can be processed by a tool, compiler etc. (e.g. JavaDoc comments "@author"). The purpose of annotations is to simplify programming by helping programmers avoid boiler-plate code. Annotations are not part of the program itself, they provide data about the program. They have no effect on the code that they annotate. Uses for Annotations: 1. Information for the compiler 2. Deployment time processing 3. Runtime processing How do annotations work? Annotations can be applied to packages, classes, parameters, variables, fields or methods. It is defined using an "@" syntax. Annotations has a corresponding annotation type. The annotation type defines the content of the metadata. There are predefined annotations in Java as well as some API's provide their own annotation library. But to define your own annotation, here is how. Defining a s