Tuesday, December 16, 2008

XQuery XQL

Combine SQL, OQL (Object Query Language) and XPath (XML Path Language).

Monday, December 15, 2008

Method signature and method header

The signature of a method consists of the name of the method and the description (i.e., type, number, and position) of its parameters.

Example:
  • toUpperCase()
  • println(String s)
Note: the names of the parameters have no relevance for the signature

The header of a method consists of the signature plus the description of (the type of) the result.

Example:
  • String toUpperCase()
  • void println(String s)
The keyword void denotes the fact that the method does not return any result (i.e., the method implements an action and not a function).

Two methods of the same class can have the same name, provided they have different signatures. Methods with the same name (but with different signatures) are said to be overloaded. For example, the substring() method in the class String.

Thursday, November 20, 2008

2G Memory is not enough for RSA Profile

IBM RSA 7.0.0.7, 2G memory, not able to start WAS 6.1.19 server Profile.

JVMDUMP013I Processed Dump Event "systhrow", detail "java/lang/OutOfMemoryError".

Friday, November 14, 2008

RSS - Really Simple Syndication

RSS is another way of building a dynamic content website and publishing news.

History 1997, now RSS 2.0 in 2003. 50% sites still use RSS 0.91, 25% RSS 1.0, 12.5% 0.9x and 12.5% 2.0.

With RSS,
  1. you create a RSS document and save it with a xml extension
  2. upload the file to your website
  3. register it with a RSS aggregator
The aggregator searches the registered websites for RSS documents, verify the link and displays information about the feed so clients can link to documents that interests them.

Java RSS programming - ROME
Render RSS on web pages - RSS2HTML
Include rss2html output in a html page - Server Side Include (xyz.shtml)

Thursday, October 23, 2008

Start Tomcat in Eclipse

Error: Timeout waiting for Tomcat v6.0 Server at localhost to start. Server did not start after 45s.

Solution: Window -> Preferences -> Server -> Server timeout delay

set it to Unlimited.

Monday, October 20, 2008

Enabling PostgreSQL on Linux System Startup

#chkconfig --list to list all services

To enable PostgreSQL at startup
#chkconfig --all postgresql
#chkconfig postgresql on --level 2
#chkconfig postgresql on --level 3
#chkconfig postgresql on --level 5

Thursday, October 02, 2008

RUP Notes

The Rational Unified Process (RUP) is a proprietorial process that has been developed by the Rational Software Corporation, now part of IBM.

RUP provides the software developer with a DISCIPLINED approach to the development process.

The aim of RUP is to ensure a high-quality result that satisfies user requirements within a predictable budget and schedule. It was designed to be fully compatible with object-oriented technology and the UML. It supports component-based software development.

RUP is a configurable process. It uses use cases to drive the development activities. Use cases facilitate the development from the beginning of the development process through to testing. And they give you a means to trace the process flow through the development of the system and the delivered product.

RUP is the opposite of sequential approaches. It is an iterative and incremental approach to the software life cycle. RUP encourages continuous integration. (Note, here it is "encourage", which means you still need to implemente your own continuous integration, or also called continuous build. Since RUP as a process to focus the final executible deliverables, continuous build servics as compliment to build the deliverables automatically. Sometime the build can also include regression tests which is even better.)

RUP deals errors and flaws in the system over successive iterations, thus makes the system more robust and stable.

Coming behind RUP are requirements management and change control. RM ensures the system better meets the customer's expectations, also limits the size of the project to acceptable levels(scope). Change control helps keep track of defects, misunderstandings, and project commitments and to associate them with specific artifacts.

RUP is architecture-centric, its early iterations has a main thrust to produce and validate a software architecture.

In RUP, quality control has been incorporated into the process. This quality assessment uses objective measurements and criteria for all activities and participants in the process.

RUP has four phases and each phase has iterations. At the end of each phase, comes a milestone, which is a predefined point in time by which certain goals must be achieved and certain decisions made. During the inception phase, the original vision of the product is transformed into a project(my understanding, a well defined plan, definition of deliveriables, iterations, etc.). Formulate the vision, establish business cases and specify the project scope, make decisions on what to invest time and money on. Business cases include success criteria, risk assessment, estimation of resources, phase plan indicating the dates of milestones, prototyping.

The goal of the elaboration phase is more thorough analysis of the problem domain, to establish and define the architecture, to address and eliminate high-rish elements of the project, to determine how the work should be divided into iterations(I think it is difficult but critical. It needs strategic thinking, knowledge and experience. But it is also where the value of a good architect lies.) At the end of the elaboration phase, the decision must be made to build or not the system.

