Archive for the 'java' Category

How to get rid of .svn folders

Wednesday, October 3rd, 2007

Use Ant!


<delete includeemptydirs=”true” >
<fileset dir=”${checkout.dir}” defaultexcludes=”false” >
<include name=”**/.svn/” />
</fileset>
</delete>

Faces component: Table with subtotals

Friday, March 9th, 2007

I tried to search all over the web for a Java Faces component, which will do a simple thing: totals and subtotals. And I failed. It seems that whole web is about how much more AJAX you could put everywhere, not how more useful your product could be for average user.

It could be done through a facet tag, which is obvious.

I think about that as competitive advantage for myself. If nobody done it - I should do it and be recognised for it!

Axis 1.x or Axis2?

Tuesday, September 26th, 2006

This blog post answers the questions about which version of Axis framework developers should use and also gives a short story about Axis development history. Short and must read.

Security in JSF apps

Wednesday, July 26th, 2006

Java Developer’s Journal published a very good article on security issues in JSF applications. The article consists of three pages. Two first pages provide the neccessary background information with the possible solution. The third page looks like the editors decided not to publish more details and just finish that article as fast as possible. And source code attachment does not work either.

Another link to check is JSF security project on Sourceforge

Filenet does exception handling - 2

Tuesday, February 14th, 2006

Week ago I wrote about unusual way of handling exceptions in Filenet Workplace.

Today I found another "gem":

JAVA:
  1. try
  2.            {
  3.                invokeNamedEvent(eventName, uiModule, request, new WcmEventResponse(response, this, okToRedirect));
  4.  
  5.                // If a non-null return value was returned from the invoke, check for true/false.  If the
  6.                // result matches "false", set the redirect flag to true indicating to cancel processing
  7.                // of the page.
  8.                Object result = request.getAttribute(INVOKE_RETURN_VALUE);
  9.                if ( result != null  result.toString().equals(String.valueOf(false)) )
  10.                    sendRedirectCalled = true;
  11.            }
  12.            catch (Exception e)
  13.            {
  14.                throw e;
  15.            }

Why to catch an exception here? And why string comparison is used when Boolean has a constructor with the String parameter?

It seems that Filenet doesn't use any of code review procedures internally. Developers just hack the code all day, make no comments and only two of them really understand the whole Filenet Workplace system. Or it was written long time ago by developer, which left the company, and nobody has time and/or will to do a proper system.

Technorati Tags: , ,

Dozer - object to object mapping tool

Wednesday, February 8th, 2006

Dozer - about

This one looks like very promising solution when I will need to convert normal Java beans to Filenet's property bags.

Technorati Tags: , , , ,

This is how exceptions are handled

Tuesday, February 7th, 2006
This is how WcmController.java, the "Controller" part of FileNet Workplace's implementation of MVC pattern, handles exceptions:

First, declare this:

JAVA:
  1. private Exception            configureWindowIdException = null;

Then, in ConfigurePage function, do this:

JAVA:
  1. public void configurePage(ServletContext applicationValue, HttpServletRequest request, long windowIdMode)
  2.       throws Exception
  3. {
  4.           ... skipped ...
  5.       configureWindowId(request);
  6.  
  7.       //  If configureWindowId constructed an exception, throw it.
  8.       if ( configureWindowIdException != null  )
  9.       {
  10.            if ( !sp.isSignedIn() )
  11.            {
  12.                // We attempted to propogate a window Id when not signed in
  13.                // probably the result of signing out of an info page.
  14.                // Don't throw.  Fix the windowId to mainWindow instead.
  15.                //
  16.                WindowID assignedId = new WindowID(null);
  17.                WindowID currentId  = new WindowID(null);
  18.  
  19.                assignWindowId(assignedId, currentId, false);
  20.                configureWindowState();
  21.                postProcessWindowId(assignedId, currentId, currentId,
  22.                                    false, false, false, false, false);
  23.            }
  24.            else
  25.                throw configureWindowIdException;
  26.       }
  27.           ... skipped ...
  28. }

What about good old try-catch?

There is no proper exception handling in Workplace. Should I send this piece to The Daily WTF?

Technorati Tags: ,

Filenet Workplace inheritance

Tuesday, February 7th, 2006

While discovering internals of Filenet Workplace I decided to create a class diagram.

Here is the starting diagram:

Apparently there is something wrong with the inheritance and everything use everything else and share the data. This is not OOP, it's good old VB style of programming done by somebody, who was converted to a java programmer by management decision.

More to go...

Technorati Tags: , , ,

Filenet Workplace oddities

Wednesday, February 1st, 2006
Now starting to investigate how Filenet Workplace works and how to integrate and extend it with Java Server Faces (JSF).

Created a new web project project in Rational Software Architect and imported Workplace into it. Right after the start discovered that it fails to run on localhost. "Huh? This is strange". Looked up the source code and found that marvelous piece of code:

