Wednesday, June 13, 2012

Aspect Oriented Programming

Aspect Oriented Programming (AOP) is a promising new technology for separating crosscutting concerns that are usually hard to do in object-oriented programming. This article aims to be an introductory point to the basic concepts associated with this new paradigm.

Crosscutting Concerns

An example of crosscutting concerns is "logging," which is frequently used in distributed applications to aid debugging by tracing method calls. Suppose we do logging at both the beginning and the end of each function body. This will result in crosscutting all classes that have at least one function. Other typical crosscutting concerns include context-sensitive error handling, performance optimization, and design patterns.

Crosscutting concerns may exist in some programs, especially large ones. However, in some situations, redesign of the system might transform a crosscutting into an object. AOP assumes that crosscutting concerns may exist in programs and can't be re-factored out of the design in all situations.

Aspect Oriented Programming and Java

AOP is a concept, so it is not bound to a specific programming language. In fact, it can help with the shortcomings of all languages (not only OO languages) that use single, hierarchical decomposition. AOP has been implemented in different languages (for example, C++, Smalltalk, C#, C, and Java).
Of course, the language that gains a great interest of the research community is the Java language. The following is a list of tools that support AOP with Java:

A very simple approach is  AspectWerkz .

Ref : http://aspectwerkz.codehaus.org/index.html

Friday, April 20, 2012

JStuff

Annotations:

  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compiler-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime.

 

Annotation is a very powerful mechanism and can be used in a lot of different ways:
  • to describe constraints or usage of an element: e.g. @Deprecated, @Override, or @NotNull
  • to describe the "nature" of an element, e.g. @Entity, @TestCase, @WebService
  • to describe the behavior of an element: @Statefull, @Transaction
  • to describe how to process the element: @Column, @XmlElement

Usage of annotations:
  • Documentation, e.g. XDoclet
  • Compilation
  • IDE
  • Testing framework, e.g. JUnit
  • IoC container e.g. as Spring
  • Serialization, e.g. XML
  • Aspect-oriented programming (AOP), e.g. Spring AOP
  • Application servers, e.g. EJB container, Web Service
  • Object-relational mapping (ORM), e.g. Hibernate, JPA
  • and many more...
------------------------------------------------------------------------------------------------------------

Struts-Flow:


1) When first the request is made from a JSP/HTML/XSLT to the server with a particular URI(/something.do), the controll first reaches Web.xml file.
2) it checks the mapping for /something.do in web.xml and finds the ActionServlet and loads ActionServlet.
......
<servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
.....

    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
3) As part of loading ActionServlet calls the init() as every other servlet does.
(Note: ActionServlet extends HttpServlet only)
......................
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
........................
4) in init() it takes the init-parameters as struts-config.xml and loads the xml file.
5) then the ActionServlet calls the proceed() of RequestProcessor class.
6) in proceed() , it checks the appropriate mapping for current request, creates and ActionMapping object and maps the URI to the action in the struts-config.xml.
7) then it creates an object to ActionForm associated to that action mapped object

8) calls the setters and reset().

9) if the action tag in struts-config.xml contains validate="true", then the validate method is called.

10) if any validation errors, it return to view component (any jsp,XSLT) which is specified as an attribute of input="/error.jsp"

11) if there are not validation errors, it then creates an Action class for that mapping and search for execute method and executes it.

12) execute method performs the bussinesslogic which you provide and returns with an ActionForward key.

13) now the returned key is searched in the mapping object which is specified as forward tag.

14) it looks for the appropriate view component and performs the getters on that view component and returns the response to the browser.

Message Driven Bean

A MDB is component can process messages asynchronously. This is associated with JMS service. Basically it works as JMS Listener. The messages can be sent by any client like JMSclient, any other EJB,system that does not use Java EE technology. Bean associated with JMS queue or topic.

Monday, March 19, 2012

XML Info

