Friday, November 16, 2012

Usage of JMS Message ID and Correlation ID

These two JMS message headers are used to link messages being exchanged between two applications.

Standard pattern is:
  • App1 sends a message to App2
  • App2 stores the JMSMsgID (say 123) and completes the processing
  • App2 generates response for App1 and sets above JMSMsgID (123) as JMSCorrelID
  • App1 receives the response, using the JMSCorrelID it matches with the original request
Setting/getting correlation ID is straight forward.  Tricky one is MsgID.

From Java EE doc:

void setJMSMessageID(String id) throws JMSException

Sets the message ID.

JMS providers set this field when a message is sent. This method can be used to change the value for a message that has been received
.

I am not sure what purpose it solves to change message ID after a message is received.  Key point to note is that JMS provider shall set/override this value when the message is published.  Which means even if you try to override by calling this method, the value will be lost!!

On Websphere default messaging, we can set message ID to any value, but on JBoss messaging it mandates that you prefix the value with ID: as per spec :-)  Anyways the value gets lost.  So how to use this property??

As highlighted above message ID is set after the message is sent/published.  We can get the same using getJMSMessageID method on Message.  We need to store this to link with the response we receive later.

So far good.  Then later I got to know from our client that he is sending his own message ID, back to square one thinking how is this possible?  Silly me...this restriction is imposed by JMS API !! so my client must be doing this using different API.  For IBM MQ, we have a Java API, which is seperate from JMS API.  It also offers API for C as well.  When you use this API, this restriction does not apply.  We can set the message ID value to whatever we want.  The doc of this API confirms this, below is the extract:

Tuesday, October 30, 2012

Run jar file in a secure way

Often we download java tools/applications that are either from known sources or to try out their features.  Mostly they would come with either a bat/sh file to setup the path for the application and launch the jar.  Say you are logged in with an elevated user and what if the application you want to try just wipes out C drive!!

Always run the jar files (tweak the shell/batch scripts if required) to enable java security manager.  All that we need to do is launch jvm as java -Djava.security.manager -jar <jarFile>

This will use the default policy file that comes with JDK at JAVA_HOME/lib/security/java.policy, which is good enough.

Monday, October 29, 2012

Oracle jdbc driver changed since 9i

Came across this while going through the tomcat docs.  Since Oracle 9i release the jdbc driver class oracle.jdbc.driver.OracleDriver is deprecated and oracle.jdbc.OracleDriver is the new one to be used.  We use 10g and have been using the old driver since last 3 years.  Not sure if this will make any difference interms of performance though.  Will update once we have some stats.

Friday, October 26, 2012

Intro to OSGi

Came across the nice book by Neil Bartlett on OSGi while reading news on Jigsaw getting delayed and plans to include it in Java 9.

His book is so nice and I finished reading the intro, below are quick facts we should look to design for OSGi

Version Dependency
METAINF.MF could be used to declare the dependencies, but can not enforce version.

1. For example, suppose we determine somehow that a JAR has a dependency on Log4J. Which version of Log4J do we need to supply to make the JAR work?

2. Versions cause other problems. Suppose our application requires two libraries, A and B, and both of these libraries depend in turn upon a third library, C.  But they require different versions: library A requires version 1.2 or greater of C, but library B requires version 1.1 of C, and will not work with version 1.2!

Lack of Information Hiding Across JARs
Classes within a JAR need to have access to the classes in other packages of the same JAR. That means we must make those classes public, because that is the only access modifier which makes classes visible across package boundaries.  As a consequence, all those classes declared public are accessible to clients outside the JAR as well.  Therefore the whole JAR is effectively public API, even the parts that we would prefer to keep hidden.

I hope to continue and complete this book.

Tuesday, May 22, 2012

Moving to IntelliJ and back

Post the release of IntelliJ ver 11, I have heard lot of good things and thought of giving it a try.  I saw it is open-source and free, but realised only the community edition is free and which is way limited in its capabilities compared to the paid version.  Somewhere I read that IntelliJ is a smart Java IDE where as eclipse is a general purpose IDE, Java being one of the languages it supports or rather famous for.  The download is an exe rather than a zip.  As I do not have admin rights on my lap, I usually prefer zip versions.  But I was happy as the exe is itself can be unzipped (7-zip).

You will find the exe to run in "ideaIC-11.1.2\bin" folder, and unlike eclipse it did not ask me to choose a folder to keep the profile/settings, uses APPDATA on XP to create a folder in your user profile.  As this adds to my profile size, I always move it to my D drive if possible.  There is a file in "ideaIC-11.1.2\bin\idea.properties", where you can change the locations and tell IntelliJ to store your preferences and plugin data.  I found in the forum which says zip version is provided only for ultimate edition, not sure why !!

Once it is up and running I really did struggle to move around and code as there is no shortcut to un learn eclipse shortcuts and get to used to IntelliJ quickly.  Download and keep the shortcuts reference aside, it will help a lot in making the ide usage a pleasant one.  As I keep using I can feel the intelligence, while doing auto-fill or auto-suggestions.  But I miss the eclipse feature to insert comma or semicolon automatically at the end, need to press Ctrl+Enter to do the same.  Another good thing is its seamless support for maven, autofilling the dependency info in your pom is really good, but couldn't figure out how to run any specific goal instead of build/run available in the menu.  As an exercise I started to learn Stripes and though using maven tomcat/jetty plugins I could deploy and test my web application slowly I felt the need to have support for the server from within IDE, I actually wanted to do remote debugging.  Also felt that it eats away my battery very quickly, not sure how fast, but you can feel it.

After playing around for some more time, I went back to netbeans/eclipse.  I keep switching between them.  So finally my experience is - the IntelliJ community edition is not worth dumping eclipse/netbeans.  But if you can get to the entriprise version, I do think it will be more fun as they promise.

