Friday, December 21, 2007

IBM HATS in Passport Advantage

HATS version 7.0 under

Rational Software/IBM WebSphere Host Integration Solution (HIS) for ... v 7.0/

IBM WebSphere Host Access Transformation Services (HATS) Standard v7.0 ... (C97NZML)
IBM WebSphere Host Access Transformation Services Run-Time Web Enablement ... (C97P2ML)

It's so hard to find anything in IBM Passport Advantage.

Tuesday, December 11, 2007

CICS ECI Resource Adapter - execute timeout

The execute timeout can be specified at creating method in a J2C bean.

0 - No timeout, this is the default value.
any positive int value - in milliseconds

How to Add a VM Argument to WAS 6.1

Actually the WAS 6.1 is the embedded one inside RSA 7.0.

Open the Administrative Console. Navigate through server -> process definition -> Java Virtual Machine -> Customer Variables.

Done.

Monday, November 26, 2007

J2C CICS ECI - Generate Simple JSP

Do the same steps as generate a web service, instead, select Simple JSP at the J2EE Resource Type.

Enter /minzyWeb as the Web project, ou as the JSP folder.

Show Advanced, if the Resource Reference is missing, enter eisOrderUpdateRef.

Click on Finish.

Notice 4 jsp files were created under WebContent\ou.

J2C CICS ECI - Generate Web Service

Start Web Page, Web Service, or EJB from J2C Java Bean wizard.

Enter \minzyConnect\src\tliu\minzy\eis\ou\OrderUpdateJ2CImpl.java as the J2C bean implementation. Click on "Next >".

Select "Web Service" and click on "Next >".

Browse and select /minzyWeb, show advanced and enter eisOrderUpdateRef as the resource reference, keep JNDI lookup name as eis/OrderUpdate as proposed.

Click on Finish.

Notice minzyWeb was changed to have a reference to minzyConnect, 10 classes generated under tliu.minzy.eis.ou, OrderUpdateJ2CImpl.wsdl generated under WEB-INF/wsdl and webservices.xml, etc under WEB-INF.

Note, do not remove the "gen" folder. It is the generated folder for the 10 new classes.

J2C CICS ECI - Generate J2C Bean Classes

Select DIC44010.cpy and start J2C Java Bean wizard.

Select ECIResourceAdapter (IBM 6.0.2.1) under J2C 1.5. (CTG 6.1 needs this match up)

Give eis/OrderUpdate as JNDI name.

Click on "New...", select WAS v6.1 as server.

Enter tcp://10.104.252.233 as Connection URL. (For remote, tcp://, for WAS and CTG on same server, local:), AMGCOHA3 as server, 32006 as the port number, user and password etc.. (configurations here shall be obtained from CTG admin)

After that, enter minzyConnect as project, tliu.minzy.eis.ou as package, OrderUpdateJ2C as interface, the implementation class will automatically be given as OrderUpdateJ2CImpl.

At next step, click on Add... to add a method.

Give updateOrder as the method name.

Click on Browse... and select OrderUpdateBind as input type and check on Use the input type for output.

If execute time out is a required argument, enable the Show Advanced and expand Interaction Spec to select executeTimeout - int.

Click on Finish and enter DIC44010 as the Function name.

Click on Finish and generate the J2C Java bean.

Notice the OrderUpdateJ2C and OrderUpdateJ2CImpl were created under tliu.minzy.eis.ou, cicseci6021 i was created and minzyConnect was updated to have cicseci6021 in its build path.

Wednesday, November 21, 2007

J2C CICS ECI - Generate J2C Data Binding Classes

Select the DIC44010.cpy file and summon the J2C CICS/IMS Java Data Binding wizard.

Choose mapping COBOL to Java.

Select z/OS for Platform, IBM-037 for Code page. Click on Query.

Select the DFHCOMMAREA which is the CICS common area.

Select "Shorten names" as Generation Style, minzyConnect as project, tliu.minzy.eis.ou as package, OrderUpdateBind as class.

Class OrderUpdateBind, OrderUpdateBind_DFH_PAL_ID_DATA_DFH_EPC_DATA and OrderUpdateBind_DFH_PAL_ID_DATA will be created under tliu.minzy.eis.ou.

J2C CICS ECI - Obtain COBOL Copybook

RSA J2C wizard in version 7 accepts only the copybook of common area. It used to accept the whole COBOL program in WSAD version 5.1. I obtained the whole program and I found out I needed to trim it to the copybook only and rename it from DIC44010.ccp to DIC44010.cpy. The wizard actually tells the difference between ccp and cpy.

The copybook looks like this,
01 DFHCOMMAREA.
02 DFH-INPUT-FIELDS.
05 DFH-MRG-NBR PIC 9(07) VALUE ZEROS.
05 DFH-DC-NBR-FILLING PIC X(02) VALUE SPACES.
05 DFH-SESSION-CNT PIC 9(02) VALUE ZEROS.
05 DFH-PAL-ID-DATA OCCURS 5 TIMES.
10 DFH-PAL-ID-NBR PIC 9(03) VALUE ZEROS.
10 DFH-PAL-EPC-NBR PIC 9(09) VALUE ZEROS.
10 DFH-EPC-DATA OCCURS 300 TIMES.
15 DFH-EPC-NBR PIC 9(12) VALUE ZEROS.
02 DFH-STATUS-FIELDS.
05 DFH-RETURN-CODE PIC 99 VALUE ZEROS.
05 DFH-RETURN-TEXT PIC X(80) VALUE SPACES.
05 DFH-PROGRAM-NAME PIC X(08) VALUE SPACES.
05 DFH-ERROR-STATUS PIC X(04) VALUE SPACES.
05 DFH-ERROR-RECORD PIC X(16) VALUE SPACES.
05 DFH-ERROR-SET PIC X(16) VALUE SPACES.
05 DFH-ERROR-AREA PIC X(16) VALUE SPACES.
05 DFH-DML-SEQUENCE PIC 9(08) VALUE ZEROS.
Do not edit the file.

I created a eis folder under minzyConnect. I put DIC44010.cpy under the newly created eis folder.

J2C CICS ECI - Review the Environment

In this trial, I will create a J2C service to call a CICS COBOL program. I use
  • IBM Rational Software Architect (RSA) v 7.0.0.3
  • IBM WebSphere Application Server (WAS) v 6.1, embedded in RSA 7
  • IBM CICS Transaction Gateway (CTG) v 6.1
CTG connection URL is tcp://10.104.252.233, port 32006, server name AMGCOH3, user name ctgwebu, and password ***.

Note, if WAS and CTG sit at the same server, CTG connection URL shall be local:.

Project minzyConnect is created to hold the data binding and J2C beans.

Project minzy is created as EAR holder, and its module project minzyWeb, minzyEnt (for EJB), and minzyClient are also created.

Tuesday, November 20, 2007

CICS Transaction Gateway

Connection URL set to "local" if the servlet sits at the same server. Set to "tcp:" if the servlet needs to connect a remore CICS Transaction Gateway, e.g. tcp://9.100.101.102:2006.

Friday, November 16, 2007

Informatica Upgrade to 8.1.1 - Client

Informatica is a Web Service Hub. When the server upgrades to 8.1.1, from the client side, do the followings,
  1. Open the Hub's home page, e.g. http://host:7333/wsh/
  2. Click on the "Batch Web Services"
  3. Click on the WSDL icon under Metadata WSDL
  4. Right click on the pop-up page and select "View Source"
  5. Save the content as MetaData.wsdl
  6. Do the same for DataIntegration WSDL, save as DataIntegration.wsdl
  7. Import these two files to a RSA project
  8. Add axis-1.4.jar to the project
  9. Create a Java Application Run,
  10. Set main class as org.apache.axis.wsdl.WSDL2Java
  11. Check "Include libraries when searching for a main class" on
  12. Select Arguments tab
  13. Enter "--NStoPkg http://www.informatica.com/wsh=com.informatica.www -W informatica-8.1.1/MetaData.wsdl" as Program arguments, where the informatica-8.1.1 is the folder of MetaData.wsdl file
  14. Run this Java Application
  15. Informatica client code for MetaData service will be generated
  16. Do the same for DataIntegration service
  17. There are some changes from version 7, especially of the connection, workflow and folder
  18. Modify the client application accordingly

CICS ECI Resource Adapter

The CICS resource adapter makes use of interfaces within J2EE Connector Architecture to facilitate the communication between J2EE applications and CICS information systems. The JCA defines a programming interface called the Common Client Inteface (CCI). This interface can be used, with minor changes, to communicate with any EIS. This CICS Transaction Gateway provides resource adapters that implement the CCI for interfactions with CICS.
  • ECIResourceAdapter (IBM : 5.1): This version of the CICS ECI resource adapter is based on Version 1.0 of the J2EE Connector Architecture (JCA 1.0). Because CICS ECI resource adapter for Java verion 5.1 is a JCA 1.0 resource adapter, it will only run in a JCA 1.0 application server or WAS version 5.0.2 (or above). Select CICS 5.1 resource adapter if targeting a WAS v 5.0 server.
  • ECIResourceAdapter (IBM : 6.0.2): This version of the CICS ECI resource adapter is based on version 1.5 of the JCA (JCA 1.5). It runs on WAS 6.0.
  • ECIResourceAdapter (IBM : 7.0.0): This version based on JCA 1.5. It runs on WAS 6.1.