The third phase is the construction. In its final iteration the construction delivers a constructed software system.

RUP defines a transition phase, where the product is supplied to its end-users. Plan the packaging, pricing, roll out, support, training, transition strategy, production details.

It's recommended to have a "postmortem" analysis of the project, addressing how well the original and revised success criteria have been met.

There are nine core workflows in the RUP, either engineering process workflows or supporting process workflows. Business modeling, requirements capture, application/system analysis and design, implementation, testing, deployment

Thursday, September 11, 2008

JDBC ResultSet Column Name with Multiple Tables

For SQL like, "select a.col1, b.col2 from atab a, btab b where a.id=b.aid and b.id=?", when extracting values from ResultSet, what column name to use?

Incorrect - a.col1, b.col2.
Correct - col1, col2.

What if same column names in both tables, like a.col3 and b.col3?

Write SQL like "select a.col3 as acol3, b.col3 as bcol3 ...", then name the column in getXXX method as acol3 and bcol3.

Thursday, August 28, 2008

Customize 401 Error Page with HTTP Basic Authentication

For HTTP Basic Authentication, you define the auth type as BASIC.

After adding an error-page element in web.xml to customize 401 error page, HTTP auth will not work.

So far with Tomcat 6.0, I have found no way to make them work.

Monday, August 25, 2008

Tomcat DataSourceRealm

PostgreSQL version 8.

userTable="schema1.users" works and the schema name should be lower case too in the database.

Schema1 or SCHEMA1 won't work.

Wednesday, August 06, 2008

External JACC Provider in WebSphere 6.1

In WebSphere Application Server version 6.1, you can choose Default Authorization or External Authorization by JACC Provider.
  1. Internal accepts "welcome.do" but external TAM provider doesn't, it accepts "/welcome.do"
  2. I switched from Default to External but failed to switch it back. Even from the admin console it looked fine, but the server kept using TAM as authorization provider. What I had to do was to reinstall RSA.

Friday, August 01, 2008

TAM Error AWXJC0050E

[8/1/08 11:16:51:373 EDT] 00000020 SystemErr R Caused by:
com.tivoli.pd.as.jacc.cfg.TAMConfigException: AWXJC0048E An error occurred during the configuration. The details are:
com.tivoli.pd.as.jacc.cfg.ConfigActionFailedException: AWXJC0050E The Tivoli Access Manager user, sec_master, failed to add the Tivoli Access Manager user, JACC_-264539269/cledt-123691.agna.amgreetings.com, to the Tivoli
Access Manager group, iv-admin. The details are: Wrappered Exception:java.net.BindException: Address already in use:
NET_Bind[HPDCO1050E Socket could not be created (8920).].. at
com.tivoli.pd.as.jacc.cfg.TAMConfigController.execute(TAMConfigController.java:156)

For this error, note the port 8920 in the message, then change the client listener port from default 8900:8999 to 8921:8999.

Have a $ in your password?

In WAS 6.1 administrative console, when define a LDAP connection and enter the Bind password. It has a $. For example, the password is "abc$$cba".

What you need to enter is "abc$$$$cba".

Wednesday, May 14, 2008

Struts InvalidCancelException

2.1. Bug 38374 - Validation always skipped with Globals.CANCEL_KEY




2.1.1. Issue: Cancel Processing



The Struts <html:cancel> tag sets a request parameter (org.apache.struts.taglib.html.Constants.CANCEL) which causes validation to be skipped.


Spoofing this request parameter however, could be used maliciously in order to circumvent an applications validation and proceed with the request processing with erroneous and potentially damaging data.


See [WWW] Bug 38374 for full details.



2.1.2. Resolution: Cancellable Property



A new cancellable property has been introduced which indicates whether an action is allowed to be cancelled or not. In Struts 1.2.9 this is set to true or false for an action in the struts-config.xml using the <set-property> notation. From Struts 1.3.x a new cancellable attribute has been added to the <action> element.


Now any action where the cancellable property is not set to true will throw an InvalidCancelException.



2.1.3. Upgrade Implications



Any existing applications that use the Cancel processing will need to modify their struts-config.xml to set the cancellable property for actions which require it.


In Struts 1.2.9 the <set-property> is used to set the cancellable property for an action....



<action path="/fooAction"
input="/foo.jsp"
validate="true">
<set-property property="cancellable" value="true"/>
<forward name="success" path="/bar.jsp"/>
</action>

From Struts 1.3.x a new cancellable attribute can be used....