Thursday, December 8, 2011

Eclipse workspace

I use eclipse for all development activities and started with multiple copies of eclipse for each topic.  Say I am learning JUNIT, will have eclipse installation in one folder.  Similarly I used to have a different installation for learning generics/annotations, android, webservices etc.

Over time I realized that in most cases I am using same version of eclipse and this setup is taking up lot of space (this is not really a big issue).  As I started experimenting with maven and other code quality/metric tools, I needed to do the installation of these plugins in every installation of eclipse.

Another possible option is to have single eclipse installation with different workspaces for each specific task.  This addresses the space issue, but I still need to install the plugins in different workspaces again and again.  Having unrelated plugins takes up lot of memory and slows down the eclipse itself.

How about having workspaces for different plugins (grouped logically) and use whichever plugin set is required for your task?  Not sure, but I do not have any better options at this point.  While I play around on how to manage my workspace below trick would help in identifying which workspace is currently being used:

Add -showlocation as the first line in eclipse.ini, which would show the workspace name in the title bar.

Tuesday, July 5, 2011

BigDecimal to String conversion

We have just realised one more non obvious issue with toString() method of BigDecimal while migrating from jdk1.4 to 1.6

Since Java 5, the toString method started printing the value in scientific form if scale is more than 6, so our messages going out have become wrong; no coding issues, its like silent killer :-)  Good lesson for me is to override this method whenever the output make a difference even though the default is enough.  The new method added is toPlainString() to get what toString() is doing earlier.

Thursday, April 14, 2011

What is JIT

The Just-In-Time (JIT) compiler is a part of JVM to improve application performance.

As we all know the class files generated with javac contain platform-independent bytecodes to be interpreted by a JVM on specific OS/machine.  Due to this interpretation performance will be slow than that of a native application.  The JIT compiler compiles bytecodes into native machine code at run time and helps in improving the performance.  Below are some points to be noted:
  • It is enabled by default, and is activated when a Java method is called.
  • It compiles the bytecodes of that method into native machine code, compiling it "just in time" to run.
  • After a method is compiled, JVM calls the compiled code directly instead of interpreting it.
  • Methods are not compiled the first time they are called.  For each method, JVM maintains a call counter.  JVM interprets a method until its call count exceeds a JIT compilation threshold.
  • After a method is compiled, its call count is reset to zero and subsequent calls to the method will continue to increment its count.  When the call count of a method reaches the JIT recompilation threshold, the JIT compiler compiles it a second time, applying further optimizations than on the previous compilation.  This process is repeated until the maximum optimization level is reached.
  • The JIT compiler can be disabled (-Xint interpret-only mode), in which case the entire Java program will be interpreted.


Monday, December 7, 2009

Starting java without command prompt

I have a jar file (self-executable, with Main-class attribute set) and to run it I just need to double click it as jar files are associated with javaw on my machine.  However, I needed to pass some arguments to this jar.  So I put this one line into a cmd file and tried to run:

javaw -jar myJar.jar -Duser.home=C:\myTest\myHome

When I run this even though my GUI (jar is a swing app) comes up, command window doesn't go away.  One has to put "start" also before for the command window to go away.  So the above line should read as below:

start javaw -jar myJar.jar -Duser.home=C:\myTest\myHome

By the way, we can have all the profile files to be created at mentioned folder instead of default user.home by overriding the system variable as above.

Wednesday, October 22, 2008

JBOSS resources

  1. DebugtomcatjbossEclipse
  2. Tomcat
  3. AccessControlForJMXConsole
  4. EncryptingDataSourcePasswords
  5. ConfigDataSources
  6. SetUpMysqlAsDefaultDS
  7. JBossAdminGuide
  8. BaseCertLoginModule
  9. LoginConfiguration
  10. SecureTheJmxConsole
  11. JAASSetup
  12. CreateASimpleSecurityDomainForJBossSX
  13. WARConfiguration
  14. SecureAWebApplicationUsingACustomForm
  15. SecureAWebApplicationInJBoss
  16. SecureJBoss
  17. Security
  18. RMIClassLoadingService
  19. Technical White Paper - JBoss Security
  20. JBossClassLoadingUseCases
  21. ThreadDump
  22. VersionOfTomcatInJBossAS
  23. WebsphereMQIntegration
  24. UsingWebSphereMQSeriesWithJBossASPartI
  25. UsingWebSphereMQSeriesWithJBossASPart2
  26. UsingWebSphereMQSeriesWithJBossASPart3
  27. UsingWebSphereMQSeriesWithJBossASPart4
  28. JBossMessaging
  29. JBossNS
  30. JBossWS
  31. IntegratingActiveMQWithJBoss
  32. Enhancements in Packages java.lang.* and java.util.*
  33. VirtualHosts
  34. SingleSignOn
  35. Scripting
  36. StartStopJBoss
  37. ServiceBindingManager
  38. Logging
  39. JBossMonitoring
  40. JBossWSoverHTTPS
  41. TomcatClustering
  42. SSLSetup
  43. StartingWithSeamAGuideForBeginners
  44. Twiddle
  45. UDDIExample
  46. HowDoIGetAnMDBSingleton
  47. MessageTransformation
  48. ThreadDumpJSP
  49. WARConfiguration
  50. JBossSX
  51. LdapLoginModule
  52. MainDeployer
  53. LoggingRMICalls
  54. How to configure a Quartz service
  55. JBossProfiler
  56. ClassLeakage
  57. Receiving IllegalStateExceptions in client
  58. ThreadSafeCode
  59. JBossJTA
  60. JBossJTAOverview
  61. DaylightSavingsTimeIssues
  62. JBossRunParameters
  63. JBossConfiguration
  64. Log4jRepositorySelector
  65. JBossDTDs
  66. EnableClassloaderLogging
  67. LimitAccessToCertainClients
  68. MonitoringTomcatEmbeddedInJboss
  69. GenerateAThreadDumpWithTheJMXConsole
  70. StartupAndDeploymentCheck
  71. CustomizingSecurityUsingValves
  72. HttpSessionReplication
  73. PermanentGeneration
  74. JBossMQLogging
  75. JBossConfigurationFiles
  76. ServerConfiguration
  77. DeterminingClassVersionFromADotClassFile
  78. TimerService
  79. RemoveEJBTimer
  80. HowDoICreateAResourceRef
  81. RetryingTransactions
  82. AnIntroductionToJMX
  83. ConfigMessagingJDBC2Persistence
  84. DynamicLoginConfig