SAX Parser:
  1. Event based model.
  2. Serial access (flow of events).
  3. Low memory usage (only events are generated).
  4. To process parts of the document (catching relevant events).
  5. To process the document only once.
  6. Backward navigation is not possible as it sequentially processes the document.
  7. Objects are to be created.
DOM Parser:
  1. (Object based)Tree data structure.
  2. Random access (in-memory data structure).
  3. High memory usage (the document is loaded into memory).
  4. To edit the document (processing the in-memory data structure).
  5. To process multiple times (document loaded in memory).
  6. Ease of navigation.
  7. Stored as objects.
XPath :
  • XPath is used to navigate through elements and attributes in an XML document.
  • Used in XSLT.
  • XPath uses path expressions to select nodes or node-sets in an XML document.

Friday, February 17, 2012

Linux Commands

 Count number of files in a directory:
    
  $  ls -1 targetdir | wc -l

The above method will count symbolic links as well as subdirectories in targetdir (but not recursively into subdirectories).

If you want to exclude subdirectories, you need a heavier duty tool than ls.
 
$ find targetdir -type f  -maxdepth 1 | wc -l
 
 type f ensures that the find command only returns regular files for counting (no subdirectories).   

By default, the find command traverses into subdirectories for searching.  -maxdepth 1 prevents find from traversing into subdirectories.   If you do want to count files in the subdirectories, just remove -maxdepth 1 from the command line.

Note that the find command does NOT classify a symbolic link as a regular file.  Therefore, the above find -type f command does not return symbolic links. As a result, the final count excludes all symbolic links.

To include symbolic links, add the -follow option to find.
 
$ find targetdir -type f -follow  -maxdepth 1 | wc -l 

Tuesday, February 7, 2012

Classloader issues with MQ shared object files

NoClassDefFoundError: com/ibm/mq/server/MQSESSION when running WSMQ adapter in bindings mode

Symptom