<action path="/fooAction"
input="/foo.jsp"
validate="true"
cancellable="true">
<forward name="success" path="/bar.jsp"/>
</action>

In both Struts 1.2.9 and Struts 1.3.x an exception handler can be configured to handle the InvalidCancelException



<action path="/fooAction"
input="/foo.jsp"
validate="true"
cancellable="true">
<forward name="success" path="/bar.jsp"/>
<exception key="errors.cancel"
type="org.apache.struts.action.InvalidCancelException"
path="/foo.jsp"/>
</action>


2.1.4. Test Cases



This bug was tested using the struts-examples webapp (see struts-examples.war in the binary distribution). If you fire up the examples webapp, select the Taglib Test Pages link, then select the <html:cancel> link you will be presented with a page where you can try the Cancel button for four different configurations.

Tuesday, April 29, 2008

Cancel Button for CancellableFormController

input type="submit" name="_cancel" value="Cancel"

where by default "_cancel" is the cancelParamKey. You can use setCancelParamKey() to override it.

Redirect in Spring MVC

return new ModelAndView(new RedirectView(redirectURL, true), model);

Thursday, April 24, 2008

Form Validation Error Message

Use SpringFramework, SimpleFormController, and CustomDateEditor.

When the date input doesn't match the specified format, it will report an error message. The message is very much in Java developer's language, not user oriented.

To replace the message with your own, just put a line like that in your messages.properties,

typeMismatch=Invalid or incomplete input.

Spring Framework - Date Field in a SimpleFormController

  1. Override the initBinder method.
  2. Create a SimpleDateFormat, e.g. MM/dd/yyyy HH:mm:ss where M is month, d is day, y is year, H is hour(0-23), m is minute, and s is second.
  3. Set the date format lenient false, which means inputs do not have to match the format exactly
  4. Create a CustomDateEditor(dateFormat, true), where true means empty allowed.
  5. Register the editor to Date.class.

Thursday, April 10, 2008

Postgresql - Generate Primary Key before Insert

First define the primary key column as serial, it is a integer, but a sequence table will be created automatically to match it. For example, if you define an April_ID as type serial in table April, a sequence table called April_April_ID_SEQ will be created automatically when creating the April table.

Second in your program, use select nextval('schema.april_april_id_seq') to obtain the next value for primary key. You don't need to plus 1 since Postgresql does it for you. If using Spring JDBC template, just call getJdbcTemplate().queryForInt(the sql).

Third, use the value just obtained as parameter in the insert sql.

Done.

Monday, April 07, 2008

Velocity Layout in Spring

Spring 2.5.2/Velocity 1.5

In web.xml, define org.springframework.web.servlet.DispatcherServlet as spring. Mapping *.xhtml to spring. I leave html for real html files.

In spring-servlet.xml, define

viewResolver class=org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver

  • viewClass = org.springframework.web.servlet.view.velocity.VelocityLayoutView
  • layoutUrl = layouts/mainlayout.vm
  • cache = true
  • suffix = .vm
  • exposeRequestAttributes = true
  • exposeSessionAttributes = true
  • exposeSpringMacroHelpers = true
  • dateToolAttribute = dateTool
  • numberToolAttribute = numberTool

velocityConfigurer class = org.springframework.web.servlet.view.velocity.VelocityConfigurer

  • resourceLoaderPath = WEB-INF/views
  • velocityProperties directive.foreach.counter.name = loopCounter
  • directive.foreach.counter.initial.value=0

Create a layout file, mainlayout.vm under WEB-INF/views/layouts. Put html, body, stylesheet stuff in. Note the stylesheet file shall sit outside WEB-INF. e.g. stylesheet href = "includes/main.css" means the main.css file sits at [web-root]/includes forlder.

Put $screen_content whereever you want.

In spring controller, return the ModelAndView name "dashboard", create a dashboard.vm file under WEB-INF/views.

In the dashboard.vm file, put any content in.

Monday, March 31, 2008

Books for JMS

Enterprise Messaging Using JMS and IBM(R) WebSphere(R) (IBM Press Book) (Paperback)
  • Paperback: 352 pages
  • Publisher: IBM Press (February 25, 2004)
  • Language: English
  • ISBN-10: 0131468634
  • ISBN-13: 978-0131468634
Editorial Reviews

This book offers start-to-finish guidance for building reliable, high-performance JMS-based messaging infrastructure with IBM WebSphere technologies.