Finally the JBOSS wiki and main page.

WAS resources

Transactions in J2EE
Transactions in J2EE

WebSphere Web Services Information Roadmap
General information
Concepts, technology, and specifications
Developing Web services
Working with the Web Services Gateway
Web services security
Building solutions using Web services

Using Web Services for Business Integration
Chapter 1. Web services technology and standards
Chapter 2. Sample application
Chapter 3. WebSphere InterChange Server as a Web services router
Chapter 4. WebSphere BI Message Broker as a Web services router
Chapter 5. WebSphere Enterprise as a Web services router
Chapter 6. Process Choreographer as a Web services router
Appendix A. Hardware and software configuration
Appendix B. Additional material

Programming J2EE APIs with WebSphere Advanced
Part 1. Introduction
Chapter 1. Our development conditions
Chapter 2. J2EE overview
Chapter 3. Products used within this book
Chapter 4. Introducing PiggyBank
Part 2. The EJB container
Chapter 5. Working with Enterprise JavaBeans
Chapter 6. Transactions and EJBs
Chapter 7. Messaging with JMS, WebSphere and MQSeries
Part 3. The Web container
Chapter 8. Servlets
Chapter 9. JavaServer Pages
Chapter 10. JSPs extended: custom tags
Part 4. Additional discussions
Chapter 11. Application clients and J2EE communications
Chapter 12. Deploying J2EE applications to WebSphere
Appendix A. Additional material

Patterns: Service-Oriented Architecture and Web Services
Chapter 1. Patterns for e-business
Chapter 2. Service-oriented architecture
Chapter 3. Service-oriented architecture and Patterns for e-business
Chapter 4. Service-oriented architecture approach
Chapter 5. Technology options
Chapter 6. HTTP service bus
Chapter 7. JMS service bus
Chapter 8. Service directory
Chapter 9. Web service gateway
Chapter 10. e-business on demand and Service-oriented architecture
Appendix A. Scenarios lab environment
Appendix B. Additional material

Self-Study Guide: WebSphere Studio Application Developer and Web Services
Part 1. Presentations
Unit 1. Workshop Introduction
Unit 2. Application Developer: Overview
Unit 3. Application Developer: Java Development
Unit 4. Application Developer: Relational Schema Center
Unit 5. Application Developer: XML Development
Unit 6. Application Developer: Web Development
Unit 7. Application Developer: EJB Development
Unit 8. Application Developer: Deployment to WebSphere
Unit 9. Application Developer: Profiling Tools
Unit 10. Application Developer: Team Development
Unit 11. Web Services Overview
Unit 12. Creating Web Services
Unit 13. Using Web Services
Unit 14. Web Services and the UDDI Explorer

Part 2. Exercises
Exercise 1. Java development
Exercise 2. Relational Schema Center
Exercise 3. XML development
Exercise 4. Web development
Exercise 5. EJB development
Exercise 6. Test and deploy using WebSphere AEs
Exercise 7. Profiling an application
Exercise 8. Create a Web Service
Exercise 9. Deploy and test a Web Service
Exercise 10. Using a Web service in a client application
Exercise 11. Web Service publishing in the UDDI registry

Part 3. Appendixes
Appendix A. Installation and configuration
Appendix B. Additional material

Patterns: SOA with an Enterprise Service Bus in WebSphere Application Server V6
Part 1. Patterns for e-business and SOA
Chapter 1. Introduction to Patterns for e-business
Chapter 2. SOA and the Enterprise Service Bus
Chapter 3. Application Integration and Extended Enterprise patterns
Chapter 4. Product descriptions and ESB capabilities
Chapter 5. SOA runtime patterns and Product mappings
Part 2. Business scenario and guidelines
Chapter 6. The business scenario that this book uses
Chapter 7. Technology options
Part 3. Scenario implementation
Chapter 8. SOA Direct Connection pattern
Chapter 9. Enterprise Service Bus pattern: router scenario
Chapter 10. Enterprise Service Bus pattern: broker scenario
Chapter 11. Exposed ESB Gateway pattern
Part 4. Appendixes
Appendix A. Additional material
Appendix B. Configuring the scenario environment

Connecting Enterprise Applications to WebSphere Enterprise Service Bus
Part 1. Background
Chapter 1. Connecting enterprise applications
Chapter 2. Service Component Architecture
Chapter 3. Connecting to the WebSphere Enterprise Service Bus
Chapter 4. Adapters
Part 2. Scenarios and patterns
Chapter 5. Business scenarios
Chapter 6. Connection patterns
Part 3. Working examples
Chapter 7. Historical integration using WebSphere MQ
Chapter 8. Custom CICS integration using WebSphere MQ
Chapter 9. Code-free CICS integration using WebSphere MQ
Chapter 10. Custom application integration using JMS
Chapter 11. Event-driven integration using a JDBC adapter
Chapter 12. Lightweight Web client integration using http
Chapter 13. Lightweight Web service integration using http
Chapter 14. Summary
Appendix A. Additional material
Appendix B. Source listings