GIS 4.1.1 Build Version: 1982_BR4932266_SR1370953
Customer is able to use WSMQ adapter without issue when running in client mode. When switching to bindings mode, an initializer error and no class definition found error is logged in the WebSphereMQSuite.log
Verified that the correct jars are referenced in dynamicclasspath.cfg, and that they exist at the specified locations.
Error Message [2009-05-26 10:40:19.53] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-515856336> ##[DEBUG]## startupAdapter
[2009-05-26 10:40:19.54] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> ### WSMQAsyncRcv thread running ###
[2009-05-26 10:40:19.54] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-515856336> ##[DEBUG]## startup complete
[2009-05-26 10:40:19.547] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> ##[DEBUG]## ThreadMgr maxThreads=10
[2009-05-26 10:40:19.547] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-ccaita2p:16ff17dd:1217d5d1ebc:-100f-5149388 32> ##[DEBUG]## Attempting to open a connection with the following values:
MQEnvironment version_notice=MQSeries classes for Java V5.2.0
hostname=null (bindings mode)
port=1414
qManager=QM0.PR.US.CCAITA2P
channel=null (bindings mode)
[2009-05-26 10:40:19.589] ERROR 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> Exception in WSMQAsyncRcv thread
java.lang.ExceptionInInitializerError
at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java(Compiled Code))
at com.ibm.mq.MQSESSION.getSession(MQSESSION.java(Compiled Code))
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java(Compiled Code))
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBind ingsManagedConnectionFactoryJ11.java:179)
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindi ngsManagedConnectionFactoryJ11.java:215)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java(Compiled Code))
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManage r.java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory. java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.jav a(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java(C ompiled Code))
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java(Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.openConnection(WSM QSession.java(Inlined Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.openSession(WSMQSe ssion.java(Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQAsyncRcv$1.run(WSMQAsyncRc v.java(Compiled Code))
Caused by: java.lang.NullPointerException
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2159)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1994)
at java.lang.Runtime.loadLibrary0(Runtime.java:824)
at java.lang.System.loadLibrary(System.java:908)
at com.ibm.mq.MQSESSION.loadLib(MQSESSION.java:1088)
at com.ibm.mq.server.MQSESSION$1.run(MQSESSION.java:230)
at java.security.AccessController.doPrivileged1(Native Method)
at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))
at com.ibm.mq.server.MQSESSION.<clinit>(MQSESSION.java:224)
... 15 more
[2009-05-26 10:40:19.686] ERROR 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> Exception in WSMQAsyncRcv thread during backout
java.lang.Exception: Queue Manager is null.
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.backout(WSMQSessio n.java(Inlined Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQAsyncRcv$1.run(WSMQAsyncRc v.java(Compiled Code))
[2009-05-26 10:40:19.687] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> ### Exception occurred - waiting to retry
[2009-05-26 10:45:19.688] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-ccaita2p:16ff17dd:1217d61d8d8:-3273-5149388 32> ##[DEBUG]## Attempting to open a connection with the following values:
MQEnvironment version_notice=MQSeries classes for Java V5.2.0
hostname=null (bindings mode)
port=1414
qManager=QM0.PR.US.CCAITA2P
channel=null (bindings mode)
[2009-05-26 10:45:19.688] ERROR 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> Exception in WSMQAsyncRcv thread
java.lang.NoClassDefFoundError: com/ibm/mq/server/MQSESSION
at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java(Compiled Code))
at com.ibm.mq.MQSESSION.getSession(MQSESSION.java(Compiled Code))
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java(Compiled Code))
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBind ingsManagedConnectionFactoryJ11.java:179)
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindi ngsManagedConnectionFactoryJ11.java:215)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java(Compiled Code))
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManage r.java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory. java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.jav a(Compiled Code))
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java(C ompiled Code))
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java(Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.openConnection(WSM QSession.java(Inlined Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.openSession(WSMQSe ssion.java(Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQAsyncRcv$1.run(WSMQAsyncRc v.java(Compiled Code))
[2009-05-26 10:45:19.689] ERROR 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> Exception in WSMQAsyncRcv thread during backout
java.lang.Exception: Queue Manager is null.
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQSession.backout(WSMQSessio n.java(Inlined Compiled Code))
at com.sterlingcommerce.woodstock.services.wsmqSuite.WSMQAsyncRcv$1.run(WSMQAsyncRc v.java(Compiled Code))
[2009-05-26 10:45:19.689] ALL 000000000000 GLOBAL_SCOPE <WSMQAsyncRcv-TA.CA.INFRA.TEST_Node2-514938832> ### Exception occurred - waiting to retry

Resolving the problem

Currently this issue does not have a resolution; it is being worked on by IBM Sterling Support. If you believe you are experiencing this issue and would like to be notified when a resolution is reached, please open a case through Customer Center and ask that it be associated with number 25540

Monday, January 23, 2012

How to delete a profile from a WebSphere 6.1 & 7.0 application server


Step 1.


Location of tool:

\AppServer\bin\manageprofiles.bat

syntax:

manageprofiles.bat -delete -profileName (case sensitive commands)

Note: This used to be wasprofile.bat in version 6.0.x and is depricated in 6.1.

The Windows service for the profile will have been set to disabled now.


Step 2.


Delete the folder e.g \ApplicationServer\profiles\


Step 3.


manageprofiles.bat -validateAndUpdateRegistry

This process validates the profile registry and lists the non-valid profiles that it purges.


Step 4.


Remove the Windows service that is set to run the profile.

WASService.exe -remove
service_name

e.g If the service name is "IBM Websphere Application Server V6.1 - Node"

Then the command will be:

WASService.exe -remove "Node"


You can also look at this document on WebSphere NT Services
-- For Linux box you will have .sh files
http://www.webspheretools.com/sites/webspheretools.nsf/docs/Using%20WASService.exe%20to%20help%20with%20configuring%20windows%20services%20for%20IBM%20WebSphere%20Application%20Server.