Tuesday, October 14, 2008

Java Developers sometimes forced/asked to create XML document using any of the available implementations may be from IBM, Oracle, BEA, or SUN reference implementations. Relying on particular implementation which will stop improving the performance by including unwanted classes also in our classpath.

If your requirement is just to create XML document not doing any manipulation below is the sample code which will helps you to created easily the XML document with fully formattedXML.

TWO Java files: - Tag.java, XMLGenerator.java

Tag.java

- which holds the details of how the architecture looks like and how the attribute and elements will be hold and generated the XML string object out of it.

XMLGenerator.java

- Sample program which utilize this Tag generator and creates XML for you.

An application client helps to connect to container resources by referring resources in config xmls. We really not interested in doing all this magic. We know the resource(DataSource/Beans/JMS QUeue/topic) type and the location where it is located.

A JNDI(Java Naming and Directory Interface) name is the reference name specified in container to refer the resource from local and remote.

A J2EE application client is a standalone program launched from the command line or desktop, and typically accesses Enterprise JavaBean programs running on the J2EE application server. In Application client, we have to bundle an application such a way that to access the beans. Please refer for more info J2EE Application Client.

Again this is hectic way of accessing the resources from Application container, then what will I do ?.

yeah, we have the answer for this. Using RMI protocol, we can access any of the Beans/DataSource/Topic/Queue from server.

The following four properties and requesting object executables(classes) in your class path is enough to communicate with server.

The above mentioned properties will vary based on what kind of Application server, we are using. Here, I have taken Oracle 10.1.3 Application server OC4J to explain.

we can specify these properties in either of three approaches

1. Programmatically including these attributes

In this Approach, we have to always pass a Hashtable to create a Initialcontext. That HashTable has to store all these properties and values. Most of the time this approach is not suggested, because of the reason we have to modify these values(hard coded values) or we have to pick from external environment and given to Hash table

3. Specifying in jndi.properties file

Best way of segregating configuration and application is specify these configuration details separately in a proprty file and name it as jndi.properties. This file containing folder has to be included in classpath.

Check java.naming.provider.url is correct or not. If you are accessing beans/topic/queue then you have to specify EJB Application also in this URL. Example, If your EJB Application name is Bank then specify like java.naming.provider.url=ormi://localhost:23791/Bank

In this software world, everything has to be built our own or it has to be opensource code which helps us to tune the performance our application. I was in the need of testing my product which makes more than 100 HTTP request per minute. I initially thought of installing freely available any of the HTTP server. But, none of the HTTPServer comes with the flavour of light weight, everything starts minimum of 10 MB and it needs separate installation which will not be started just like that.

Building a HTTP Server:

We have to have little bit of knowledge about the HTTP protocol. This protocol is nothing but built on top of TCP with specific headers, which leads us to important details easily using some kind of getter method.

To build HTTPServer, we have to know the threading concept with socket programming knowledge. Don't worry, I won't ask you to write the HTTPServer code here, I will share with you full code which is ready to use.

No configuration is required for this server. Just add this class in your classpath and create instance of this Class by passing port number.

Recent Posts

Texts

This blog intended to share the knowledge and contribute to JAVA Community such a way that by providing samples and pointing right documents/webpages. We try to give our knowledege level best and no guarantee can be claimed on truth. Copyright and Terms of Policy refer blogspot.com