Patterns: Implementing an SOA using an Enterprise Service Bus
Part 1. Patterns for e-business and SOA
Chapter 1. Introduction to Patterns for e-business
Chapter 2. e-business on demand and service-oriented architecture
Chapter 3. Web services and service-oriented architecture
Part 2. Enterprise Service Bus
Chapter 4. Enterprise Service Bus and SOA patterns
Chapter 5. ESB and SOA component implementations
Chapter 6. Endpoint enablement roadmap
Part 3. Scenario implementation
Chapter 7. The business scenario used in this book
Chapter 8. Enterprise Service Bus: Router variation
Chapter 9. Enterprise Service Bus: Broker variation
Chapter 10. Business Service Choreography
Chapter 11. Exposed ESB Gateway composite pattern
Appendix A. Additional material
Appendix B. Configuring the scenario lab environment

Patterns: SOA Design Using WebSphere Message Broker and WebSphere ESB
Chapter 1. Introduction
Part 1. Concepts, patterns, and products
Chapter 2. Introduction to SOA and ESB
Chapter 3. Product descriptions
Part 2. Product capabilities in relation to SOA and ESB
Chapter 4. ESB runtime patterns and product mappings
Chapter 5. WebSphere Enterprise Service Bus
Chapter 6. WebSphere Message Broker in SOA
Chapter 7. WebSphere DataPower appliances in SOA
Chapter 8. ESB design options
Part 3. Physical scenarios
Chapter 9. Scenario: using WebSphere ESB and WebSphere Message Broker in combination
Chapter 10. Scenario: DataPower in an SOA
Appendix A. Java node source code
Appendix B. Sample instructions
Appendix C. Additional material

WebSphere Version 6 Web Services Handbook Development and Deployment
Part 1. Web services concepts
Chapter 1. Web services introduction
Chapter 2. Web services standards
Chapter 3. Introduction to SOAP
Chapter 4. Introduction to WSDL
Chapter 5. JAX-RPC (JSR 101)
Chapter 6. Web Services for J2EE
Chapter 7. Introduction to UDDI
Chapter 8. Web Services Inspection Language
Chapter 9. Web services security
Chapter 10. Web services interoperability
Chapter 11. Web services architectures
Chapter 12. Best practices
Part 2. Implementing and using Web services
Chapter 13. IBM products for Web services
Chapter 14. Sample application: Weather forecast
Chapter 15. Development overview
Chapter 16. Develop Web services with Application Developer V6.0
Chapter 17. Test and monitor Web services
Chapter 18. Deploy and run Web services in WebSphere Application Server V6.0
Chapter 19. Command-line tools, Ant, and multiprotocol binding
Part 3. Advanced Web services techniques
Chapter 20. Web services interoperability tools and examples
Chapter 21. Securing Web services
Chapter 22. Web services and the service integration bus
Chapter 23. Implementing a private UDDI registry
Chapter 24. Web services caching
Appendix A. Installation and setup
Appendix B. WS-Security configuration details: Mapping V5/V6, predefined properties, sample forms
Appendix C. Additional material

Experience J2EE! Using WebSphere Application Server V6.1
Part 1. Preliminary activities
Chapter 1. Introduction
Chapter 2. Install and configure software
Chapter 3. Configure the development environment
Chapter 4. Prepare the legacy application
Part 2. Core J2EE application
Chapter 5. Create the employee data access element
Chapter 6. Create the funds data access element
Chapter 7. Create the donate business logic element
Chapter 8. Create the employee facade business logic element
Chapter 9. Create the Web front end
Chapter 10. Create the application client
Chapter 11. Implement core security
Chapter 12. Alternative Import the core J2EE application
Part 3. Web services
Chapter 13. Create the Web service
Chapter 14. Implement security for the Web service
Part 4. Messaging
Chapter 15. Create the message-driven bean
Chapter 16. Add publication of results
Chapter 17. Implement security for messaging
Chapter 18. What next?
Appendix A. Additional material

Web Services Feature Pack for WebSphere Application Server V6.1
Part 1. Introduction
Chapter 1. What is in the feature pack
Chapter 2. History and roadmap
Part 2. Benefits of the feature pack
Chapter 3. Business scenarios
Chapter 4. Facets and patterns
Chapter 5. Technical advantages
Part 3. Using the feature pack
Chapter 6. Installation
Chapter 7. JAX-WS programming model
Chapter 8. Policy sets
Chapter 9. Secure conversation
Chapter 10. Reliable messaging
Chapter 11. Interoperability
Appendix A. Sample code
Appendix B. Additional material

Web Services Handbook for WebSphere Application Server 6.1
Part 1. Web services concepts
Chapter 1. Web services introduction
Chapter 2. Web services standards
Chapter 3. Introduction to SOAP
Chapter 4. Introduction to WSDL
Chapter 5. JAX-RPC (JSR 101)
Chapter 6. Web Services for J2EE
Chapter 7. Introduction to UDDI
Chapter 8. Web services security
Chapter 9. Web services interoperability
Chapter 10. Web services architectures
Chapter 11. Best practices
Part 2. Implementing and using Web services
Chapter 12. IBM products for Web services
Chapter 13. Sample application: Weather forecast
Chapter 14. Development overview
Chapter 15. Develop Web services with Application Server Toolkit 6.1
Chapter 16. Test and monitor Web services
Chapter 17. Deploy and run Web services in WebSphere Application Server 6.1
Chapter 18. Command-line tools, Ant, and multiprotocol binding
Part 3. Advanced Web services techniques
Chapter 19. WS-Addressing and WS-Resource
Chapter 20. Web services transactions using WS-Coordination, WS-AtomicTransaction and WS-BusinessActivity
Chapter 21. Web services and the service integration bus
Chapter 22. WS-Notification
Chapter 23. Web services interoperability tools and examples
Chapter 24. Implementing a private UDDI registry
Chapter 25. Securing Web services
Chapter 26. Web services caching
Appendix A. Installation and setup
Appendix B. Additional material