IBM expert Kareem Yusuf systematically introduces the latest versions of JMS—both 1.1 and 1.02b. Once you've thoroughly mastered JMS development on any platform, Yusuf turns to the exceptional JMS support found in IBM's WebSphere products. Using extensive code examples, he walks you step-by-step through WebSphere JMS development, configuration, deployment, and administration in several real-world scenarios.

Coverage includes:
  • Roles and goals of messaging infrastructure in the enterprise
  • Key JMS concepts: messaging domains, messages, and Application Server Facilities
  • Defining/structuring content, choosing message types, and manipulating messages
  • The JMS API, explained through detailed code examples
  • Using JMS with EJB, message-driven beans, servlets, and portlets
  • Working with IBM WebSphere JMS providers, administered objects, and tools
  • Hands-on tutorials: EJB message exchange, integration with non-JMS applications, and SSL security
  • Resource location and physical topologies for maximizing availability and efficiency

Whether you're developing enterprise messaging infrastructure, architecting it, or managing it, this bookdelivers indispensable guidance-straight from the frontlines.

HTTP Request Headers

An add-on called Tamper Data on Firefox can add and modify HTTP request headers. It can even read input from a text file. This feature makes it very useful because you can save one header file for each applicaiton.

Its only problem is the header need to applied for every request. It doesn't remember or recall.

I also tested another add-on on Firefox called Modify Headers. It only worked the very first try but failed ever after.

Neither Tamper Data nor Modify Headers works on Internet Explorer.

It is said that IBM Page Details can work on IE.

Thursday, March 27, 2008

Books for Web Services

Web Services

Developing Web Services for Web Applications: A Guided Tour for Rational Application Developer and WebSphere Application Server (Ibm Illustrated Guide Series) (Paperback)

  • Paperback: 400 pages
  • Publisher: Mc Press; Pap/Cdr edition (September 15, 2005)
  • Language: English
  • ISBN-10: 1931182213
  • ISBN-13: 978-1931182218

Editorial Reviews

This book shows you how easy it is to create and use Web Services with IBM® Rational Application Developer or Web Developer, and WebSphere Application Server.

Intended for novice to intermediate Java programmers, Developing Web Services for Web Applications teaches users how to create Web Services, deploy Web Services to a server, and create client applications that use Web Services. Each chapter of the book teaches a key Web Service concept and takes you on a detailed, guided tour for creating or using a particular Web Service. Even if you’re completely new to Web Services, by the time you finish the lessons in this book, you’ll have all the skills needed to create useful Java programs with Web Services.

Using the “guided tour” approach, the book comes with practical step-by-step instructions and numerous screen captures, making it easy to follow along. While most books teach how to use either a development tool or a particular technology, Developing Web Services for Web Applications combines learning about Web Services with using Rational Developer tools. Each chapter develops a complete Web Service and/or application, with sample code and solution files provided on the accompanying CD-ROM. Also included in each chapter are additional exercises to help reinforce the concepts covered in that chapter.

By the end of the tour, you’ll be able to use Rational Developer tools to build your own Web Services, and you’ll understand why Web Services are gaining popularity as a way to provide services across the Internet.

Developing Web Services for Web Applications:

  • Is perfect for all skill levels, from those taking their first steps to those looking to explore more advanced topics
  • Teaches you Web Services concepts and terminology as you learn how to use the Rational Developer tools
  • Shows you how to create, deploy, publish, and use Web Services
  • Explores troubleshooting, using relational databases, using JavaServer Faces Web applications, adding security features, and much more

Contents:

Introduction
Chapter 1: Creating your first Web service and Web application
Chapter 2: Deploying and publishing your Web service
Chapter 3: Discovering Web services
Chapter 4: Handling Web service errors
Chapter 5: Using databases, part 1
Chapter 6: Using databases, part 2
Chapter 7: Using Web services with JavaServer Faces, part 1
Chapter 8: Using Web services with JavaServer Faces, part 2
Chapter 9: Securing Web services, part 1
Chapter 10: Securing Web services, part 2
Appendix A: Installing WebSphere Express

JMS Suggested Readings

Introductions

JMS Programming

JMS and WebSphere

Samples

Web Services Suggested Readings

Introductions

Java Web Services

Samples

Tutorials

Tuesday, March 18, 2008

Struts Configuration Editor in RSA 7

Once we couldn't open struts configuration file using Struts Configuration Editor. Right click the file, the Editor was not shown in the list.

We solved it by doing the following,

Opened the welcome perspective, enabled web development. Went back to J2EE or Web perspective and right clicked the struts-config.xml, the Editor was listed.

Tuesday, March 04, 2008

J2C CICS COBOL