JAVA:
  1. /**
  2.      * Validates HostName
  3.      *
  4.      * @param hostName The host nema to validate
  5.      * @return true, if valid.
  6.      */
  7.     public static boolean validateHostName( String hostName )
  8.     {
  9.         return !hostName.equalsIgnoreCase("localhost")  !validateIP(hostName);
  10.     }

What?! It just checks for localhost and validates IP of a host name. Ok, let's look into validateIP function:

JAVA:
  1. /**
  2.      *  Validates a String as a valid IP address.  Checks for four parts, and that
  3.      *  each part represents a numeric value between 0 and 255.
  4.      *
  5.      *  @param ipAddress
  6.      *  @return
  7.      */
  8.     public static boolean validateIP( String ipAddress )
  9.     {
  10.         boolean isValid = false;
  11.  
  12.         StringTokenizer st = new StringTokenizer(ipAddress, ".");
  13.         if ( st.countTokens() == 4 )
  14.         {
  15.             isValid = true;
  16.             while ( isValid  st.hasMoreTokens() )
  17.                 isValid = validateUnsignedByte(st.nextToken());
  18.         }
  19.  
  20.         return isValid;
  21.     }

Apparently there is no validation of correct IP address and Workplace should work normally if it would be started using

127.0.0.1

So I commented out first part of the code and Workspace now works on my localhost with no problems.

Technorati Tags: , , ,

Creating WebSphere 6 application MBeans

Friday, January 20th, 2006

This is a little step by step guide on how to create and register custom service with JMX interface on WebSphere:

1. Create class, which implements two interfaces:

JAVA:
  1. com.ibm.websphere.runtime.CustomService
  2. com.ibm.websphere.management.JMXManageable

2. Implement "initialize" method (inherited from CustomService)
This method has a parameter, Properties, which will contain properties defined via WS Administration console. We are interested in one property: externalConfigURLKey. This property contains path to external configuration file (if any is needed).

This is how to get the path:

JAVA:
  1. public void initialize(Properties configProperties) throws Exception {
  2.  readConfig(configProperties.getProperty(externalConfigURLKey));
  3. }

3. shutdown() method may be left blank.

4. implement getType() method (inherited from JMXManageable):

JAVA:
  1. public String getType() {
  2.  return "MyMBean";
  3. }

Remember the name you returned here!

5. implement getMBeanProperties:

JAVA:
  1. public Properties getMBeanProperties() {
  2.  Properties props = new Properties();
  3.  props.put("SpecialProperty", "value");
  4.  return props;
  5. }

I think this will return a list of properties, not declared in MBean descriptor. Read only, of course, since there is no setMBeanProperties() method.

6. implement getters and setters for properties you want to expose:

JAVA:
  1. public String getUserName() {
  2.  return this.userName;
  3. }
  4.  
  5. public void setUserName(String param) {
  6.  this.userName = param;
  7. }

7. Create MBean descriptor file, for example myTest.xml.

XML:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE MBean SYSTEM "MBeanDescriptor.dtd">
  3. <MBean type="MyMBean">
  4.     <attribute name="UserName" type="java.lang.String" getMethod="getUserName" setMethod="setUserName" />
  5. </MBean>

IMPORTANT: Make sure that type matches the value you remembered on the step 4!

8. Compile and package. Create .jar, having descriptor in the root. Place .jar somewhere accesible for WebSphere.

9. Start WebSphere and open Administration console.

10. Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Administration Services

11. Click on "Extension MBean providers"

12. Click on "New"

13. In the "Classpath" entry type the full path and name of your jar (created on step 8)

14. Type something memorable in two other fields and click Apply.

15. Click on "Extension MBeans" (on the left)

16. Click on "New"

17. Enter the name of MBean descriptor file (see step 7.)

for example:
myTest.xml

18. Enter the type name of your MBean. IMPORTANT: must be the same name as it was on steps 4 and 7.

19. Click Apply.

20. Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Custom Services

21. Click New

22. Place check on "Enable service at server startup".

23. Enter full class name (with package) of your MBean class (the one we created on step 1) into "Classname" field.

24. Enter something memorable in "Display Name"

25. Enter fill path and file name of the jar file (step 8) into "Classpath".

26. If your service requires configuration file (step 2) enter full path to it into " External Configuration URL"

27. Click on Apply.

28. Click on Save (on top)

29. Click Save.

30. Restart the server.

Here are the commands, used to verify MBean from admin console:

To run console:
wsadmin.bat -conntype SOAP -port 8881

To make sure that MBean started:
$AdminControl queryNames *:*,type=>

Store MBean in Tcl variable:
set mybean [$AdminControl queryNames *:*,type=MBeanName]

See MBean description:
$Help all $mybean

See MBean attributes and values:
$AdminControl getAttributes $mybean

Set specific attribute:
$AdminControl setAttribute $mybean UserName mike

Bad Behavior has blocked 45 access attempts in the last 7 days.