WebSphere MQ Version 6 and Web Services
Part 1. Overview
Chapter 1. Introduction
Chapter 2. Objectives
Chapter 3. Technologies
Part 2. Web Services and security considerations
Chapter 4. WebSphere Services with WebSphere MQ
Chapter 5. SOAP/WebSphere MQ implementation
Chapter 6. Security
Part 3. Implementing synchronous Web Services
Chapter 7. Environment setup
Chapter 8. Axis Web Service
Chapter 9. Axis client
Chapter 10. .NET Web Service
Chapter 11. .NET client
Chapter 12. WebSphere Application Server Web Service
Chapter 13. WebSphere Application Server client
Part 4. Asynchrony and transactionality
Chapter 14. Long-term asynchronous functionality (MA0V)
Chapter 15. Implementing long-term asynchronousWeb Service clients
Chapter 16. Transactional functionality (MA0V)
Chapter 17. Implementing transactionality
Part 5. Web Services and WebSphere MQ clustering
Chapter 18. Using WebSphere MQ clustering with Web Services
Appendix A. WebSphere MQ using .NET classes
Appendix B. WebSphere MQ using Java classes
Appendix C. Deployment utility quick reference
Appendix D. Additional material

Connecting Enterprise Applications to WebSphere Enterprise Service Bus
Part 1. Background
Chapter 1. Connecting enterprise applications
Chapter 2. Service Component Architecture
Chapter 3. Connecting to the WebSphere Enterprise Service Bus
Chapter 4. Adapters
Part 2. Scenarios and patterns
Chapter 5. Business scenarios
Chapter 6. Connection patterns
Part 3. Working examples
Chapter 7. Historical integration using WebSphere MQ
Chapter 8. Custom CICS integration using WebSphere MQ
Chapter 9. Code-free CICS integration using WebSphere MQ
Chapter 10. Custom application integration using JMS
Chapter 11. Event-driven integration using a JDBC adapter
Chapter 12. Lightweight Web client integration using http
Chapter 13. Lightweight Web service integration using http
Chapter 14. Summary
Appendix A. Additional material
Appendix B. Source listings

Enabling SOA Using WebSphere Messaging
Chapter 1. Introduction
Chapter 2. Product selection
Chapter 3. Runtime topology selection
Chapter 4. Application design
Chapter 5. Point-to-point runtime configuration
Chapter 6. Integration scenarios with WebSphere ESB
Chapter 7. Integration scenarios with WebSphere Message Broker
Appendix A. Sample files

MQSeries Programming Patterns
Part 1. Introduction
Chapter 1. Introduction and patterns
Chapter 2. Messaging and the APIs
Part 2. The APIs
Chapter 3. Programming with MQI
Chapter 4. Programming with AMI
Chapter 5. Programming with C++
Chapter 6. Programming with ActiveX
Chapter 7. Programming with Java
Chapter 8. Programming with JMS

MQSeries Workflow for Windows NT for Beginners
Chapter 1. Introduction
Chapter 2. Installation and configuration
Chapter 3. Using MQSeries Workflow - a tutorial
Chapter 4. Using MQSeries Workflow - next steps
Chapter 5. Programming using DB2 and Workflow APIs
Appendix A. OrderFulfillment.java
Appendix B. StartOrder.java

MQSeries Security: Example of Using a Channel Security Exit, Encryption and Decryption

WebSphere Application Server V6: Default Messaging Provider Problem Determination

WebSphere Application Server V6.1 Web Services Problem Determination
Introduction
Problems that occur during development
Problems deploying Web services applications
Problems that occur during runtime
Collecting diagnostic data
The next step

WebSphere Application Server V6.1: JMS Problem Determination
Chapter 1. Introduction to JMS problem determination
Chapter 2. Messaging engine problem determination
Chapter 3. Message store problem determination
Chapter 4. Message store with data store persistence
Chapter 5. File store problem determination
Chapter 6. JMS application problem determination
Chapter 7. Messaging in a multiple messaging engine environment
Chapter 8. Clustering problem determination
Chapter 9. Message-driven beans problem determination
Chapter 10. WebSphere MQ and MDBs
Chapter 11. WebSphere MQ Server problem determination
Chapter 12. WebSphere MQ configuration
Chapter 13. WebSphere MQ link problem determination
Chapter 14. JMS application with WebSphere MQ problem determination
Chapter 15. Foreign bus problem determination
Chapter 16. Mediation problem determination
Chapter 17. Default messaging provider security
Chapter 18. The next step

WebSphere Application Server V6.1: Classloader Problem Determination
Introduction to class loaders
Problem determination for class loader exceptions
ClassCastException
ClassNotFoundException
NoClassDefFoundError
NoSuchMethodError and IllegalArgumentException
UnsatisfiedLinkError
VerifyError
Configuring shared libraries
Using custom JAR files for your application
Collecting diagnostic data
The next step

WebSphere Application Server V6.1: Technical Overview
Not available.

WebSphere Application Server V6.1: System Management and Configuration
Part 1. The basics
Chapter 1. WebSphere Application Server
Chapter 2. System management: A technical overview
Chapter 3. Getting started with profiles
Chapter 4. Administration basics
Chapter 5. Administration with scripting
Chapter 6. Configuring WebSphere resources
Chapter 7. Managing Web servers
Part 2. Messaging with WebSphere
Chapter 8. Asynchronous messaging
Chapter 9. Default messaging provider
Part 3. Working with applications
Chapter 10. Session management
Chapter 11. WebSphere naming implementation
Chapter 12. Understanding class loaders
Chapter 13. Packaging applications
Chapter 14. Deploying applications

WebSphere Security Fundamentals
Chapter 1. Security fundamentals
Chapter 2. Supporting security components for WebSphere
Chapter 3. Security fundamentals for J2SE, J2EE, and WebSphere