If you select Configure Resource Adapter Deployment on the Deployment Information page of the J2C wizard, you can use the Resource Adapter Deployment page to configure RAR.

The resource adapter can be deployed as a standalone resource adapter or as part of an EAR file. Typical environments use the standalone method, giving all modules on the application server visibility to the adapter.

Note: Multiple resource adapters should not be installed as standalone on the same runtime server, especially if they are for the same EIS type (for example, CICS ECI 5.1 and CICS ECI 6.2). This is because all standalone resource adapters share the same class loader.

My note: It's probably easier for application maintanence to deploy the adapter per EAR file.

Wednesday, October 31, 2007

Axis 1.1 and 1.2

Some Web Service software, such as Informatica, generate stub classes to access web services. Some classes were generated based on Axis 1.1 and they use org.apache.axis.enum.Style.

In Axis 1.2, that class has been replaced by org.apache.axis.constants.Style. When clients try to make connections to web services, it will get an error that enum.Style cannot be found.

I think it will solve the problem to regenerate the stub classes with Axis WSDL2Java emitter from the WSDL definition files. We will see the result after several days.

Monday, October 22, 2007

DelegetingActionProxy

DelegetingActionProxy solves the problem of having to create an action as subclasses of ActionSupport. It is better to define beans in the Spring application context are proxies to the Struts Actions.

