SOA / Web Services / Java

A Technology Blog

When to use REST based web services?

Posted by oracled on March 11, 2009

REST expose a much simpler interface than SOAP, with some limitations. Development with REST is easier and quicker and this is the reason why most famous web APIs are REST-based.
 
The limitations are related to the protocol: with REST you are bound to HTTP. So it is difficult to handle different transports like MQ or JMS. So if you are designing an application to be used exclusively on the web, REST could be the option. If you are designing a SOA for an Enterprise, that needs to interconnect to multiple systems using multiple transport/channels and having sophisticated transactions to be modeled with BPMs, then it is better to go with SOAP.
Note than you are going to pay SOAP’s flexibility with development complexity: SOAP interfaces are described by the WSDL standard which looks really complicated and is not supposed to be read by humans.

RESTful applications simply rely on the built-in HTTP security (the HTTPS protocol), with SOAP you can have more sophisticated choices, like WS-Security that lets you encrypt only portions of the messages and moves the security handling from the transport layer to the message layer.

REST is younger than SOAP, so it is not as well supported by commercial products (both BPM and ESB products). However new versions of the major ESBs support REST (ex mule, openesb).

RESTful services do not have a strict describtor, they tried to define something simmilar to WSDL, it’s called WADL (https://wadl.dev.java.net/). The WADL is currently not a common standard the adoption is very low and mostly not wanted for RESTful services.

Even for ESB’s most of the vendors where lacking the support some month ago. But now nearly each big ESB vendor (commercial or open source) supports the RESTful protocol. From the usage of an ESB it is currently not a problem to run RESTful services.

If you plan to run a very big deployment with many data interfaces, you will get great benefits using RESTful Services. REST is based 100% on the HTTP rfc (http://www.w3.org/Protocols/rfc2616/rfc2616.html). Many of the RESTful Interface which you see currently on the internet do not fully support HTTP specification, the result is that they could not benefit from it in terms of performance, caching, content negotiation and security. 
One great reason is to use RESTful interfaces is it can easily support different content-types/mime-types. First you think about, vendor specific XML with a xsd definition, later you would like to support AJAX Mashups and even later you think about to support text formats, reports in PDF, and so on. This is very easy to implement with REST because you query always with the same data query but the requested content type is just different.
Another reason why people are using RESTful interfaces is to be scalable like the web (www) and google. This is possible when you are using plain and simple HTTP protocol. You have support from so many standard product like web proxy caches (like SQUID) or other to scale your application a very low effort. For Social Communities you have have now a new Standard for RESTful Service Security. It is called Oauth (http://oauth.net/) which makes authentication over HTTP very easy.

Some other examples where RESTFul Services are dominant:
Amazon AWS: E.g. they offer Services for Storage (S3) and they have SOAP and REST interfaces but over 90% of the clients are using REST
Google Maps is using RESTful uris to provide cachable map tiles
yahoo API’s are mostly build with RESTful interfaces
RESTful Services are very dominant in lighweight web 2.0 API’s for Mashups like OpenSocial
API.

REST design is good for the database driven applications and when client wants quick integration.

Posted in Web Services | Leave a Comment »

Some Web Services Best Practices

Posted by oracled on March 7, 2009

1. Start designing web service with WSDL and schema i.e., follow Top-Down approach.If already have classes or EJBs that need to be exposed as web services,then bottom-up approach is the only choice and the resulting WSDL will be generated by Web Services toolkit. It is easy to design a Web Service from exisiting classes but then it offers less flexibility when reuse of definitions are desired. Also, the WSDL will contain a format that is specific to the web services toolkit being used and it will not be possible to add extra information or annotations in the WSDL by including the documentation element of WSDL.

2. In RPC style of web services, the job of marshalling and unmarshalling is performed by SOAP engine. This may lead to significant performance degradations if complex operations are involved. However, RPC style web services are better suited for implementing fine-grained functionalities.

3. Implemention of Document style web services is complex and time-consuming. Document-style Web Services can handle large documents without any performance trade-offs. If coarse-grained functionality is required then Document style web service is the right choice. These are also suitable when asychronous operations are involved.

4. Using “encoding” requires both sides to have prior knowledge of the encoding style. It is the responsibility of SOAP engine to perform encoding adn decoding, which is an overhead. It is not preferred for complex data structures.

5. When use is set to “literal”, XML schema directly defines the data types. It is preferred when complex and custom data types are involved and better performance is desired.

6. To decide what style and use from available choices: RPC-encoded, RPC-literal, Document-literal and Document-encoded, should be used, following link that gives detailed explanation can be referred:
 
 http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ 

7. SOAP with attachment or SwA is useful for documents that conforms to schema in languages not supported by web service end point.Sending information as attachments rather than in SOAP body results in smaller body and faster processing. However, writing a SOAP handler can be tedious. Care should be taken while using Message Queues to transmit the message as the message queue capacity may be less and the message may require chopping.

8. Though services can maintain state whenever there is a high volume of related requests and responses and responses need to sent in pieces. Maintaning state is not desired when trying to implement Service Oriented Architecture though.

9. As XML is verbose and takes up considerable size, solutions like binary-XML can be used to zip or compress the message. Both client and server should be able to access the compression technique.

10. Use message oriented middleware (MOM) to handle asynchronous communication and where sensitive data are transmitted. This is a good choice to achieve Reliable Messaging.

11. Data binding specific to a SOAP engine is switched off in case of Document –literal style web service. Custom binding mechanisms like castor, xmlbeans, JAXB, JaxMe can be used by applications to offload the job of marshalling and unmarshalling from SOAP engine and handle custom data types.

12. SOAP engines use parsing mechanisms internally. Parsing is an overhead and it can lead to performance issues. Axis 2.0 uses a new mechanism called AXIOM (AXis Object Model) which is a StAX-based, XML Infoset compliant object model which supports on-demand building of the object tree.

13. Use WS-Security for transmitting sensitive data. However, always secure part of message and not the entire message. Usage of HTTPS for transport level security is desired. SAML should be used for identity management.

14. Use a test harness tool like SOAPUI for testing the web services client by creating mock or simulated web services. Use TCP/IP monitor for tracing the SOAP messages.

15. XML security gateways and proxies can be used to prevent Denial of Service (DoS) attacks.

16. ESB or Enterprise Service Bus can be used when there is lot of integrating logic and activities like message routing, validation, enrichment, transformation, monitoring, logging and event management need to be deferred. ESB is the underlying infrastructure for implementing SOA. Canonical applications can be exposed as web services using adapters and current world ESBs are equipped with adapters for such applications.

17. Use UDDI-based registry to maintain a system of record, increase visibility of services and manage lifecycle and versioning of services.

18. Use a workflow language like BPEL to orchestrate services and provide Business Process Management (BPM). This is important for facilitating agility and hiding technical complexities.

19. Check if your web service is WS-I basic profile compliant and conforming to all the rules. http://www.ws-i.org/deliverables/workinggroup.aspx?wg=basicprofile

Posted in Web Services | Leave a Comment »

WSRR Installation Issues

Posted by oracled on March 6, 2009

WSRR or Websphere Service Registry and Repository is IBM’s answer to a robust SOA Governance solution framework. Every complex product brings some issues along with it and when its an IBM product, it is obvious.

If you are installing WSRR 6.1, make sure you have followed the below mentioned steps:

1. Installed Websphere Application Server (WAS) 6.1.0.13 or later.  If not, first install Update Installer in WAS Installation Directory.

2. Install Websphere Application Server fix pack using Update Installer on top of existing Websphere Application Server installation.

3. Install IBM SDK SR6 using Update Installer from here

4. Install Oracle or DB2 database and create database schema.

5. Install Websphere Service Registry Repository

6. Deploy WSRR on WAS using “deploywizard” or “installall” batch/shell scripts (Located under WSRR_HOME/install directory).

To download Update Installer, interim fix and Fix Packs 13 for windows, Click Here

Note: Web Service feature pack is not required for WSRR. If you have already installed Web Services feature pack, please install interim fix and Fix Pack for Web Services feature pack before following step 3. (Not Recommended)

Chances are that deployment of WSRR ear on WAS may fail. In such cases, make sure that

1. you have correctly specified server and profile details of WAS on one of the deployement details screens.

2. If you are on database details screen, choose “Preload the database” option rather than “Reuse an existing database” option. If not, you may end up getting only configuration perpective of WSRR. Administrator and User perspective may not be visible. Though, you can go to Configuration –> Manage Configuration Profile –> Configuration Profiles from your WSRR Homepage, Select Load Configuration Profile, Browse to $REGISTRY_HOME/samples, select SamplesProfile.zip, select OK and Restart server.

3. If you have opted for Oracle database, make sure you have set Oracle_JDBC_Driver_Path. If not, go to WAS Administrative Console –> Environment –> Websphere variables. Set the value for Oracle_JDBC_Driver_Path and restart server.

Posted in SOA Governance | Leave a Comment »

Parse WSDL effectively

Posted by oracled on February 4, 2009

As a WSDL’s constituents are well-defined already, it is feasible to use a parser that can get the elements of the WSDL using APIs that are already defined. This will minimize complexity in the code and will help in achieving better performance.

 

Oracle WSDL parser is one such option.

 

It is only needed to import the necessary classes as the APIs are already defined and packaged with wsdl.jar.

 

//importing the necessary classes from library

import oracle.wsdl.WSDLDocument;

import oracle.wsdl.internal.Binding;

import oracle.wsdl.internal.Definitions;

import oracle.wsdl.internal.Documentation;

import oracle.wsdl.internal.Import;

import oracle.wsdl.internal.Message;

import oracle.wsdl.internal.PortType;

…….

 

 

WSDLDocument wsdldoc = new WSDLDocument(wsdl_url);

//getting definition element

Definitions definition = wsdldoc.getDefinitions();

//getting service element

Map servicesMap = definition.getServices();

//getting binding element

Map bindingsMap = definition.getBindings();

//getting PortType element

Map ptypesMap = definition.getPortTypes();

//getting message element

Map messagesMap = definition.getMessages();

//getting import details

Map importsMap = definition.getImports();

//getting documentation details

Documentation docs = definition.getDocumentation();

 

 

As there can be multiple elements, an “iterator” can be used to parse an individual element.

For Example:

 

Iterator iterator = servicesMap.entrySet().iterator();

        while (iterator.hasNext()) {

            Map.Entry me = (Map.Entry) iterator.next();

            …….

        }

 

The above code fragments keep things fairly simple while processing a WSDL.

 

Apache Woden

 

Woden provides Java class library for reading, manipulating, creating and writing WSDL documents.

 

Woden’s DOM-based XML parsing depends on Apache Xerces 2.7.1. Its XML Schema support it depends on the schema parser and object model implemented by the Apache Web Services Commons (ws-commons) XmlSchema project.

 

//importing necessary classes from woden jars

import org.apache.woden.WSDLException;

import org.apache.woden.WSDLFactory;

import org.apache.woden.WSDLReader;

import org.apache.woden.wsdl20.Binding;

import org.apache.woden.wsdl20.Description;

import org.apache.woden.wsdl20.Interface;

import org.apache.woden.wsdl20.Service;

….

 

  

 

WSDLFactory factory = WSDLFactory.newInstance();

WSDLReader reader = factory.newWSDLReader();

reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);

String wsdlurl = “C://axis2-1.4.1//newwsdl.wsdl”;

 

//reading the WSDL Document

DescriptionElement descElem = (DescriptionElement) reader.readWSDL(wsdlurl);

Description descComp = descElem.toComponent();

 

//getting Interface, Binding and Service elements

InterfaceElement[] interfaces = descElem.getInterfaceElements();

BindingElement[] bindings = descElem.getBindingElements();

ServiceElement[] services = descElem.getServiceElements();

  

 

Complete details about usage and extensibility of woden are available at:

 

http://ws.apache.org/woden/userguide.html

 

JWSDL:

 

 

JWSDL is another option that is intended for use by developers of Web services tools and others who need to utilize WSDL documents in Java.

JWSDL is designed to allow users to read, modify, write, create and re-organize WSDL documents in memory. JWSDL is not designed to validate WSDL documents beyond syntactic validity. One use of JWSDL is to develop a tool that validates WSDL semantically.

JWSDL is designed for use in WSDL editors and tools where a partial, incomplete or incorrect WSDL document may require representation.

 

Details of JWSDL can be obtained by accessing the following link:

 

http://wsdl4j.sourceforge.net/downloads/JSR110_proposed_final_draft.pdf

Posted in Java/J2EE, Web Services | Tagged: , , | Leave a Comment »

What XML parser to use?

Posted by oracled on February 3, 2009

XML, being the lingua franca of web services, has found its use in many applications mostly because of its platform agnostic feature. Applications using XML and XML-based artifacts like SOAP, WSDL etc. tremendously require traversal, customization and transformation of these artifacts to suit its needs. This is the reason why we see parsing and binding (marshalling and unmarshalling) of XML documents at various critical points in an application. One important thing to note is that XML is verbose and leads to various performance issues when processed, especially in complex environments. Over the years, we have seen use of DOM (Document Object Model) and SAX (Simple API for XML) parsers but these parsers have their own limitations and require trade-offs in some situations. For example,  

DOM requires in-memory representation of the XML document, which exerts unnecessary pressure on system resources and is thus considered impractical for large documents. Also, DOM APIs introduces complexity while processing XML nodes.

Other alternatives or parsers that use tree-based APIs are dom4j, JDOM and XOM. While dom4j document object model is fast and memory-efficient and offers great extensibility, JDOM is mostly known for its ease of use. The XOM document object model protects users from common mistakes in the use of XML, while offering good performance and memory efficiency. 

SAX, on the other hand, is inappropriate when reordering or cross-referencing of XML nodes is desired. 

WoodStox is an XML processor that combines the best of both the worlds. In other words, it is easy to use or convenient like DOM and efficient like SAX. It is an open source implementation of StAX pull parser standard. It, however, encounters performance issues like Xerces2, the Apache Implementation of the W3C document object model standard, when dealing with small documents, for eg. SOAP. 

To improve the performance of such widely-used XML parsers, Apache introduced a new parser. This new parser, AXIs Object Model (AXIOM), is considered not just another object model but a very useful and performance enhancing parser for CPU and Memory intensive applications. AXIOM tries to achieve its objective of being a memory-efficient parser by deferring creation of XML tree when not required. AXIOM is StAX (Streaming Api for XML) based object model and it implements “pull-parsing” methodology, unlike SAX and DOM. It also has built in support for XML Optimized Packaging (XOP) and MTOM, the combination of which allows XML to carry binary data efficiently and in a transparent manner. Another important feature supported by AXIOM is that it provides APIs to parse SOAP (Simple Object Access Protocol) documents effectively. When the APIs are already defined, complexity can be easily avoided and performance overhead can be easily tackled. Apache’s SOAP engine Axis2, thus, has provision for AXIOM. AXIOM’s ability to support various binding mechanisms helps it optimize the marshalling and unmarshalling of XML fragments and hence, results in improved performance.

 

While AXIOM has pre-defined APIs for parsing a SOAP message, it should also be possible to define APIs that can extract elements from a WSDL (Web Services Description Language) file.

 

Posted in Java/J2EE, Web Services | Tagged: , , | Leave a Comment »

Preserve white spaces in a SOAP message

Posted by oracled on January 30, 2009

Sometimes, the business requirement mandates that a SOAP request/response should maintain leading or trailing spaces that are present in a variable. By default, this does not happen. For example, you may expect ” ABC” or “ABC “, but you get “ABC”. The spaces are removed. Also, you may encounter issues if you use a binding mechanism like JAXB to marshal/ unmarshal xml fragments.  This requires modifying the default marshalling or unmarshalling behavior. This is how you can still maintain any whitespaces:

Before marshalling call

marshaller.setPropertyMarshaller.JAXB_ENCODING, “UTF-8″)

 which informs MarshallerImpl#createWriter(…) to create a UTF8XmlOutput instead of SAXOutput. 

UTF8XmlOutput escapes line-break into “ ”, which will be preserved when unmarshalling is performed by any xml parser.

Posted in Web Services | Tagged: , , | Leave a Comment »

Best UDDI Registries

Posted by oracled on January 27, 2009

UDDI service registry is of paramount importance when it comes to providing a SOA Governance solution. A service registry stores metadata that is related to the particular asset you have interest in, without actually containing those assets.  It is essentially an online directory of services that enables the service providers to advertise their offerings and allowing service consumers to find services that match their criteria. It provides a foundation for the governance and lifecycle management of Business Services. It provides with what is needed to obtain enterprise-wide insight, control and economic leverage of organization’s business and service artifacts. The registry also supports metadata like classifications, categorizations, relationships and properties. These metadata are then used to define taxonomies, describe how service artifacts are related to each other and associate generic as well as object specific characteristics for service artifacts.

Here are some UDDI registries that are widely used in organizations:

1. Systinet Registry (now HP SOA Systinet Registry)  

2. Oracle Service Registry : It is a modified version of Systinet Registry. Remodeled according to Oracle needs.

3. Aqualogic Service Registry: Again a modified version of Systinet Registry.

4. IBM Web Services Registry Repository

5. TIBCO ActiveMatrix: Again a modified version of Systinet Registry.

Posted in SOA Governance | Tagged: , , , , | Leave a Comment »

5 things that suck about working in IT (and 5 things that don’t)

Posted by oracled on January 26, 2009

Posted in Miscellaneous | Leave a Comment »

Good Practices: Oracle BPEL

Posted by oracled on January 26, 2009

–Do not import or add XSD files in a ZIP file into a BPEL project. Always  extract the XSD files from a ZIP file before importing them.

–Do not include any special characters in the project name (such as periods). If you do include special characters, errors appear when you attempt to compile your project

–The bpel.xml file content is only read into memory when the file is opened. Therefore, if you change the content of bpel.xml after the file is opened, the changes are not made in memory. After changing the content of the BPEL file, close and reopen the file for the changes to take effect.

–Do not edit the bpel.xml file through a combination of Oracle JDeveloper and a text editor such as Notepad or Wordpad. Use only a single editing environment such as Oracle JDeveloper.

–Do not edit the bpel.xml file, BPEL files, and WSDL files while changing the
design of the process. If you want to edit a file:
1. Ensure that the BPEL files are not being edited in Oracle JDeveloper. If they are being edited (that is, a tab for that file is visible), close it and save changes as needed.
2. Edit the required file and save the changes

–Oracle BPEL Process Manager does not support SOAP-encoded arrays.(soapenc:arrayType).
Use one of the following workarounds:
         * Apache Axis supports document-literal style services. This means you can change the service to not use soapenc:arrayType.
         * A wrapper can be placed around the service (also using Apache Axis) so that the BPEL process talks to the document literal wrapper service, which in turn calls the underlying service with soapenc:arrayType.
         * Call a service with soapenc:arrayType from BPEL, but construct the XML message more manually in the BPEL code. This enables you to avoid changing or wrapping the service. However, each time you want to call that service from BPEL, you must take extra steps

–If you use large binary attachment files in SOAP messages with Oracle Database Lite, your BPEL process may not complete processing, which can cause you to run out of system memory. Oracle Database Lite is largely for testing purposes. To use large binary attachment files in SOAP messages, use an Oracle Database as your dehydration store

–Use TCP tunneling to view SOAP messages exchanged between the BPEL process flow and the Web service (including those containing the
correlation ID). You can see the exact SOAP messages that are sent to, or received from, services with which a BPEL process flow communicates.

–Instead of manually entering an expression, you can press Ctrl and then the space bar in the Expression field. Scroll through the list of values that appears and double-click the value you want. Edit the value as necessary. As you enter information, a trailing slash can appear. This means you are being prompted for additional information. Either enter additional information, or press the Esc key and delete the trailing slash to complete the input of information.

–Do not copy and paste the expression syntax shown in this document into Oracle JDeveloper. This is because the single and double quotation marks are sometimes not compatible with Oracle JDeveloper. Instead, use the Expression Builder window or press Ctrl and then the space bar to use the XPath Building  Assistant.
 
–When you deploy a process with the same name and version, you are prompted to overwrite the currently-deployed BPEL process or deploy to a new version number. The best practice is to always deploy to a new version (as described in this tutorial). Redeploying a process with the same version can have consequences, such as instances being marked as stale.

 

I recommend reading the following article about Managing complexities within a BPEL Environment. It includes some of the best practices one can follow to ensure availability of BPEL Infrastructure.

http://soa.sys-con.com/node/744119

Hope it helps.

Posted in jdeveloper, oracle | Leave a Comment »

Some J2EE Best Practices

Posted by oracled on January 12, 2009

 

–Use the MVC, or Model 2, architecture pattern to isolate and modularize screen logic, control logic, and business logic. A generic MVC implementation is a key component of the reference architecture as it provides a flexible and reusable foundation for rapid Web application development.

–A large session size can quickly degrade the scalability and performance of an application. It is recommended that the size of the session be kept fairly small. How small is small enough? Well, remember that the session size multiplied by a number of users gives an amount of memory that will be consumed on the Web tier. Taking into consideration that this amount is only a portion of the memory needed to run the application, you can get a rough idea of the number of concurrent users that will be supported by a single instance of a JSP container. Multiply this number by the number of JSP container instances in your production cluster, and this gives you a rough limit on the total number of concurrent users your application can support.

–The delete operation of a business object should also encapsulate the deletion of any aggregated objects in order to ensure data integrity.

–The create operation of a business object should also encapsulate the creation of any required aggregated objects such as a Customer and the corresponding Address. Other aggregated objects are created later in the parent lifecycle by corresponding business methods, such as the aggregated Transaction object that is created by the deposit method on an Account object.

–Do not use Entity Bean finder methods to iterate through a result set of business objects unless you can enforce either a read-only caching strategy or an aggressive-loading approach by the container. For a result set of n objects using lazy loading, this can actually cause (n + 1) database interactions. Use a JDBC wrapper component to run the database query and either hold the result set for iteration or return a set of value objects. This limits the operation to one database interaction.

–Perform some amount of load testing early on in your projects to determine if Entity Beans provide an acceptable level of performance in your application environment. As a general rule, you may want to consider using Java business objects instead of Entity Beans for extremely high throughput application components. If performance is acceptable, use Entity Beans to take advantage of a standard component model that provides services such as object persistence and transaction concurrency. Also, use Entity Beans if you want to distribute business objects directly to remote clients. When using either implementation model, consider planning for a migration path between the two. Application requirements or transaction volumes may change. Robust EJB 2.0 container implementations will likely provide a much increased boost from earlier versions; however, test in your environment before making a decision to commit to the Entity Bean model.

–For a lightweight optimistic locking solution, use an integer property with a standardized name on business objects as an optimistic lock column to handle transaction concurrency. The data access objects can generically increment the property’s value and include it in the WHERE clause on UPDATE and DELETE statements. If no rows are found from the SQL statement, an Optimistic Lock exception is thrown. Many J2EE containers and object-relational mapping vendors provide support to make implementing optimistic locking quite easy by allowing the developer to designate an optimistic locking column.

–It is a good practice always to use the getter and setter methods of a given property, even within other methods in that business object. This is the strictest form of encapsulation, in which only the getter and setter methods actually refer to the member variable. The member variables are declared as private to help enforce this concept, although use within the class itself requires discipline by the programmer. This technique can be beneficial in many ways. One example of when this comes in handy is the case in which a property does not have an assigned value. If you referred directly to the member variable, your code would get a NullPointerException in this case. However, use of the getter method can protect you from this condition by checking for this and initializing the value. This logic can then be implemented and encapsulated in one place, and other methods do not need to worry about this condition. This concept becomes even more powerful when the concept of lazy instantiation is used in getter methods for aggregated objects.

–Use of a standard interface for business objects is a good technique that can ensure consistency across business objects. In addition to making code more maintainable, this standard interface enables you to automate a number of business object functions and services because you can implement them generically, referring only to the Java BusinessObject interface.

–Use an error utility class to consistently and effectively manage business errors in your application

–Use exceptions whenever processing should halt immediately in a given method. Business errors should then be used wherever processing may continue in the case of an error occurring

–Map system-level exceptions to defined business errors that have more meaningful messages that can be presented to the users.

–Isolate the JDBC logic to execute a SQL statement in a common utility class. This prevents every application developer from having to write this common logic and ensures that all resources are closed properly.

–Whether you are using Entity Beans or regular Java business objects, use a factory method (Erich Gamma et al. 1995) abstraction to create and discover instances of business objects. This simplifies the client code and provides a hook for potential future optimizations such as caching EJB Home interfaces. You can create a BusinessObjectFactory utility class to do this. In the case of EJBs, the BusinessObjectFactory can use the EJB Home interface to look up the Entity Bean. In the case of Java business objects, you can instantiate and populate the proper business object within the BusinessObjectFactory.

–Managing a list of objects for data retrieval or for selective updates is a common operation in business applications. Consider the use of a utility class that consistently and effectively manages collections of objects for you. If Entity Beans are used as the business object implementation, you can also use the collection utility to get a list of value objects and have it instantiate corresponding Entity Beans for any transactional updates.

–Always use business objects for transactional updates to ensure data integrity and avoid redundant business logic validation code. Straight database queries can be used for read-only operations if they are more effective at traversing large table structures. However, this should be done only if you can mitigate the risk of having database names permeate throughout the application code.

–Use the Template Method pattern to implement common behaviors in the business object base class. A primary example of this is the save method, which can call a hook method to perform data validation, specific object validation, and any presave logic implemented in the subclass.

–Use a metadata format that allows your design models to be the original source of the metadata. Either build your metadata parser to read the XMI format or use a conversion utility to create your own XML format from XMI, which is generated by development tools from the design models.

–Cache frequently used data that is fairly static to speed application performance. Use a consistent, extensible cache mechanism that can be implemented either as a Stateless Session Bean or as a Java singleton class. If the cached data can be updated and the application needs the latest data, consider the use of a JMS solution for notifying caches across a cluster to refresh their data

–Implement service-based components as stateless Session Beans to take advantage of Enterprise Java services such as distribution and transaction management while maximizing scalability and performance

–Put the actual workflow and transaction logic of the service in a Java class. This implementation of the service can then be wrapped by the Session Bean to engage the container-managed services of transaction management, distribution, and so on. This allows services to be reused within other services more efficiently because you have the option of avoiding another EJB method invocation. Optionally, you can use a local interface of the Session Bean, which is slightly less efficient but avoids the RMI and serialization overhead.

–Service components with specific interfaces for different functions work well in many software architectures. Use a standard interface for service-based components in order to enable highly automated front-end components. Choose the generic data structure that best fits your needs for this interface. XML data is the most flexible choice for automated components. However, it performs the worst, especially for large amounts of data. For many cases, a collection of value objects that implement a standard value object interface works well. For simpler architectures that do not involve many hierarchies or collections of objects, an argument list containing name and value pairs can also work quite well.

–Consider the use of a standard interface for service components. This approach enables the reference architecture to automate the invocation of services to a large extent. Services can be generically invoked through their interface, and standard data structures allow for the automated creation of input data. A standard service data structure can be used to store arguments and object data as input as well as the corresponding output data and error information from the service.

–Wrap service components with a stateless Session Bean to manage the transaction and distribute the service. Use a common base class to standardize the service error handling and integration with EJB transaction management. Command pattern logic can be used to easily invoke services implemented as regular Java objects while subclasses using the Template Method pattern can be used in order to have specific EJB deployments of a service.

–If you are going to use straight database queries in your application for performance reasons, mitigate the development risk by externalizing the SQL from the application, isolating the JDBC code in a reusable utility to ensure that resources are properly managed, and mapping the database column names to properties as soon as possible to ease code maintenance.

–Build and use generic, reusable services whenever appropriate to realize the benefits of automation, rapid application development, and increased code quality and maintainability.

–Use a generic MVC, or Model 2, implementation as the foundation for the User Interaction Architecture. The Jakarta Struts project provides an excellent, readily available implementation that you can use for this purpose. This approach automates much of the front-end processing while providing a flexible and extensible foundation to meet all types of application requirements. This also adheres to a key design principle that permeates the reference architecture. This principle is to make the normal case as simple as possible through automation and configuration but give the application the ability to override automated, configurable elements when necessary for complex cases.

–Abstract the HTTP request as a user event to isolate the specific protocol being used from as much of the front-end logic as possible. The user event can then be used to drive the other key abstractions in the controller architecture. These include the action, the service, and the next Web page. By abstracting these key elements of user interaction, a good portion of the front-end processing can be automated and defined through metadata.

–Abstract physical URLs out of the application into metadata in order to enable automation, avoid broken links, and have more maintainable pages.

–Keep the session size fairly small, especially for applications that need to scale to large numbers of users.

–Minimize the amount of actual Java code in a JSP. Large amounts of Java code interspersed with HTML in a JSP can quickly become unreadable and unmanageable. Instead, use custom tags wherever possible to encapsulate presentation logic and integrate with the controller architecture. You can also move logic out to action classes that perform setup work for the page or JavaBeans that are referenced by the page. If you do have scriptlets within the JSP, try to use a few large scriptlets as opposed to interspersing Java code throughout the entire HTML content

–Use a JSP template mechanism to apply a common look and feel to your application Web pages. This approach makes it easy to globally change common aspects of pages and reduces the amount of duplicated code

–Use the Struts template tag library or an analogous mechanism to simplify the development and maintenance of the common aspects of application Web pages. A standard naming scheme can be used to distinguish between JSP components that implement template instances and page content.

–Use the same Template Method pattern within form beans to implement a validate template. This mechanism can reuse much of the property validation and handling logic implemented for use with the business objects. This prevents a duplication of code and effort.

–Consider the use of asynchronous processing to alleviate performance concerns in applications with semi-real-time updates, multiple external applications that can be invoked in parallel, or work that can be partitioned into segments. Use Message-Driven Beans and JMS to implement parallel processing in a J2EE container. Asynchronous processing can also be used to increase the perceived performance of an application.

–Make sure that your software components have easy to use APIs and are well documented. A little JavaDoc can go a long way toward helping someone understand an existing component and feel comfortable reusing it.

–For large, strategically important development projects, use a combination of industry and organizational reuse along with the creativity and innovation of the development team. Each of these sources brings unique value to the table. An approach that combines these aspects will help to alleviate the “not-invented-here” syndrome while at the same time providing a jumpstart to the development effort.

–Add refactoring as an explicit task in iterative software development. This helps not only to increase the overall quality of the software, but it often leads to more robust code that can be harvested into reusable assets.

–Choose a reference architecture and view it as a “reuse” architecture. Use it consistently throughout J2EE development projects. Incorporate standard interaction points for components with known interfaces. Use extensible, configurable components, such as the Jakarta Struts project, as a foundation. Take advantage of standard J2EE implementation models such as JSP custom tags and Session Bean EJB components.

Make sure you are abiding by all the design patterns also. Here are those:

Basic Patterns:
         Interface
        Abstract Parent Class
        Private Methods
        Accessor Methods
        Constant Data Manager
         Immutable Object
        Monitor
Creational Patterns
        Factory Method
        Singleton
        Abstract Factory
        Prototype
        Builder

Collectional Patterns
       Composite
       Iterator
       Flyweight
       Visitor

Structural Patterns
       Decorator
       Adapter
       Chain of Responsibility
       Façade
       Proxy
       Bridge
       Virtual Proxy
       Counting Proxy
       Aggregate Enforcer
       Explicit Object Release
       Object Cache

Behavioral Patterns
       Command
       Mediator
       Memento
       Observer
        Interpreter
       State
       Strategy
       Null Object
       Template Method
       Object Authenticator
       Common Attribute Registry

Concurrency Patterns
       Critical Section
       Consistent Lock Order
       Guarded Suspension
       Read-Write Lock

Posted in Java/J2EE | Tagged: , , , | Comments Off