IBM WebSphere Application Server V6.1 Security Handbook
Part 1. Application server security
Chapter 1. Introduction
Chapter 2. Configuring the user registry
Chapter 3. Administrative security
Chapter 4. SSL administration
Chapter 5. JAAS for authentication in WebSphere Application Server
Chapter 6. Application security
Chapter 7. Securing a Web application
Chapter 8. Securing an EJB application
Chapter 9. Client security
Chapter 10. Securing the service integration bus
Part 2. Extending security beyond the Application Server
Chapter 11. Security attribute propagation
Chapter 12. Securing a WebSphere application using Tivoli Access Manager
Chapter 13. Trust Association Interceptors and third party software integration
Chapter 14. Externalizing authorization with JACC
Chapter 15. Web services security
Chapter 16. Securing access to WebSphere MQ
Chapter 17. J2EE Connector security
Chapter 18. Securing the database connection
Part 3. Development environment
Chapter 19. Development environment security
Appendix A. Additional configurations
Appendix B. Additional material

Security in WebSphere Application Server V6.1 and J2EE 1.4 on z/OS
Chapter 1. Introduction
Chapter 2. WebSphere security design
Chapter 3. Web container security
Chapter 4. Application security
Chapter 5. Web services security introduction
Chapter 6. Web services message layer security
Chapter 7. Secure Sockets Layer (SSL)
Chapter 8. Web services transport security
Chapter 9. Security attribute propagation and CSIv2
Chapter 10. User registries
Chapter 11. SPNEGO and Windows single sign-on
Chapter 12. Operating system security
Chapter 13. WAS administrative security
Appendix A. Additional material

Rational Application Developer V7 Programming Guide
Part 1. Introduction to Rational Application Developer
Chapter 1. Introduction
Chapter 2. Programming technologies
Chapter 3. Workbench setup and preferences
Chapter 4. Perspectives, views, and editors
Chapter 5. Projects
Part 2. Develop applications
Chapter 6. RUP and UML
Chapter 7. Develop Java applications
Chapter 8. Accelerate development using patterns
Chapter 9. Develop Database Applications
Chapter 10. Develop GUI applications
Chapter 11. Develop XML applications
Chapter 12. Develop Web applications using JSPs and servlets
Chapter 13. Develop Web applications using Struts
Chapter 14. Develop Web applications using JSF and SDO
Chapter 15. Develop applications using EGL
Chapter 16. Develop Web applications using EJBs
Chapter 17. Develop J2EE application clients
Chapter 18. Develop Web services applications
Chapter 19. Develop portal applications
Part 3. Test and debug applications
Chapter 20. Servers and server configuration
Chapter 21. Test using JUnit
Chapter 22. Debug local and remote applications
Part 4. Deploy and profile applications
Chapter 23. Build applications with Ant
Chapter 24. Deploy enterprise applications
Chapter 25. Profile applications
Part 5. Team development
Chapter 26. ClearCase integration
Chapter 27. CVS integration
Appendix A. Product installation
Appendix B. Additional material

WebSphere MQ V6 Fundamentals
Chapter 1. Overview
Chapter 2. Concepts of message queuing
Chapter 3. Facilities for message queuing provided by WebSphere MQ
Chapter 4. Designing applications that access a WebSphere MQ infrastructure
Chapter 5. Understanding and configuring queue managers
Chapter 6. Technical introduction to message queuing
Chapter 7. Queue manager intercommunication and client connections in WebSphere MQ
Chapter 8. Queue manager clusters
Chapter 9. Hands-on introduction to messaging with WebSphere MQ
Chapter 10. Hands-on guide to building WebSphere MQ infrastructure
Chapter 11. Securing a WebSphere MQ infrastructure
Chapter 12. Troubleshooting
Appendix A. Functionality new to WebSphere MQ V6.0
Appendix B. Quick reference

Migrating Applications from WebLogic, JBoss and Tomcat to WebSphere V6
Chapter 1. Introduction
Chapter 2. WebSphere overview
Chapter 3. Migration strategy and planning
Chapter 4. Installation and configuration
Chapter 5. Common migration issues
Chapter 6. Migrating from BEA WebLogic
Chapter 7. Migrating from JBoss
Chapter 8. Migrating from Tomcat
Appendix A. Development tips for portable applications
Appendix B. Additional material

Source Code for Redbooks

IBM WebSphere Developer Technical Journal

WebSphere : developerWorks

WAS 6.0 resources

WAS news

IBM - WebSphere MQ - Library

IBM - WMQ JMS exception messages

Understanding LDAP - Design and Implementation

Finally best for general articles/tutorials on Java

Tuesday, October 21, 2008

How to generate stacktrace

Requesting stackTrace on linux

kill -"quitsignal" "pid"

How to find the signal?

Execute kill -l to get a list of signals and their numbers. See which is the one for QUIT, usually it would be QUIT OR SIGQUIT and number would be 3 based on your OS. Then send quit signal as below:

kill -3 "pid" OR kill -s SIGQQUIT "pid"

The dump file would be created in the corresponding profile directory or the place where it is configured. If you have a open console where process is running, then we can generate the dump by pressing \. On windows we need to press

Getting stackTrace on JBOSS by using JMX console. Select the MBean 'type=ServerInfo' under jboss.system. Invoke the operation listThreadDump() to get the required output.

This link explains clearly how to read stack traces.

Tuesday, October 14, 2008

XML validation using XSD

I was using JAXB for reading one configuration file and before unmarshall, I want to validate the document. To do this we need to know two things:

  1. How to link xml document with schema
  2. How to configure SAX/DOM parser to use the schema and validate
Below are the excellent resources I found explaining above steps:

  1. Link schema with xml
  2. Configure parser to use schema for validation

Friday, October 3, 2008