For example, class SpringIndexAction extends Action and declares a setter for the productionManager property. We add an action declaration to the Struts configuration file struts-config.xml.
[action path="/sindex"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false"]
[forward name="success"
path=".index"/]
[/action]

Notice the action type is set to DelegatingActionProxy, which is a Spring class that delegates all calls to the real bean of the SpringIndexAction class.

Before we can use DelegatingActionProxy, we first need to add the ContextLoaderPlugin bean to the Struts configuration file.
[plug-in
className="org.springframework.web.struts.ContextLoaderPlugin"]
[set-property property="contextConfigLocation"
value="/WEB-INF/actionContext.xml"/]
[/plug-in]

We declare the SpringIndexAction in the actionContext.xml file.
[beans]
[bean name="/sindex" class="com.....actions.SpringIndexAction"]
[property name="productManager"][ref
bean="productManager"/][/property]
[/bean]
[/beans]

When we now make a request to the /sindex.do URL, DelegatingActionProxy looks up the bean with its name set to /sindex. It uses the beans defined in the WebApplicationContext that is loaded by the ContextLoaderPlugin declared in the file specified in its contextConfiguration property. The /sindex bean is the actual SpringIndexAction, it is instantiated, and its productManager property is set.

The difference after using DelegetingActionProxy is that the SpringIndexAction is a fully Spring-managed bean and we have no manual dependency lookup code in the Action.

Monday, October 15, 2007

Form-based Authentication in WAS

Form-based login

One of the login challenges defined in J2EE Specification is form-based login. It enables the application developer to customize the login process and present an application-specific form by making use of the Form Login Authentication Method.

Form login works in the following manner:

1. An unauthenticated user requests a resource protected by the Form Login authentication type.
2. The application server redirects the request to the Login Form defined previously in the Web deployment descriptor.
3. On the HTML login form, the user enters the user ID and password and submits the form.
4. The action triggered by the form submission runs a special WebSphere Application servlet j_security_check. The Web container, after receiving a request for the j_security_check servlet, dispatches the request to another WebSphere servlet that authenticates the user.
5. If the servlet authenticates the user successfully, the originally requested resource is displayed.

Form login configuration using WebSphere Studio

1. Open the web.xml file under the Web project. A Web Deployment Descriptor should be opened in a deployment descriptor editor window.
2. Select the Pages tab, then modify the Login section.
3. Type in the realm name, for example: SecureRealm.
4. Click the drop-down list and select FORM as the Authentication method.
5. In the Login page, click Browse and select your login page from the project, for example: /login/login.html.
6. In the Error page, click Browse and select your login page from the project, for example: /login/loginerror.html (we have used the same page for login and error, but you can define a custom error.jsp page that will present actual error code and error messages).
7. Save and close the Web deployment descriptor file.

Setting the Authentication Method for the application Web module will create a [login-config] section in a Web deployment descriptor XML file, as shown in the following example.

[login-config]
[auth-method]FORM[/auth-method]
[realm-name]SecureRealm[/realm-name]
[form-login-config]
[form-login-page]/login/login.html[/form-login-page]
[form-error-page]/login/loginerror.html[/form-error-page]
[/form-login-config]
[/login-config]

Simple form-based login does not require any extra code development on the server side. The j_security_check servlet used by WebSphere Application Server enforces only the name of the input fields that the developer should put in the custom Login Form. These fields are as follows:

* j_username should be the input field in which a user will type the user ID.
* j_password should be the input field into which the user will type the password.

The action required for the HTTP POST method is j_security_check. A simple HTML code for the custom Login Form is given in the following example:

[!-- ............... --]
[form method="post" action="/itsobank/j_security_check"]
[table width="80%"]
[tr]
[td width="20%" align="right"]Userid:[/td]
[td][input size="20" type="text" name="j_username" maxlength="25"][/td]
[/tr]
[tr]
[td align="right"]Password:[/td]
[td][input size="20" type="password" name="j_password" maxlength="25"][/td]
[/tr]
[tr]
[td][/td]
[td][input type="submit" name="action" value="Login"] [input type="reset" name="reset" value="Clear"][/td]
[/tr]
[/table]
[/form]
[!-- ............... --]

Form-based logout

One of the IBM’s extensions to the J2EE Specification is the form-based logout. After logging out, the user is required to re-authenticate to have access to protected resources again. This logout form can be on any page with calling a POST action on the ibm_security_logout servlet. This form must exist within the same Web application to which the user gets redirected after logging out.

[form method="post" action="ibm_security_logout" name="logout"]
[input type="submit" name="logout" value="Logout"]
[input type="hidden" name="logoutExitPage" value="/login/login.html"]
[/form]

A Real Case with WAS Security

This case worked under RSA 7.0 and WAS 6.1.

In the application, it defined two roles, tliu:passw0rd:101:101:Thomas Liu and authenticated_user. Only users with administrator role can access administrator pages and carry out administrator functions. Any users authenticated with a pair of user id and password can access general pages and carry out general functions.

In the application.xml file of the EAR project, two security-roles were defined.

[security-role id="admin"]
[role-name]administrator[/role-name]
[/security-role]
[security-role id="user"]
[role-name]authenticated_user[/role-name]
[/security-role]

In the ibm-application-bnd.xml file of the EAR project, one authorization table with two authorizations was defined.

[authorizationTable xmi:id="AuthorizationTable_1126620398213"]
[authorizations xmi:id="RoleAssignment_1126807102767"]
[specialSubjects
xmi:type="applicationbnd:AllAuthenticatedUsers"
xmi:id="AllAuthenticatedUsers_1140011292114"
name="AllAuthenticatedUsers" /]
[role
href="META-INF/application.xml#user" /]
[/authorizations]
[authorizations xmi:id="RoleAssignment_1140011292114"]
[role
href="META-INF/application.xml#admin" /]
[groups xmi:id="Group_1140011292114" name="ceadmin" /]
[/authorizations]
[/authorizationTable]

In the web.xml file of the web project, two security-constraint, one login-config, and two security-role were defined.

[security-constraint]
[display-name]Administrators Constraint[/display-name]
[web-resource-collection]
[web-resource-name](Administrator Web Resource Collection)[/web-resource-name]
[description][/description]
[url-pattern]/admin/*[/url-pattern]
[http-method]GET[/http-method]
[http-method]PUT[/http-method]
[http-method]HEAD[/http-method]
[http-method]DELETE[/http-method]
[http-method]OPTIONS[/http-method]
[/web-resource-collection]
[auth-constraint]
[description][/description]
[role-name]administrator[/role-name]
[/auth-constraint]
[user-data-constraint]
[transport-guarantee]NONE[/transport-guarantee]
[/user-data-constraint]
[/security-constraint]
[security-constraint]
[web-resource-collection]
[web-resource-name](Users Web Resource Collection)[/web-resource-name]
[description][/description]
[url-pattern]/document/*[/url-pattern]
[http-method]GET[/http-method]
[http-method]PUT[/http-method]
[http-method]HEAD[/http-method]
[http-method]POST[/http-method]
[http-method]DELETE[/http-method]
[/web-resource-collection]
[auth-constraint]
[description][/description]
[role-name]authenticated_user[/role-name]
[/auth-constraint]
[user-data-constraint]
[transport-guarantee]NONE[/transport-guarantee]
[/user-data-constraint]
[/security-constraint]
[login-config]
[auth-method]FORM[/auth-method]
[form-login-config]
[form-login-page]/login.do[/form-login-page]
[form-error-page]/login_error.do[/form-error-page]
[/form-login-config]
[/login-config]
[security-role]
[description][/description]
[role-name]administrator[/role-name]
[/security-role]
[security-role]
[description][/description]
[role-name]authenticated_user[/role-name]
[/security-role]


The above login-config enabled the application to use a WebSphere extension called Form-based authentication. WAS Form-based authentication will be introduced in a later post.

In WAS administrative console, in Applications - Enterprise Applications - [Appl] - Security role to user/group mapping, there were two lines

Role | Everyone? | All authenticated? | Mapped users | Mapped groups
authenticated_users | unchecked | checked | null | null
administrator | unchecked | unchecked | null | ceadmin


WAS was defined to use File-based J2EE security. See a previous post about File-based J2EE security for details.

In the groups.props, add a line ceadmin:101:tester:CE Administrative Group, where the 101 was the group number.

In the users.props, add a line tester:password:101:101:CE Admin Tester, where the first 101 was the user number and the second group number.

With the above definitions, the application was able to make use of WAS security and can distinguish users by their authentication and role.

Friday, October 12, 2007

LDAP Browser in Eclipse

Actually I was installing LDAP browser plugin in my Rational Software Architect 7. I defined a remote update site using the URL http://directory.apache.org/studio/update/1.x and installed the LDAP Browser on my RSA.

That site was somehow a little bit weird. I tried the connection for several times before I was able to see the LDAP browser selection.

I used the "Connections" view to set up a new connection to LDAP server. After connected, I switched to the LDAP Browser view and saw three roots, DIT, Searches and Bookmarks.

The LDAP server which I connected was quite a big one. I easily got lost in the DIT tree. So I had to use the search. I learned something new here which was called the LDAP query.

For example, I needed to search any records that has a uid of ABC. What I needed to put in the "Filter" was (&(uid=ABC)). In my application, it had a query like (&(cn=my_group)(member=uid={0}, *)). It was very interesting, at least to me, since LDAP query was a new thing to me.

The searching speed was actually quite cool. Boom, the result was out. Since I would need to view that record from time to time. I saved it as a bookmark.

So far, the experience was good.

Friday, October 05, 2007

WAS 6.1/RSA 7.0 File-based Authentication

To enable file-based authentication,
  1. start up WAS 6.1 in RSA 7.0
  2. run administrative console
  3. security > secure administration, applications, and infrastructure
  4. check on "Enable administrative security"
  5. check on "Enable application security" (might be checked on automatically when check on "Enable administrative security")
  6. check off "Use Java 2 security to restrict ..." (if on, be ready to define web resource and beans and roles)
  7. select "Standalone custom registry" from the "Available realm definitions"
  8. click on "Set as current"
  9. click on "Configuration", the "Standalone custom registry" page will be shown
  10. click on "Custom properties"
  11. add two properties, usersFile ${USER_INSTALL_ROOT}/File-based_JACC/users.props, groupsFile $USER_INSTALL_ROOT}/File-based_JACC/groups.props
  12. in Windows explorer, go to folder \runtimes\base_v61\profiles\AppSrv01, e.g. C:\Program Files\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01, and create a new folder "File-based_JACC"
  13. under the newly created folder, create two files, users.props and groups.props,
  14. in users.props, add entry "wsadmin:password:100:100:Administrator"
  15. in groups.props, add entry "admins:100:wsadmin:Administrative group"
  16. go back to "Standalone custom registry" page in the administrative console
  17. enter "wsadmin" into "Primary administrative user name"
  18. select "Automatically generated server identity"
  19. make sure the "Custom registry class name" is "com.ibm.websphere.security.FileRegistrySample" (shall be by default)
  20. click on "OK" and click on "Save" if asked
  21. click on "Apply" and click on "Save" if asked
  22. right click on the "WebSphere Application Server v6.1" in "Servers" view and select "Open"
  23. expand "Security" and check on "Security is enabled on this server"
  24. enter "wsadmin" in "User ID" and "password" in "Password"
  25. save changes made to the server
  26. restart the server, the server should be ready to use file-based authentication.

Wednesday, October 03, 2007

Ant with JUnit in WID 6.0.2

Since I had a junit task in my ant script, I added the junit.jar into ant::Runtime::Classpath::Global Entries. The interesting part was, WID warned me no tools.jar in the classpath and asked me if I wanted to ignore it.

I searched tools.jar under WID installation. None of them was exactly fit to me. So I decided to ignore it.

Run the ant script, it completed successfully. Question is, what does tools.jar do in ant classpath?

IBM WebSphere Integration Developer

Current version is 6.0.2. Updates will be made available through the Rational Product Updater. As I installed it on 10/2/2007, necessary updates were available and required to be installed.
  • WebSphere Integration Developer Fix Pack 6.0.2.2
  • WebSphere Integration Developer 6.0.2.2 Interim Fix 002
  • WebSphere Integration Developer 6.0.2.2 National Language Support Interim Fix
  • J2EE Connector Tools 6.0.1.5
Downloading these fixpacks failed three times since the operation timed out. Learned from IBM forum that the interim fix may cause error. Cross off the two interim fixes. Failed the fourth time.

If IBM WebSphere Process Server Test Environment is also installed, its updates are not provided through the Rational Product Updater, but may be obtained by visiting http://www.ibm.com/software/integration/wps/support/. Current updates are Fixpack 2 to 6.0.2, released on 7/31/2007.

Started using WID without updates. Since we use Harvest, I started with installing Harvest plugin. WID 6.0.2 uses Eclipse 3.0.2. Harvest plugin site is the same for Eclipse 3.2, 3.1, and 3.0. The site is http://supportconnectw.ca.com/public/harvesteclipse.

Carefully selected Eclipse 3.0, then plugin version 6.20.2. Check out a project from Harvest, no problem. Synchronize the workspace with Harvest, it suggested removing local files.

Harvest plugin was actually installed under rwd. Locate it and uninstall it. Do the plugin installation again, select 6.20.1 and then carefully select the destination to eclipse not rwd. This time the synchronization worked fine.

WID 6.0.2 uses Sun JDK 1.4.2 as default JRE. It has WAS 5.1 and 6.0, but not 6.1. It has the default perspective Business Integration, the only one cannot be found in Rational Software Architect 7.0.0.3.

Tuesday, October 02, 2007

JACC - Java Authorization Container Contract

The Java Authorization Container Contract (JACC) is a specification that was introduced in Java 2 Platform, Enterprise Edition (J2EE) 1.4 through the Java Specification Request (JSR) 115 process. This specification defines a contract between J2EE containers and authorization providers. This enables any third-party authorization providers to plug into any J2EE 1.4 Application Servers such as WebSphere to make authorization decisions when a J2EE resource is being accessed. The access decisions is made through the standard java.security.Policy object.

When an authenticated user makes a request to a web or a EJB resource, the security runtime makes the decision of whether to allow the access. This is called an access decision. Based on JACC, the appropriate permission object is created, the appropriate policy context handlers are registered, and the appropriate policy context identifier (contextID) is set. A call is made to the java.security.Policy object that is implemented by the provider to make the access decision.

In IBM WebSphere Application Server (WAS), when security is enabled, the default authorization is used unless a JACC provider is specified. The default authorization does not require special setup, and the default authorization engine makes all of the authorization decisions. However, if a JACC provider is configured and set up for WAS, all of the enterprise bean and web resource access decision will be delegated to the JACC provider.

Monday, October 01, 2007

WAS 6.1 Startup Error on SystemOut.log

My WAS 6.1 on RSA 7.0.0.3 has this error when starts up.
[10/1/07 9:48:28:785 EDT] 0000000a WrappingFileO E archiveCurrentFile TRAS0016E: An unexpected exception while trying to archive log file C:\Program Files\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\logs\server1\SystemOut.log Exception is java.io.IOException: Unable to rename file C:\Program Files\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\logs\server1\SystemOut.log to C:\Program Files\IBM\SDP70\runtimes\base_v61\profiles\AppSrv01\logs\server1\SystemOut_07.10.01_09.48.28.log. Logging continues.
It was said on IBM WID Forum that the fix for this issue will be available in 6.0.2.25 fixpack.

Friday, September 28, 2007

Log4JCategoryLog

Apache common logging 1.0 used Log4JCategoryLog. In version 1.1, replace it with Log4JLogger. The commons-logging.properties file will look like this,
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

web.xml version 2.4

In web.xml version 2.4, taglib shall be defined inside a jsp-config section.

Monday, September 17, 2007

升级FC6->FC7

折腾了好几个晚上,想把自己的一台老爷机从FC6升级到FC7,未果。
根本的原因是,FC7不认PATA的硬盘。就算用RESCUE碟都不行。
记住,自此一定不能升级内核。

Tuesday, September 11, 2007

Hibernate and Struts - Identifier Altered

In our application, we used Hibernate 3.1.2, Spring 1.2.6 and Struts 1.2.4. One of the page flows was to gather input from a form and insert a record into database then go back to the list page.

We saw messages like that,
org.hibernate.HibernateException: identifier of an instance of ... was altered ...
...
org.hibernate.event.def.DefaultFlushEventListener.onFlush...
...
In the beginning of investigation, we found the Hibernate related code did not flush after insert. We added the flush, but it didn't solve the problem.

Then we read Spring document and found HibernateTemplate recommended over Session. So we replaced Session with Template. But it didn't solve the problem.

Because because it had no problem going back to list after update, we tried to use saveOrUpdate and replace save. But it was the same.

Finally we noticed the Hibernate flush was scheduled after the page was forwarded, no matter what the setting of transaction.flush_before_completion was true or false. We also noticed the struts always recovered the form after forward. We tried to reset the data bean in the form right after insert. And this time, it solved the problem.

Thursday, September 06, 2007

Hibernate and MS SQL - Nullability Problem

The nullability problem happens when Hibernate 3 deletes an instance with any null value property defined not nullable.
org.springframework.orm.hibernate3.HibernateSystemException: not-null property references a null or transient value: com.ag.applications.forms.entity.qstnaire.QstnaireBean.qstnaireNam; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ag.applications.forms.entity.qstnaire.QstnaireBean.qstnaireNam
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ag.applications.forms.entity.qstnaire.QstnaireBean.qstnaireNam
To get rid of the error, edit the hbm.xml file and change the not-null="true" to "false".

However, it is necessary to define some properties not nullable. In this case, modify the application and let the property has non-null value or get the instance from database by primary key, then delete it.

This problem was reported to Hibernate on August, 2007. No known release fixes it.

Wednesday, September 05, 2007

Hibernate and MS SQL - Delete Operation

When does delete operation, application prompts message,
Data Access Error: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition.
This is because Spring 1.2 is incompatible with Hibernate 3. I heard Spring 2.0 solved this problem, but I found a workaround solution with Spring 1.2.

Here is the solution, in applicationContext.xml, set the property "checkWriteOperations" of "org.springframework.orm.hibernate3.HibernateTemplate" to false.

Tuesday, September 04, 2007

Hibernate and MS SQL - Unsupported prepareStatement

Insert operation generated by Hibernate didn't work with MS SQL. I was using Hibernate 3.1.2, WAS 6.1, JVM 1.5. And I was testing two JDBC drivers.

For IBM ConnectJDBC for MS SQL,
java.sql.SQLException: [IBM][SQLServer JDBC Driver]Unsupported method: Connection.prepareStatement
at com.ibm.websphere.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.ibm.websphere.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.ibm.websphere.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at com.ibm.websphere.jdbcx.base.BasePooledConnection.prepareStatement(Unknown Source)
at com.ibm.websphere.jdbcx.base.BaseConnectionWrapper.prepareStatement(Unknown Source)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.pmiPrepareStatement(WSJdbcConnection.java:3980)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:3854)
For DirectData ConnectJDBC for MS SQL,
java.sql.SQLException: [DataDirect][SQLServer JDBC Driver]Unsupported method: Connection.prepareStatement(String, String[])
at com.ddtek.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.ddtek.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.ddtek.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at com.ddtek.jdbcx.base.BasePooledConnection.prepareStatement(Unknown Source)
at com.ddtek.jdbcx.base.BaseConnectionWrapper.prepareStatement(Unknown Source)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.pmiPrepareStatement(WSJdbcConnection.java:3980)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:3854)
There is a saying that the Connection.prepareStatement(String sql, String[] columnNames) is not supported. Workaround solution is to set the "hibernate.jdbc.use_get_generated_keys" to false in the hibernate settings, either in the properties or in the cfg.xml.

Here is the definition of the property.
Enable use of JDBC3 PreparedStatement.getGeneratedKeys() to retrieve natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+, set to false if your driver has problems with the Hibernate identifier generators. By default, tries to determine the driver capabilites using connection metadata.

eg. true|false

Here is the quote from mdiamonte in DataDirect forum.
Against SQL Server 2000, the driver can not implement this method correctly in the general case because SQL Server 2000 does not allow you to return the value of an arbitrary column from an insert, update or delete statement. At least not with out making an extra round trip to the server, which negates the purpose of this method.

I have seen implementations of this method by other drivers where the value returned will be the value of the identity column regardless of which column was actually asked for. I believe that implementation is bad. I feel it is much worse for a driver to return incorrect information than it is to not be able to return the information. Assuming the id column in the statement is an identity column, then Hibernate may have just gotten lucky that it worked in the testing that they did.

Tuesday, August 28, 2007

Migrate WASD 5.1 Application to RSA 7.0/WAS 6.1

Get the application source from Harvest repository. Disconnect Harvest connection.

Create a new web project and ear project in RSA on a new folder. Import source code from the old folder. Compile passed.

Deploy to the embedded WAS 6.1. Run.

Find the tld path problem. Old web.xml sets tlds under WEB_INF/, now application looks tlds under WEB_INF/tlds. Edit web.xml and fix it. WAS 6.1 automatically republishes the app and restart the app.

Get this exception.
[8/28/07 10:49:14:485 EDT] 00000036 WebApp E Exception caught while initializing context
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator' defined in ServletContext resource [/WEB-INF/declarativeServices.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.FatalBeanException: Could not instantiate class [org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator]; constructor threw exception; nested exception is java.lang.NoSuchMethodError: org/objectweb/asm/ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
org.springframework.beans.FatalBeanException: Could not instantiate class [org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator]; constructor threw exception; nested exception is java.lang.NoSuchMethodError: org/objectweb/asm/ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
java.lang.NoSuchMethodError: org/objectweb/asm/ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
Search Google. Find talks on incompatibility of asm, cglib, spring and hibernate. We are using
  • spring-1.2.6
  • hibernate-3.1.2
  • asm-1.5.3
  • cglib-2.1_3
Try to obtain the ear file from production system and deploy to WAS 6.1.

Encounter the same exception.

Several combinations tried. Finally this one worked.

Download spring-framework-1.2.9-with-dependencies.zip and extract the cglib-nodep-2.1_3.jar and replace the original cglib-2.1_3.jar. Redeploy the application in workspace to WAS 6.1 and restart server.

It is possibly both spring framework and hibernate depend on cglib, and further on asm, but they require different asm. cglib-nodep actually packages a revised asm, spring will have no need of a separate asm and let hiberate uses the asm exclusively. Hibernate may actually not need any cglib, but no time for this research yet.

Saturday, August 18, 2007

终于能在Red Hat中键入中文

关键是需要将默认的语言设置成简体中文,然后用Ctrl+Space在中英文之间切换。

默认的输入法是二笔,我不会,改成了智能拼音就好了。和用惯了的全拼有些区别,用用也就习惯了。

简体中文中好多系统菜单翻译得莫名其妙,试了试,不知道怎么切回英文。

Thursday, August 09, 2007

Compare Fuse Message Broker 4.1 to Apache Active MQ 4.1.1

  1. conf\activemq.xml: Fuse has one more block of comments.
  2. installsession_log.xml: only Fuse has.
  3. docs: Fuse has welcome.htm and more images.
  4. etc: only Fuse has etc folder, including license_agreement.txt and notices.txt. Apache puts these two files at the root directory.
  5. example is not compared.
  6. lib: Most differences are on the release number. Fuse is 4.1.2.4, Apache is 4.1.1. One noticable difference is Fuse has xbean-spring-fuse-2.7.0.0.jar, but Apache has xbean-spring-2.8.jar.

Monday, August 06, 2007

Unit Test - Piece of Logic Covered or Not?

Emma coverage report will show uncovered pieces of logic red. For example,
if (validField(fk.getName(), valueFK)) {
criteria.add(buildRestriction(propertyTypes[i], value, relationName));
criteriaCount.add(buildRestriction(propertyTypes[i], value, relationName));
}
In the unit test, you will need to make the validField returns true. And then the report will show them covered and mark them green.

JMS Implementation with RSA 7.0 and WAS 6.1

Environment:
IBM Rational Software Architect 7.0 with embedded WebSphere Application Server 6.1.

Purpose:
  • Create a JMS client application to send a simple message to a queue defined by WAS 6.1 default messaging provider.
  • Create a MDB to consume the message received by the queue.
Development:
  1. Open RSA, use the New wizard to create an Enterprise Application Project under J2EE group, if you cannot see this selection, check if you are using the J2EE perspective. I called the project minzy.
  2. Click "Show Runtimes" to make sure the v6.1 is selected.
  3. Click "New Modules" to create default modules, check off Web module and Connector module, which we don't need, and change the name of the EJB module to minzyEnt. It's only my preference, you can call it any name.
  4. Rename source folders to "src" in both minzyClient and minzyEnt.
  5. In minzyClient, create a package "tliu.minzy.client" and create a class "MessProducer" with main method.
  6. Delete default package.
  7. Edit MANIFEST.MF under META-INF and change Main-Class to tliu.minzy.client.MessProducer.
  8. From menu Project, select clean and select minzyClient, minzyEnt and minzy, error in minzy and minzyClient will be gone.
  9. In minzyEnt, create package tliu.minzy.ent, use New wizard to create a Enterprise Bean.
  10. Check "Message-driven bean", give name MessConsumer, select package tliu.minzy.ent and check on "Generate an annotated bean class".
  11. Make sure JMS type is javax.jms.MessageListener.
  12. Check off "Add bean to Class Diagram", diagrams are out of the scope.
  13. Now you see all error gone, we are ready to put real codes in.
Code in MessProducer:
    public static void main(String[] args) throws Exception {
InitialContext initCtx = new InitialContext();
javax.jms.ConnectionFactory qcf = (javax.jms.ConnectionFactory) initCtx.lookup("jms/minzyConnectionFactory");
Destination q = (Destination) initCtx.lookup("jms/minzyQueue");
Connection connection = qcf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer queueSender = session.createProducer(q);
TextMessage outMessage = session.createTextMessage();
outMessage.setText("Hello, minzy.");
outMessage.setJMSType("minzy");
outMessage.setJMSDestination(q);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(outMessage);
connection.close();
System.out.println("Minzy mess produced.");
}
Code in MessConsumerBean:
    public void onMessage(javax.jms.Message mess) {
TextMessage text = (TextMessage) mess;
try {
System.out.println("Message Received: " + text.getText());
} catch (JMSException e) {
System.out.println("Oops, exception.");
}
}
Packaging:
Export minzyClient to C:\development\applications\minzyClient.ear.
Export minzyEnt to C:\development\applications\minzyEnt.ear.

Deployment:
  1. In Servers view in RSA, select WebSphere Application Server v6.1 and start the server.
  2. After started, right click the server and select "Run administrative console".
  3. Navigate Service integration > Buses > New and create a bus "minzyBus".
  4. Navigate minzyBus > Bus members > Add and add server "cledt-123691Node02:server1".
  5. Open a command window, and change directory to "C:\Program Files\IBM\SDP70\runtimes\base_v61\bin", run "setupCmdLine.bat".
  6. Run "wsadmin -f installSdoRepository.jacl -createDb cledt-123691Node02 server1".
  7. Verify SDO Repository successfully started under Enterprise Applications. Note, install once per server.
  8. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL_RA -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -nodeName cledt-123691Node02". Note, install once per node.
  9. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -serverName server1 -nodeName cledt-123691Node02".
  10. Run "wsadmin -f ../util/sibwsInstall.jacl INSTALL_HTTP -installRoot "C:/Program Files/IBM/SDP70/runtimes/base_v61" -serverName server1 -nodeName cledt-123691Node02".
  11. In the admin console, navigate to Servers > Application Servers > server1 > Endpoint Listeners and select New. Specify SOAPHTTPChannel1 as name, http://cledt-123691.agna.amgreetings.com:9081/SOAPHTTPChannel1 as URL root, http://cledt-123691.agna.amgreetings.com:9081/sibws as WSDL root.
  12. Select the "Connection Properties" of SOAPHTTPChannel1, client New and select minzyBus.
  13. Go to minzyBus > Destinations, there should be a new destination called cledt-123691Node02.server1.SOAPHTTPChannel1Reply.
  14. Navigate minzyBus > Destinations > New and create a Queue type destination "minzyDestination".
  15. Navigate Resources > JMS Providers > Default messaging. Select Node as the scope.
  16. Select Connection factories and click New. Enter minzyConnectionFactory as name, jms/minzyConnectionFactory as JNDI name, select minzyBus, enter localhost:7277 in the "Provider endpoints" box, leave other default and click OK.
  17. Go back to Default messaging provider and select Queues. Click New.
  18. Enter minzyQueue as name, jms/minzyQueue as JNDI name, select minzyBus and minzyDestination. Click OK.
  19. Go back to Default messaging provider and select Activation specifications. Click New.
  20. Enter minzyActivation as name, eis/minzyActivation as JNDI name, jms/minzyQueue as Destination JNDI name and select minzyBus. Click OK and save all your changes.
  21. Install minzyEnt.ear in admin console. Make sure Deploy enterprise beans are checked. Enter eis/minzyActivation as Activation Specification Target and jms/minzyQueue as Destination.
  22. Restart server.
Run:

In a command line window, change directory to C:\Program Files\IBM\SDP70\runtimes\base_v61\bin. Run,

setupCmdLine.bat
launchClient \development\applications\minzyClient.ear -CCBootstrapPort=2810

In the command line window, you shall see,
WSCL0014I: Invoking the Application Client class tliu.minzy.client.MessProducer
Minzy mess produced.

In the server console, you shall see,
[8/6/07 13:33:32:455 EDT] 0000002f SystemOut O Message Received: Hello, minzy.

The End.

Thursday, August 02, 2007

WAS 6.1 - JMS Default Provider Administrative Aspect

In WAS 6.1, there is a default messaging JMS provider. It comes with WAS 6.1.

To list messages in a queue, go through this path,

Service integration > Buses > [TheBus] > Messaging engines > [cledt-123691Node01.server1-TheBus] > Queue points > [MyQueueDestination@cledt-123691Node01.server1-TheBus] > Runtime

you see the "Current message depth".

Select "Messages", you see messages and their position, identifier, state and transaction id. You can select any of them and click "Delete" or just click "Delete all" to delete them from the queue.

The message's identifier is actually a link. Click it to get the detail of the message. It shows
identifier, state, transaction id, message type, approximate length, time stamp, message wait time, current messaging engine arrival time, redelivered count, security user id, producer type, message id, correlation id, user id, format, JMS delivery mode, JMS expiration, JMS destination, JMS reply to destination, JMS redelivered, JMS type, JMSX delivery count, JMSX application id, discriminator, priority, reliability, time to live, reply discriminator, reply priority, reply reliability, reply time to live and system message id. All attributes are read only.

Click "Message body", you will get "Approximate total message size" in bytes, message body. The message body is also read only.

You can define Performance Monitoring Infrastructure(PMI) to collect JMS runtime statistics. You will need a PMI client to view these statistics. So far, Tivoli Performance Viewer(TPV) is the only known PMI client to us. TPV has not been tested so far. According to IBM, TPV comes with WAS 6.1 and is free.

Wednesday, July 25, 2007

WAS 6.1 in RSA 7.0

Try to run WAS 6.1 in RAS 7.0. Find conflict on port 2810.

In WAS 6.1, RMI ORB bootstrap port is defined 2810. Modify it to 7810.

Start WAS 6.1, still complain on port 2810. Restart RAS 7.0.

Profile name "AppSrv01", server name "server1".

From its log, it started. but in the RSA console, it still says starting. Also the publish failed and complained not started.

Even after 30 minutes, it still says starting. So I stopped it.

Restarted the workstation. Found port 2810 gone. Modify WAS 6.1 port back to 2810. Restart RSA.

Start WAS 6.1 and started.

Sunday, June 10, 2007

Fodero Core 5 Package Updater

I was having trouble with FC 5 Package Updater. This is out of the topic, but it is a good experience anyway.

I then opened a terminal window and run "yum update". It reported the error at Macromedia update. After some research, I was suggested replacing the /etc/yum.repos.d/macromedia-mplug.repo with the following content.

[macromedia]
name=Macromedia for i386 Linux
#baseurl=http://macromedia.rediris.es/rpm/
baseurl=http://sluglug.ucsc.edu/macromedia/rpm/
enabled=1
gpgcheck=1
#gpgkey=http://macromedia.mplug.org/FEDORA-GPG-KEY
gpgkey=http://sluglug.ucsc.edu/macromedia/FEDORA-GPG-KEY

After that, the Package Update came back to normal.

Thursday, May 31, 2007

Unique ID Generation

Generating globally unique IDs in a clustered, distributed environment is a common application requirement. A simple way is to combine the following four parts together.
  1. Unique to the System.currentTimeMillis()
  2. Unique to the IP address
  3. Unique to the object instance System.identityHashCode(this)
  4. Unique within a millisecond, SecureRandom
All ints and longs will be converted to a hex string of length 8.

A open source named Java UUID Generator is available at http://jug.safehaus.org/.

Business Delegate and Session Facade

What would the cardinality generally be between the Business Delegate objects and the Session Facade?

ONE to ONE. Often, the business delegate will have the same API as the session facade.

There is a close relationship between the BD and the SF. The client layer interacts with a BD. The BD would in turn, employ the Service Locator pattern to locate the SF. It is common to see a one-to-one mapping between the BD and the SF.

Monday, May 28, 2007

Testing Glossary

  • Black-box testing - testing that verifies that given input A the component or system being tested gives you expected results B.
  • Boundary-value testing - testing of unusual or extreme situations that your code should be able to handle.
  • Function testing - a part of system testing in which development staff confirm that their application meets the specified user requirements.
  • Integration testing - testing that verifies that several portions of software work together.
  • Regression testing - testing that ensures previously tested behaviors still work as expected after changes have been made to an application.
  • Stress testing - testing that ensures the system performs as expected under a high volume of transactions, high number of users, and so on. Also referred to as load testing.
  • White-box testing - testing that verifies specific line of code work as defined. Also referred to as clear-box testing.
  • Alpha testing - a testing period in which pre-release versions of software products are released to users who need access to the product before it it officially deployed. In return, these users will report any defects to the software developers. Alpha testing is typically followed by beta testing.
  • Beta testing - a similar process to alpha testing, except the software product should be less buggy.
  • Code inspection - a form of technical review in which the deliverable being reviewed is source code.
  • Peer view - a style of technical review in which a project artifact, or portion thereof, is inspected by a small group of experts.
  • Use-case scenario testing - a testing process in which users work through use cases with the aid of a facilitator to verify that a user interface prototype fulfills the needs of its users and that the identified classes for a system fulfill the requirements described in the use cases.
  • User testing - testing processes in which the user community, as opposed to developers, performs the tests.
  • User-interface testing - the testing of the user interface to ensure that it follows accepted standards and meets its requirements. User-interface testing is often referred to as graphical user interface (GUI) testing.

Friday, May 25, 2007

Session Data in Multiframed JSPs

Update or create a session in only one frame or before accessing any frame sets. For example, assuming there is no session already associated with the browser and a user accesses a multiframed JSP files, the browser issues concurrent requests for the JSP files. Because the requests are not part of any session, the JSP files end up creating multiple sessions and all the cookies are sent back to the browser. The browser honors only the last cookie that arrives. Therefore, the client can only retrieve the session associated with the last cookie. Creating a session before accessing multiframed pages that utilize JSP files is recommended.

JSPs will, be default, create an HttpSession if it does not already exist. A developer can use <% @page session="false" %> to turn off the automatic session creation from the JSP files that will not access the session. Then if the page needs access to the session information, the developer can use <% HttpSession session = HttpServletRequest.getSession(false); %> to get the already existing session that was created by the original session creating JSP file. This action helps prevent breaking session affinity on the initial loading of the frame pages.

Web Application Session Data

  • When developing new objects to be stored in the HTTP session, they should implement Serializable to ensure that they can be persisted into a database or send via the message server if clustered sessions are enabled by the system administrator.
  • Maximize use of session affinity and avoid breaking affinity. Session affinity is enabled by default in WebSphere Application Server. It ensures that, except for hardware or software fail-over, requests are handled by the container which initialized that session. Session clustering may be used in addition to affinity to handle fail-over.
  • Release HttpSessions when done, call HttpSession.invalidate(). Otherwise the session objects remain in memory until the session timeout expires.
  • It does not make sense to protect access to session state only part of the time.
  • Distributed HttpSession support does not guarantee transactional integrity of an attribute in a failover scenario or when session affinity is broken.

Tuesday, May 22, 2007

Syntactic and Semantic

Validation comes in two types:
  • Syntactic -- this involves checking for the format of a field, e.g. number of characters, alpha or numeric, membership in a list, and so forth. This needs to be repeated on the server because of the issues with JavaScript being turned off, loss of synchronization between the two languages in a project.
  • Semantic -- this requires domain (business) logic to perform, e.g. comparing postal code with city, and so forth.

Monday, April 30, 2007

Combine Intercepting Filter and Template Method

You can use a base filter which serves as a common superclass for all filters. Common features can be encapsulated in the base filter and shared among all filters. For example, a base filter is a good place to include default behavior for the container callback methods.

At the mean time, template method can be also integrated into the base filter. As shown in this diagram.

Intercepting Filter Pattern

This pattern creates pluggable filters to process common services in a standard manner without requiring changes to core request processing code. The filters intercept incoming requests and outgoing responses, allowing preprocessing and post-processing. We are able to add and remove these filters unobtrusively, without requiring changes to our existing code.

We are able, in effect, to decorate our main processing with a variety of common services, such as security, logging, debugging, and so forth. These filters are components that are independent of the main application code, and they may be added or removed declaratively. For example, a deployment configuration file may be modified to set up a chain of filters. The same configuration file might include a mapping of specific URLs to this filter chain. When a client requests a resource that matches this configured URL mapping, the filters in the chain are each processed in order before the requested target resource is invoked.

Possible types of filters include:

  • Authentication filters
  • Logging and auditing filters
  • Image conversion filters
  • Data compression filters
  • Encryption filters
  • Tokenizing filters
  • Filters that trigger resource-access events
  • XSL/T filters that transform XML content
  • MIME-type chain filters
  • Filters that cache URLs and other information

Note: As for J2EE, filters are a new feature of the version 2.3 Java Servlet specification.

Tuesday, April 03, 2007

1998/99: A year after taking talented high school star Tracy McGrady in the draft the Raptors select his cousin Vince Carter who was a star at UNC. However, Toronto fans would have to wait to see the talented cousins in action as a 4-month lockout delayed the start of the season. When the season started the Raptors new arena was almost ready, as they beat the Vancouver Grizzlies 102-87 in their first game at the Air Canada Centre on February 21st. After years of playing in the spacious SkyDome the Raptors finally had an arena built for basketball and they clearly benefited as they finally escaped last place by posting a record of 23-27. Leading the promising Raptors was Vince Carter who became the 2nd Raptor in 4 years to win Rookie of the Year with 18.3 ppg. At season's end Carter took the microphone and addressed the ACC crowd after the final game and guaranteed a trip to the post-season next year.

1999/00: With the off-season acquisition of Antonio Davis for a high draft pick, the Raptors not only got older, they got a whole lot better. As Davis along with Charles Oakley who was acquired a year earlier provided veteran stability to a young talented team. The veteran presence helped make Vince Carter into an All-Star as he received the second most amount of all star votes ever while stealing the show in the Slam Dunk Contest which he won easily. Carter would go on to average a team high 25.7 ppg while his cousin Tracy McGrady finished second with 15.4 ppg, as the Raptors fulfilled Vince Carter's guarantee with a 45-37 record. However, in the playoffs the inexperienced Raptors would be schooled by the playoff tested New York Knicks losing in 3 straight games. Following the season, the Raptors would be jilted by Tracy McGrady, who decided to seek his own fame, out of his cousin's shadow by signing with the Orlando Magic.

2000/01: After their first playoff appearance the Raptors decided to go after a Hall of Fame coach, to lead the team to the next step as the hired al-time winingest Coach Lenny Wilkins. Vince Carter continued to establish himself as the next big star in the NBA by leading the Raptors with an impressive 27.6 pp, after exhibiting show-stopping dunks in the Olympics with Team USA. With the continued improvement of Vince Carter the Raptors would finish in 2nd place with a solid record of 47-35. In the playoffs the Raptors were matched up against the New York Knicks for the second year in a row. After splitting the first 2 games in New York the Raptors appeared to be heading for a disappointing exit again after they lost Game 3 at the ACC 97-89. However, the Raptors would send the series back to New York by winning Game 4 100-93. In the decisive 5th game in New York the Raptors would stun the Knicks 93-89 to advance to the 2nd round. In the 2nd round the Raptors were matched up against the top seed Philadelphia 76ers. However the Raptors would give the 7ers all they could handle as the battled tooth and nailed all the way to a 7th game where Vince Carter missed a buzzer beater with the Raptors down 88-87, which would have sent the Raptors on the Eastern Conference Finals.

2001/02: After experience success in the playoffs the Raptors were able to sign Vince Carter to a long-term multimillion-dollar deal to ensure their marquee stars for years to come. In addition the Raptors would add even more star power by acquiring future Hall of Famer Hakeem Olajuwon from the Houston Rockets. The Raptors appeared to be heading for another strong season as they held a record of 29-21 entering the all-star break. However, in the final game before the break Vince Carter suffered a knee injury that would hamper their star for the rest of the season. In the second half the Raptors lost 18 of 19 games including, 13 straight games following the break. With all hopes of the playoff seemingly lost Vince Carter decided to undergo knee surgery. However, the Raptors would suddenly turn thing around as they won 8 straight without Vince Carter to get back into the playoff picture. The Raptors would do on to slip into the playoff as the 7th seed with a record of 42-40. In the playoffs the Raptors would get off to a shaky start as they dropped the first 2 games on the road to the Detroit Pistons. However, coming home the Raptors would rebound nicely winning 2 games at ACC to force a decisive 5th game. In Game 5 at Detroit the Raptors gave the Pistons all they could handle before losing 85-82.

2002/03: Things looked bleak for the Raptors early in the season as Hakeem Olajuwon announced his retirement following a disappointing first season in Toronto. In addition Vince Carter continued to feel the lingering effect of his knee injury as he missed most of the first half. However, some former teammates and NBA observes began to question Carter's heart and desire and he didn't seem to be a hurry to get back in the lineup. This view was even given further ammo when Carter was dancing on stage with Nelly as the Raptors, were getting blown out by the Hawks in Atlanta. The Raptors would have all hopes for the playoff buried in January as they held a record of 8-28, which included a 12-game losing streak. Vince Carter would return and play most of the second half, averaging 20.6 ppg, but the Raptors struggles continues as Coach Lenny Wilkins who already held the record for most career wins set the record for most career losses as a coach, while the Raptors finished in 7th place with a disappointing record of 24-58. Following the final game GM Glenn Grunwald apologized to the fans at ACC announcing changes would be made. He would get started right away by firing Coach Lenny Wilkins.

2003/04: With new Coach Kevin O'Neill the Raptors started the season on a high note beating the 2-time Eastern Conference Champion New Jersey Nets 90-87. However a few days later they would set an embarrassing post shot clock record by scoring just 56 points in a loss to the Minnesota Timberwolves. That kind of inconsistency would become the hallmark of the Raptors all season, at times they looked like genuine playoff contenders, while others they looked like a last place team. At 8-8 the Raptors pulled off a blockbuster deal with the Chicago Bulls on December 1st acquiring Jalen Rose, Donyell Marshall, and Lonny Baxter in exchange for Antonio Davis, Jerome Williams, and Chris Jefferies. The Raptors would win their first 3 games after the deal but won just 1 of 7 following the initially strong start as the Raptors continued through out the entire first half as they sat at 25-25 at the All Star Break. However after the all star break injuries would become a problem as the Raptors won just 8 games the rest of the way finishing with a 33-49 record. Following the season the Raptors would fire Coach O'Neill choosing to go with Sam Mitchell.

2004/05: The Sam Mitchell era got off to a good start as the Raptors won 4 of their first 5 games. However the joy was short lived as the Raptors came back to earth fast, as a disgruntled Vince Carter continued to sulk, which hit rock bottom in a November 12th loss in Seattle as he told the Supersonics what play the team was going to run in the waning moments of an 88-87 loss. Through December the Raptors struggled badly winning just 3 of 15 games, as they finally gave up on Vince Carter as he was traded to the New Jersey Nets for Eric Williams, Aaron Williams, Alonzo Mourning, and two first-round draft picks. Mourning a future Hall of Famer refused to play for the Raptors and forced a buyout as he returned to the Miami Heat where he had his best years. Meanwhile the Raptors would go to finish tied for last place in the Atlantic Division with a 33-49 record, while Chris Bosh started to emerge as the new star of the Toronto with a solid 16.8 ppg and 8.9 rpg in just his second year.

2005/06: Under new Coach Sam Mitchell not much was expected from the Raptors who were clearly in a rebuilding mindset as they were still feeling the effects of the Vince Carter deal, in which they got nothing substantial in return, while many questioned their decision to draft Charlie Villanueva. When the season start the Raptors were struggling to match even their low expectations as they lost 15 of their first 16 games. In December the Raptors would show some improvement as they split 14 games as Chris Bosh put together an All-Star season leading the Raptors with 22.5 ppg. The Raptors would continue to play .500 ball in an up and down January that saw them set a franchise record for points in a game while a week later they were torched by Kobe Bryant for 81 points. January would also see changes in Management as GM Mike Babcock was fired and eventually replaced by Bryan Colangelo. The Raptors would close the season much as they begun losing 12 of their last 13, with Chris Bosh injured as they finished in 4th Place with a 27-55 record. The Raptors poor record would have one beneficial side effect as they won the top pick in the draft lottery which they used on Italian prodigy Andrea Bargnani, making him the first European drafted number one overall. While they would trade Charlie Villanueva, who would prove critics wrong by finishing second in Rookie of the Year Voting to the Milwaukee Bucks for play making Point Guard T.J. Ford.

猛龙队史 - 97/98

满满两年的阳光,挡不住那一夕的阴雨。

坎比等等五员大将相继倒下,被伤病浸透的猛龙无奈迎来十七连败。以色亚辞职,达蒙声言必不留营。

猛龙无奈,只好交换达蒙,虽然也换来了昌西-比卢普斯,但当时的昌西尚是菜鸟,远非今日的BIG SHOOT。

猛龙一蹶不振,16-66,全联盟垫底。

猛龙队史 - 96/97

猛龙步入第二年,以色亚-托马斯慧眼识英豪,继上一季选中最佳新秀达蒙-司徒麦尔之后,再度选中马库斯-坎比。达蒙该季的得分已经上升到了20.2分,而坎比也以场均14.7分和6.3个篮板入选了新秀挑战赛。

依然是小鬼当家,猛龙虽然战胜了诸如公牛、爵士和火箭这样的决赛圈队伍,却也输给波士顿三场。公牛是当年的总冠军,爵士和火箭则是西区的冠亚军,而波士顿一季不过才胜了15场。

第二年,30-52猛龙依然中区殿底。

猛龙队史 - 95/96

1946年11月1日,NBA的前身BAA开始了联盟的第一场球赛。

为了纪念那位加拿大人--篮球之父奈施密斯教授,第一场比赛被特意安排在多伦多开球。可惜天公不做美,多伦多HUSKIES队以66比68败给了来访的纽约尼克斯队。此后,BAA脱胎成了NBA,尼克斯也成了NBA的基石,而HUSKIES却以15-45的惨淡战绩仅生存了一个赛季便黯然收场。

光阴似箭,时光荏苒,这一去就是五十年。

九五年,正是朱罗纪公园大红大紫的那一年,顺着这股狂热,
猛龙从天而降。11月3日,也是多伦多的主场,猛龙迎战蓝网,94比78猛龙破网而出。

好彩头却依然是烂成绩,赛季结束的时候,猛龙仅仅胜了21场而排在中区最末。

虽然如此,那一季的猛龙却也是可歌可泣。一是3月24日,猛龙主场以109-108击败公牛,而那正是公牛以72-10的战绩横扫联盟的那个赛季。二是达蒙-司徒麦尔以
场均19.0分和9.3助攻当选年度最佳新秀。

Monday, March 05, 2007

ThreadLocal – A Wrapper Class for Thread Safe

In his article “Thread-safe webapps using Spring”, Steven Devijver talked about the idea behind the thread-safe template classes through which Spring achieves the Data Access Abstraction.

Basically the template thread-safe is fulfilled by using a wrapper class "ThreadLocal". The following code provides a simple example that shows how the ThreadLocal class work.

private static ThreadLocal pi = new ThreadLocal();

public Double pi() {
if (pi.get() == null) {
pi.set(new Double(22 / 7));
}
return (Double)pi.get();
}

ThreadLocal class wraps any object and binds it to the current thread thus making objects local to the thread. When a thread executes the pi() method for the first time there will be no object bound to the thread by ThreadLocal instance pi so the get() method will return null.The set() method will bind an object to the thread that is not shared by other threads. If the method pi() is called often per thread this approach may still offer a considerable performance gain while guaranteeing thread-safety.

Thursday, February 22, 2007

Is RMI Thread Safe?

When the thread safety question extends to the remote calls, e.g. RMI, it becomes even more interesting.

According to the specification defined with Java 1.4.2, RMI section 3.2,
A method dispatched by the RMI runtime to a remote object implementation may or may not execute in a separate thread. The RMI runtime makes no guarantees with respect to mapping remote object invocations to threads. Since remote method invocation on the same remote object may execute concurrently, a remote object implementation needs to make sure its implementation is thread-safe.
No matter how confusing this specification is, it at least tells us two things,
  1. RMI does not take care of the thread safety, it leaves the thread safety as it is.
  2. RMI does not give you one server thread for one client thread, actually, it guarantees nothing on the thread scheduling.
It sounds a little bit discouraging, but it is good enough already since it does not break the thread safety either.

As long as both the client objects and the server objects are thread-safe, the application is thread-safe.

Wednesday, February 21, 2007

Please! Don't Thread Safe Everything!

Thread safe is good, but please, don't do it everywhere. Do it only when instances will be used concurrently by multiple threads. We have three reasons to say that.
  • Unnecessary synchronized method invocations (and synchronized blocks) can cause unnecessary blocking and unblocking of threads, which can hurt performance.

  • Immutable objects tend to be instantiated more often, leading to greater numbers of often short-lived objects that can increase the work of the garbage collector.

  • Synchronization gives rise to the possibility of deadlock, a severe performance problem in which your program appears to hang.
None of these performance setbacks are good excuses for neglecting to make classes that need to thread-safe so, but they do constitute good reasons not to make classes thread-safe unnecessarily.

Way to Thread Safety - Wrapper

Wrapper is to embed an object in a thread-safe wrapper object. In this approach you leave the original class (which isn't thread-safe) unchanged and create a separate class that is thread-safe. Instances of the new class serve as thread-safe "front ends" to instances of the original class.

This approach makes the most sense when you want to give clients a choice between a version of a class that is thread-safe and one that isn't. It also makes sense when you're a client of someone else's class that isn't thread-safe, but you need to use the class in a multithreaded environment. Once you define your own thread-safe wrapper for the class, you can safely use the class in a multithreaded environment by going through your wrapper.

A good example of this approach from the Java API comes from the 1.2 collections library. The 1.2 collections library defines a hierarchy that includes classes that represent many kinds of collections -- none of which are thread-safe. But class Collection includes several class methods that will enclose a regular collection object in a thread-safe wrapper, so you can safely use the object in a multithreaded context. This design gives users of the collections library a choice of using a collections object that is thread-safe and one that isn't.

Note that a common attribute of wrapper classes like those you would use to add thread safety to the enclosed object is that the wrapper accepts the same messages as the enclosed object. In other words, often a wrapper class will descend from a common superclass or superinterface with the enclosed class. (For those of you familiar with the Design Patterns book by Gamma, et. al., this is the "decorator" pattern.) This decorator design approach to wrappers, which is exhibited by the thread-safe wrappers of the 1.2 collections library, allows the thread safety to be dynamically added or removed from an object.

Way to Thread Safety - Immutable

An immutable object is one whose state can't be changed once the object is created. Immutable objects are, by their very nature, thread-safe simply because threads have to be able to write to an object's instance variables to experience a read/write or write/write conflict. Because no methods (only the constructor) of an immutable object actually write to the object's instance variables, the object is by definition thread-safe.

In this approach to making an object thread-safe, you don't mark critical sections as synchronized. Instead, you separate out the critical sections that read instance variables from those that write to instance variables. The critical sections that read are left as-is. The critical sections that write must be changed so that, instead of altering the current object's instance variables, they create a new object that embodies the new state and returns a reference to that object.

It works well when objects are small and represent values of a simple abstract data type. The Java API includes several examples of immutable objects, including String and the primitive type wrappers such as Integer, Long, Float, Boolean, Character, and so on.

It also lets you pass references to them to methods without worrying that the method will change the object's state. In addition, if the overhead of immutability (excessive creation of short-lived objects) may at times be too inefficient, you can also define a mutable companion class that can be used when the immutable version isn't appropriate. An example of this design approach in the Java API is the StringBuffer class, which serves as a mutable companion to the immutable String class. Note that the StringBuffer class is also thread-safe, but it uses the "normal" approach: its instance variables are private and its critical sections are synchronized.

Way to Thread Safety - Synchronization

The most straightforward way to correct the unruly behavior exhibited by non thread safe objects when placed in a multithreaded context is to synchronize the object's critical sections.

An object's critical sections are those methods or blocks of code within methods that must be executed by only one thread at a time. Put another way, a critical section is a method or block of code that must be executed atomically, as a single, indivisible operation. By using Java's synchronized keyword, you can guarantee that only one thread at a time will ever execute the object's critical sections.

This approach takes two steps, to make all relevant fields private, and to identify and synchronize all the critical sections.

Any field that you need to coordinate multithreaded access to must be private, otherwise it may be possible for other classes and objects to ignore your critical sections and access the fields directly. Not every field must be private - only those that will be involved in any temporarily invalid states created by the object's or class's critical sections. For example, constants (static final variables) can't be corrupted by multiple threads, so they needn't be private.

A critical section is a bit of code that must be executed atomically, that is, as a single, indivisible operation.

Note that reads and writes of primitive types and object references are atomic by definition, except for longs and doubles. This means that if you have an int, for example, that is independent of any other fields in an object, you needn't synchronize code that accesses that field. If two threads were to attempt to write two different values to the int concurrently, the resulting value would be one or the other. The int would never end up with a corrupted value made up of some bits written by one thread and other bits written by the other thread.

The same is not necessarily true, however, for longs and doubles. If two different threads were to attempt to write two different values to a long concurrently, you might just end up with a corrupted value consisting of some bits written by one thread and other bits written by the other thread. Multithreaded access to longs and doubles, therefore, should always be synchronized.

For example, a Price class has two instances variables, double priceValue and Date effectiveDate. And the class has a updatePrice method,

public void updatePrice(doubel priceValue, effectiveDate) {
this.priceValue = priceValue;
this.effectiveDate = effectiveDate;
}

The way to make Price thread safe is to make the priceValue and the effectiveDate private first,
then synchronize the updatePrice method.

public synchronized void updatePrice(double priceValue, effectiveDate) {
...
}

or

public void ... {
synchronized (this) {
this.priceValue = priceValue;
this.effectiveDate = effectiveDate;
}
}

Thread Safety - How to Tell

In a multithreaded environment, instances of non thread safe classes are susceptible to two kinds of misbehavior: write/write conflicts and read/write conflicts. From any of these two conflicts, you can tell that the class is not thread safe.

Write/write conflicts

Imagine two threads are trying to write to the same object's instance variables concurrently. If the thread scheduler interleaves these two threads in just the right way, the two threads will inadvertently interfere with each other, yielding a write/write conflict. In the process, the two threads will corrupt the object's state.

Read/write conflicts

This kind of conflict arises when an object's state is read and used while in a temporarily invalid state due to the unfinished work of another thread.

This is like the ACID characteristics of transactions. As long as it takes two or more steps to move an instance from one state to another state, the class is very unlikely thread safe.

Tuesday, February 20, 2007

Thread Safety - Where to Worry About

Given the architecture of the JVM, you need only be concerned with instance and class variables when you worry about thread safety. Because all threads share the same heap, and the heap is where all instance variables are stored, multiple threads can attempt to use the same object's instance variables concurrently. Likewise, because all threads share the same method area, and the method area is where all class variables are stored, multiple threads can attempt to use the same class variables concurrently. When you do choose to make a class thread-safe, your goal is to guarantee the integrity -- in a multithreaded environment -- of instance and class variables declared in that class.

You needn't worry about multithreaded access to local variables, method parameters, and return values, because these variables reside on the Java stack. In the JVM, each thread is awarded its own Java stack. No thread can see or use any local variables, return values, or parameters belonging to another thread.

Five Categories of Thread Safety

In his Effective Java, Joshua Bloch described five categories of thread safety: immutable, thread-safe, conditionally thread-safe, thread-compatible, and thread-hostile.
  • Immutable objects are guaranteed to be thread-safe, and never require additional synchronization. Because an immutable object's externally visible state never changes, as long as it is constructed correctly, it can never be observed to be in an inconsistent state. Most of the basic value classes in the Java class libraries, such as Integer, String, and BigInteger, are immutable.
  • Thread-safe classes are safe not only for single call, but also for multiple calls combined. They will need no additional synchronzation from their callers. This thread-safety guarantee is a strong one -- many classes, like Hashtable or Vector, will fail to meet this stringent definition.
  • Conditionally thread-safe classes are those for which each individual operation may be thread-safe, but certain sequences of operations may require external synchronization. The most common example of conditional thread safety is traversing an iterator returned from Hashtable or Vector -- the fail-fast iterators returned by these classes assume that the underlying collection will not be mutated while the iterator traversal is in progress. To ensure that other threads will not mutate the collection during traversal, the iterating thread should be sure that it has exclusive access to the collection for the entirety of the traversal. Typically, exclusive access is ensured by synchronizing on a lock -- and the class's documentation should specify which lock that is (typically the object's intrinsic monitor).
  • Thread-compatible classes are not thread-safe, but can be used safely in concurrent environments by using synchronization appropriately. This might mean surrounding every method call with a synchronized block or creating a wrapper object where every method is synchronized (like Collections.synchronizedList()). Or it might mean surrounding certain sequences of operations with a synchronized block. To maximize the usefulness of thread-compatible classes, they should not require that callers synchronize on a specific lock, just that the same lock is used in all invocations. Doing so will enable thread-compatible objects held as instance variables in other thread-safe objects to piggyback on the synchronization of the owning object. Many common classes are thread-compatible, such as the collection classes ArrayList and HashMap, java.text.SimpleDateFormat, or the JDBC classes Connection and ResultSet.
  • Thread-hostile classes are those that cannot be rendered safe to use concurrently, regardless of what external synchronization is invoked. Thread hostility is rare, and typically arises when a class modifies static data that can affect the behavior of other classes that may execute in other threads. An example of a thread-hostile class would be one that calls System.setOut().

Monday, February 19, 2007

Generic Five Steps to Create JAX-RPC Web Service

The first stage is to write the interface to declare the remote methods to expose and to write the implementation class for those methods.

For the second stage, you typically run some kind of mapping tool to generate the WSDL description for the web service which maps the interface.

The third step is to run a mapping tool on the WSDL file to create the stub and tie classes which are required to allow remote client access.

The next step is to compile all the generated files and package them into an archive file, typically a WAR (Web Application Archive) file.

Finally, you deploy the web service onto a web server with a built-in SOAP engine.

Decompile .class in Eclipse

Don't you hate the "Source Not Found" while you are debugging in Eclipse?

OK yes, you can do this.
  1. download JAD at http://www.kpdus.com/jad.html and then install it on your workstation.
  2. download JAD Eclipse plugin at http://sourceforge.net/projects/jadclipse/ and then install it with your Eclipse.
  3. restart your Eclipse and click Window->Preferences->Java->JadClipse and finish the configuration.
Congratulations! .class is no longer a black box.

Wednesday, January 03, 2007

Property Editor Not Visible in Weblogic Workshop 8.1

Sometimes the Property Editor will be not visible in Workshop.

Search for the .workshop.pref and .workshop.zpref. Move them to another folder, e.g. the desktop.

Restart Workshop, the Property Editor will be visible. You will also notice that these two files will be recreated.