In COBOL, some field might be defined as "OCCURS 300 TIMES". IBM Rational Software Architect version 7.0.0.3 translates it to an array in Java Binding Class with both lower bound and upper bound 300.

That causes problem when client sends up less than 300 records.

I solved it by editing the generated Java Binding Class and modifying the lower bound validation to use 0 instead of 300.

Tomcat Debug in Eclipse

Tomcat can be started in non-debug mode, but in debug mode, it got error,

Transport dt_socket failed to initialize, rc = 509.

JAVA version = 1.4.2_16
JAVA_HOME = <>\j2sdk1.4.2_16\bin
IDE = Eclipse 3.2
Web Server = Tomcat 5.0.28

I solved this by copying the two dll files (dt_shmem.dll, dt_socket.dll) from "<>\j2sdk1.4.2_16\jre\bin" to "<>\j2sdk1.4.2_16\bin".

Tuesday, January 08, 2008

Commons Logging and IBM WebSphere 6.1

RSA 7.0.0.3/WAS 6.1.

Apache Commons Logging has a problem with WAS 6.1. Its Log4JLogger either can't be loaded or be reported not compatible with LogFactory.

The root cause is WebSphere uses commons-logging and so it's in the root classloader. In addition, WebSphere ships a commons-logging.properties with the following properties set:

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

Therefore by default the application will use JDK logging and not log4j. The solution is to ensure that the right classloader mode is set and the application has an appropriate commons-logging.properties:

Set application classloader mode as PARENT_LAST. Also, add a commons-logging.properties to the application classpath with the following entries:

priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

The priority flag was introduced in Commons Logging 1.1 to allow an ordering based on priority. To ensure that an application's commons-logging.properties will take precedence over WebSphere's file, a priority of greater that 0.0 must be set.

Wednesday, January 02, 2008

This project needs to migrate WTP metadata

Hello There, I had exactly the same error message and none of the above fixes worked. The problem I found were the following
1) The runtime the old code is still pointing to is WAS 6.0 not WAS 6.1 (in RAD7)
2) RAD7 has more options to change more settings

The Solution: I had to fix the problem on the WAR file that is used by the EAR file Following is my fix for the problem in RAD7 PART I with the WAR PROJECT
\---------------------------
1) Right click on the war project and click on properties.
2) Click on Targeted Runtimes in the properties
3) Now check your desired Runtime WebSphere Application Server 6.1
4) Now click on the WebSphere Application Server 6.1 Runtime in the same window
5) You will see under Runtime Composition com.ibm.ws.ast.st.runtime.61 JRE 5.0: WebSphere v61 JRE
6) Now click on Add/Remove Project Facets link in the same window
7) It opens a new windows Project Facets. This page has dependencies when checking the boxes. Therefore...
8) Here First check Java, I selected the version 5.0.
9) Then check Dynamic Web Module (as I am using web module), I selected 2.4
10) Then check WebSphere Web (coexistence) 6.1
11) Then check WebSphere Web (Extended) 6.1
12) Click Finish
13) Click OK in the properties window
14) Now again open the same properties window
15) You will see new types on the Left Hand Side(LHS) windows namely J2EE Module Dependencies.
16) Click J2EE Module Dependencies. Select from the drop down the EAR file name that should have this WAR file
17) Click Java Build Path on the LHS window.
18) Make sure you see WebSphere Application Server v6.1 under your libraries tab on the Right Hand Side(RHS) window.
19) Click on Project Facets and make sure you see the 4 facets namely Dynamic Web Module, Java, WebSphere Web (Co-existence) and WebSphere Web (Extended) listed with the correct values.
20) Click on the Server on the LHS window.
21) Make sure you see the WebSphere Application Server v6.1 selected on the RHS window. If not, select it.
22) Click on Targeted Runtimes. Mostly you should see this time only WebSphere Application Server v6.1
23) Click OK
24) Manually Refresh and Rebuild this project.

PART II with the EAR project
\----------------------------
1) Right click on the EAR project and click properties
2) Click J2EE module dependencies.
3) Make sure desired xxxxxx.war file is checked.
4) Click on Targeted Runtimes.
5) Make sure you have WebSphere Application server 6.1 is checked
6) Click on project Facets
7) Make sure you have EAR 1.4, WebSphere Web (coexistence) 6.1, WebSphere Web (Extended) 6.1 are selected. If not, go to step 5 and click on the add/remove proejct facets link to do it.
8) click on server and check WebSphere Application Server v6.1
9) Manually Refresh and Rebuild this project.

You should be all set. All the best.