Creating XSD from XML

Recently we had a requirement to build a data model at the back-end for a web front-end, which is based on an xml file.  Once decided to use jaxb, we realised we didn't have the schema definition but only have xml file.  So started my search for creating xsd from xml.  I found couple of on-line links for xsd creation and other applications supporting this feature.

On-line links

http://www.flame-ware.com/xml2xsd/
http://www.xmlforasp.net/codeSection.aspx?csID=79
http://www.hitsw.com/xml_utilites/

Others
IBM RAD can generate xsd from xml, you need to add xml file as part of some project.
Microsoft also provides a tool xsd.exe, but I guess you need .NET framework for this to work.
Another open-source tool trang.

Monday, September 22, 2008

Reading xls files from Java using apache POI

Ever wondered reading/writing xls, doc files through Java.  Its now (probably since long time) possible using apache POI.  I was specifically looking at reading xls files in order to receive some messages for our application.

I know couple of alternatives, but after finding POI I ignored the rest.  The library for handling excel formats is called HSSF (Horrible SpreadSheet Format).  I wonder why something is ever looked at as bad, maybe it is just the case that we are not able to see the hidden (rather other-side) benefits/workings?

Anyways, HSSF provides two models for reading xls files, usermodel and eventmodelUsermodel is the old one where one can visualize the workbook as number of sheets, each sheet as number of rows and each row as number of columns.  As one can guess memory usage would be more
in this model.

Eventmodel on the other hand is like SAX parsing, where in one would get notified of various events as parsing/reading of the file progresses.  As per the developers comments this is more efficient in terms of memory consumption, processing speed and provides finer control of reading and thus better handling of data within xls files.

To start with I just went ahead with usermodel and successfully converted xls to an xml file.  My sample xls file contains a number of contact details, first row contains headers and remaining rows contain the actual data.  Below is the sample code for converting this data into xml.

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class XLS2XML
{
  HSSFWorkbook workbook = null;
  HSSFSheet sheet = null;
  ArrayList headers = new ArrayList();
 
  public XLS2XML(InputStream in) throws Exception
  {
    workbook = new HSSFWorkbook(in);
    sheet = workbook.getSheetAt(0);
  }
 
  public String xmlExtractor() throws Exception
  {
    StringBuffer ret = new StringBuffer();
    Iterator rows = sheet.rowIterator();
    initialiseHeader((HSSFRow)rows.next());
   
    ret.append("<" + workbook.getSheetName(0) + ">");
    while(rows.hasNext())
    {
      HSSFRow row = (HSSFRow)rows.next();
      ret.append(rowExtractor(row));
    }
    ret.append("");
   
    return ret.toString();
  }
 
  private void initialiseHeader(HSSFRow row)
  {
    short minColIdx = row.getFirstCellNum();
    short maxColIdx = row.getLastCellNum();

    for(short colIdx = minColIdx; colIdx < maxColIdx; colIdx++)
    {
      HSSFCell cell = row.getCell(colIdx);
      if(cell == null)
      {
        continue;
      }
      headers.add(cell.getRichStringCellValue().getString());
    }
  }
 
  private String rowExtractor(HSSFRow row)
  {
    StringBuffer ret = new StringBuffer();
   
    short minColIdx = row.getFirstCellNum();
    short maxColIdx = row.getLastCellNum();

    ret.append("");
    for(short colIdx = minColIdx; colIdx < maxColIdx; colIdx++)
    {
      HSSFCell cell = row.getCell(colIdx);
      if(cell == null)
      {
        continue;
      }
      ret.append(getPrefix(colIdx));
      ret.append(getCellValue(cell));
      ret.append(getSuffix(colIdx));
    }
    ret.append("");
   
    return ret.toString();
  }
 
  private String getPrefix(short i)
  {
    return "<" + headers.get(i).toString() + ">";
  }

  private String getSuffix(short i)
  {
    return "";
  }
 
  private String getCellValue(HSSFCell cell)
  {
    String ret = null;
   
    switch(cell.getCellType())
    {
      case HSSFCell.CELL_TYPE_NUMERIC:
        ret = Double.toString(cell.getNumericCellValue());
        break;
      case HSSFCell.CELL_TYPE_STRING:
        ret = cell.getRichStringCellValue().getString();
        break;
      default:
        ret = "";
    }
   
    return ret;
  }
}

Saturday, September 20, 2008

Set SP params by name - new feature added in oracle 10g jdbc driver

Everyone would try not to hard-code the signature of stored procedure (SP) in all java applications requiring database interaction through SPs. One of many ways could be having the signature defined as an xml config and application can intelligently manage any changes to xml config without any code changes. Most of the complexity in doing so would result from managing the sequence numbers of parameters.

From Oracle10g onwards this shall not be the case anymore as 10g jdbc drivers support SP invocation by param names along with sequence numbers. Unfortunately this is not the case with Sybase yet (have tested with jconn3.jar). Below is the sample code I have used for testing this feature with Oracle driver ver.10.2.0.1.0

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;

public class SPTester
{
  private static CallableStatement setParamsByName(CallableStatement sp) throws Exception
  {
    sp.registerOutParameter("param1", Types.NUMERIC);
    sp.registerOutParameter("param2", Types.VARCHAR);
    sp.registerOutParameter("param3", Types.VARCHAR);
    sp.registerOutParameter("param4", Types.VARCHAR);
    sp.registerOutParameter("param5", Types.VARCHAR);
    sp.setString("param5", "12345");

    return sp;
  }
 
  private static CallableStatement setParamsBySeq(CallableStatement sp) throws Exception
  {
    sp.registerOutParameter(1, Types.NUMERIC);
    sp.registerOutParameter(2, Types.VARCHAR);
    sp.registerOutParameter(3, Types.VARCHAR);
    sp.registerOutParameter(5, Types.VARCHAR);
    sp.registerOutParameter(6, Types.VARCHAR);
    sp.setString(4, "12345");
   
    return sp;
  }

  private static void getParamsByName(CallableStatement sp) throws Exception
  {
    System.out.println("param1: " + sp.getString("param1"));
    System.out.println("param2: " + sp.getString("param2"));
    System.out.println("param3: " + sp.getString("param3"));
    System.out.println("param4: " + sp.getString("param4"));
    System.out.println("param5: " + sp.getString("param5"));
  }
 
  private static void getParamsBySeq(CallableStatement sp) throws Exception
  {
    System.out.println("param1: " + sp.getString(1));
    System.out.println("param2: " + sp.getString(2));
    System.out.println("param3: " + sp.getString(3));
    System.out.println("param4: " + sp.getString(5));
    System.out.println("param5: " + sp.getString(6));
  }

  public static void main(String[] args) throws Exception
  {
    Connection con = null;
    CallableStatement sp = null;
   
    try
    {
      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
      con = DriverManager.getConnection("jdbc:oracle:thin:@<server>:<port>:<sid>", "usr", "pass");
      sp = con.prepareCall("{call <sp_name> (?, ?, ?, ?, ?, ?)}");

      int i = 10;
      if(i == 0) // by sequence
      {
        setParamsBySeq(sp);
        sp.execute();
        getParamsBySeq(sp);
      }
      else
      {
        setParamsByName(sp);
        sp.execute();
        getParamsByName(sp);
      }
    }
    catch(Exception e)
    {
      throw e;
    }
    finally
    {
      try
      {
        if(sp != null)
        {
          sp.close();       
        }
        if(con != null)
        {
          con.close();         
        }
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
    }
  }
}

Monday, July 14, 2008

XML Namespaces

The concept of namespaces is similar to defining a variable with same name in different classes and accessing them by prefixing the object name to resolve the naming conflict. In xml document also if you have to define two elements with same tag (which would probably indicate two different things like html table & dining table) then we can use namespaces to resolve the naming conflict.

Namespace is defined by the xmlns attribute either in the start tag of an element or in the document root element as xmlns:prefix="URI". Below is the example:

<root>
<h:table h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>

<root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture">
<!-- Same as above -->
</root>
The namespace URI is not used by the parser to look up information. The purpose is just to give the namespace a unique name.

Defining a default namespace for an element saves us from using prefixes in all the child elements, the syntax is xmlns="namespaceURI". Below is an example:

<table xmlns="http://www.w3.org/TR/html4/">
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>

Converting DOM objects to XML

These days its rare to find any application not using XML for communicating with other applications. While we all use SAX or DOM parsers either directly or through JAX api, most of us are not aware of org.apache.xml.serialize.XMLSerializer class, which creates an xml string effortlessly. This supports both DOM and SAX. DOM serializing is done by calling serialize(Document) and SAX serializing is done by firing SAX events and using the serializer as document handler. Below is an example of converting a DOM object into xml string:

java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream();
org.apache.xml.serialize.OutputFormat outFormat = new org.apache.xml.serialize.OutputFormat();
org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer();
serializer.setOutputFormat(outFormat);
serializer.setOutputByteStream(outStream);
serializer.asDOMSerializer();
// document is the DOM object created elsewhere
serializer.serialize(document.getDocumentElement());
String outMessage = outStream.toString();

Careful with SAX parser

When parsing xml documents using SAX parser one need to attach an implementation of org.xml.sax.DocumentHandler to receive notifications from the parser. One of the tricky methods in this interface is public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException. Below is the extract from java docs:

The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity so that the Locator provides useful information.

The underlined part above is the thing to be handled carefully. One can not simply read the data and allocate to a String as this method might get called repeatedly!! Below is one example of handling this:

// Buffer for holding the element data
StringBuffer dataBuffer = new StringBuffer();
public void characters(char[] ch, int start, int length) throws SAXException
{
dataBuffer.append(ch, start, length);
}

// Get the data from the buffer in endElement method call

One more quirk is that the characters method removes all encoding for special characters like &, <, > etc. So if the xml data contains these special characters outside CDATA section, one need to handle them explicitly !!

Saturday, July 12, 2008

DecimalFormat issue in jdk 1.4

Any message handling application need to maintain an unique id for each message to track the status. We are generating ids in Oracle database, which are 24 chars long. As this is done with a sequence the id we get is having some zeros followed by a number like '000000001234567890123456'. To remove the leading zeros we are simply converting this to BigDecimal and then again back to string using DecimalFormat as shown in the below code. While doing this we realised that the max number that DecimalFormat can format successfully is 15 digits if all 9's else 16 digits. Any value beyond that is causing the number to be incremented as shown in the below output.

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.StringTokenizer;

public class Test
{
public static void main(String[] args)
{
String[] data = {"999999999999999", "9999999999999998", "9999999999999999", "18411028910519619"};
BigDecimal num = null;
DecimalFormat format = new DecimalFormat();

for(int i = 0;i < data.length; i++)
{
num = new BigDecimal(data[i]);
System.out.println("Bignum: " + num.toString() + " converted to: " + format.format(num));
}
}
}

Output with JDK 1.4:
Bignum: 999999999999999 converted to: 999,999,999,999,999
Bignum: 9999999999999998 converted to: 9,999,999,999,999,998
Bignum: 9999999999999999 converted to: 10,000,000,000,000,000
Bignum: 18411028910519619 converted to: 18,411,028,910,519,620

This is not an issue in JDK 1.6:
Bignum: 999999999999999 converted to: 999,999,999,999,999
Bignum: 9999999999999998 converted to: 9,999,999,999,999,998
Bignum: 9999999999999999 converted to: 9,999,999,999,999,999
Bignum: 18411028910519619 converted to: 18,411,028,910,519,619