Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Java Thread Dump Analyser


understand thread dumps by looking at a thread dump

Java Thread Dump Analyser is a tool for quickly summarizing lengthy Java thread dumps.
This tool groups threads together which have the same stack trace and allows you to only show threads which are in particular states (e.g. RUNNABLE or BLOCKED).
This makes it a bit quicker to find the interesting threads amongst the tens or hundreds of JBoss threads which spend most of their time waiting for work at the same place in the code and therefore all have the same stack trace
A Java thread dump is a way of finding out what every thread in the JVM is doing at a particular point in time. This is especially useful if your Java application sometimes seems to hang when running under load, as an analysis of the dump will show where the threads are stuck.
You can generate a thread dump under Unix/Linux by running kill -QUIT <pid>, and under Windows by hitting Ctl + Break.
To make it easier to understand the contents of a Java thread dump you can use the Java Thread Dump Analyser. All you have to do is copy/paste your thread dump text into the input tab and press the Analyse button.

Threadanalyser

Here is an example of the output which is generated.
2011-08-19 17:46:25
Full thread dump Java HotSpot(TM) Client VM (20.0-b11 mixed mode, sharing):
As the name suggests thread dump is a dump of all the threads in a Java virtual machine. It contains the current execution state of both application and the JVM specific threads. The above thread dump snippet shows two application threads [Thread-0 and Thread-1] and JVM specific threads such as “Signal Dispatcher”, “Finalizer” etc. For the purpose of this article we will focus only on application threads.
Thread dumps are extremely useful in the following situations
  • To get a holistic view of what is happening in the application at that particular moment
  • To expose glaring issues such as
  • portions of code which seem to be invoked almost always
  • portions of code where the application seems to be hung
  • locking and thread synchronization issues in an application
  • Additionally they are invaluable in production environments where sophisticated profiling tools cannot be easily attached
Format of thread dumps
The format of thread dump has been changing with JSE versions. Sun or any other vendors inform users that the format will change between versions. However one thing which hasn’t changed is the level of information contained in a thread dump. As mentioned above thread dumps is a snapshot of the JVM state listing all the application and system level threads and monitor states.
Full thread dump Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode, sharing):
"Thread-1" prio=5 tid=0x00a995d0 nid=0x1300 in Object.wait() [0x02d0f000..0x02d0fb68]
at java.lang.Object.wait(Native Method)
- waiting on <0x22aaa8d0> (a org.tw.testyard.thread.Drop)
at java.lang.Object.wait(Unknown Source)
at org.tw.testyard.thread.Drop.take(Drop.java:14)
- locked <0x22aaa8d0> (a org.tw.testyard.thread.Drop)
at org.tw.testyard.thread.Consumer.run(Consumer.java:15)
at java.lang.Thread.run(Unknown Source)
"Thread-0" prio=5 tid=0x00a88440 nid=0x6a4 waiting on condition [0x02ccf000..0x02ccfbe8]
at java.lang.Thread.sleep(Native Method)
at org.tw.testyard.thread.Producer.run(Producer.java:24)
at java.lang.Thread.run(Unknown Source)
In the thread dump snippet above you can observe the following
  • The thread dump starts with “Full thread dump”, followed by a list of threads currently being executed.
  • There are 2 application threads called Thread-1 and Thread-0. These are the default names which the JVM handed over to the threads.
  • “Thread-1″ is waiting for a notification after it called Object.wait() on the Drop object.
  • Similarly, “Thread-0″ is sleeping on a condition after it called Thread.sleep
  • At this particular instant, there are no threads in the runnable state and hence the application isn’t doing any real work.
Although thread dumps also lists the state of the system threads we are not going to look deeper into system threads.
How to take thread dumps
Thread dumps can be generated by the users as well as the system in unusual situations. The users can generate thread dumps by explicitly sending a signal to the JVM or programatically by calling java.lang.Exception.printStackTrace(). Calling printStackTrace() method will only cause the stack trace of the current thread to be printed.
On windows environment thread dumps can only be generated when the process is running in the fore ground and is associated with a command line console. Thread dumps can be generated by hitting the key combination Ctrl + \ (Back slash). On unix / linux enviroments thread dumps can be generated by the command kill -QUIT <process id of jvm> or kill -3 <process id of jvm>. Thread dumps are generally logged to the stderr. Depending on your start up commands you may find the thread dumps in some other log files. Please consult your system administrator for details. Taking thread dumps by either of the 2 strategies doesnt cause the application to terminate, the JVM dumps the execution state and continues.
Although very rare the JVM can also generate a thread dump when a thread causes the JVM to crash. The amount of information which gets logged is again implementation specific. Typically you will find information about the thread which caused the JVM to crash.

Webservices and API

Webservices and — Javamazon:

Webservices and API

An API is an Application Programming Interface, it's the means by which third parties can write code that interfaces with other code. A Web Service is a type of API, almost always one that operates over HTTP (Though some, like SOAP, can use alternate transports, like SMTP). The Official W3C Definition mentions that Web Services don't necessarily use HTTP, but this is almost always the case and is usually assumed unless otherwise mentioned.

For examples of web services specifically see SOAP, REST, and XML-RPC.

As an example of another type of API, one written in C for use on a local machine, see the Linux Kernel API
As far as protocol goes, a Webservice API almost always uses HTTP (hence the Web part), and definitely involves communication over a network. APIs in general can use any means of communication they wish. The Linux kernel API for example uses Interrupts to invoke the system calls that comprise its API for calls from userspace.
Webservice is a method of communication between two machines while an API is an exposed layer allowing you to program against something.

You could very well have an API and the main method of interacting with that API is via a webservice. API is code based integration while web service is message based integration with interoperable standards having a contract such as WSDL.

The technical definitions (courtesy of Wikipedia) are:

 API
An application programming interface (API) is a set of routines, data structures, object classes and/or protocols provided by libraries and/or operating system services in order to support the building of applications.

 Webservice
 A Web service (also Web Service) is defined by the W3C as "a software system designed to support interoperable machine-to-machine interaction over a network"

Example 1 :
API's are a published interface which defines how component A communicates with component B.

For example, Doubleclick have a published Java API which allows users to interrogate the database tables to get information about their online advertising campaign.

e.g. call GetNumberClicks (user name)

To implement the API, you have to add the Doubleclick .jar file to your class path. The call is local.

A web service is a form of API where the interface is defined by means of a WSDL. This allows remote calling of an interface over HTTP.

If Doubleclick implemented their interface as a web service, they would use something like Axis2 running inside Tomcat.The remote user would call the web service

e.g. call GetNumberClicksWebService (user name)

and the GetNumberClicksWebService service would call GetNumberClicks locally.

Example 2:

API(Application Programming Interface), the full form itself suggests that its an Interface which allows you to program for your application with the help or support of some other Application's Interface which exposes some sort of functionality which is useful to your application.

E.g showing updated currency exchange rates on your website would need some third party Interface to program against unless you plan to have your own database with currency rates and regular updates to the same. This set of functionality is when already available with some one else and when they want to share it with others they have to have an endpoint to communicate with the others who are interested in such interactions so they deploy it on web by the means of web-services. This end point is nothing but interface of their application which you can program against hence API.

another example: google map api vs google direction api web service, while the former serves (delivers) javascript file to the site (which can then be used as an api to make new functions) , the later is a Rest web service delivering data (in json or xml format), which can be processed (but not used in an api sense).

set up basic Hibernate development environment

Below are the recommended steps in getting started with Hibernate

Setting up the development environment
  • Make sure the appropriate JDK is installed. Hibernate Core 3.6 requires JDK 1.5 or higher (3.5 requires JDK 1.4 or higher).
  • Make sure an appropriate Maven version is installed. At the time of this writing, that means Maven >= 2.0.8. This is not strictly a requirement to use Hibernate, but would be needed to build Hibernate. If you wish to follow along with the tutorials as outlined below, they provide Maven poms to get up and running easily.
Download the latest production release of Hibernate from the Hibernate website at http://www.hibernate.org/ or http://sourceforge.net/projects/hibernate/files/hibernate3/ and unpack the archive after download





Historically, Hibernate facilitated the storage and retrieval of Java domain objects via Object/Relational Mapping. Today, Hibernate is a collection of related projects enabling developers to utilize POJO-style domain models in their applications in ways extending well beyond Object/Relational Mapping.

JBoss Application, Web and SOA platform


JBoss Enterprise Application Platform

JBoss Enterprise Application Platform is the market leading platform for innovative and scalable Java applications. Integrated, simplified, and delivered by the leader in enterprise open source software, it includes leading open source technologies for building, deploying, and hosting enterprise Java applications and services.

JBoss Enterprise Application Platform balances innovation with enterprise class stability by integrating the most popular clustered Java EE application server with next generation application frameworks. Built on open standards, JBoss Enterprise Application Platform integrates JBoss Application Server, with JBoss Hibernate, JBoss Seam, and other leading open source Java technologies from JBoss.org into a complete, simple enterprise solution for Java applications.

Features and Benefits



JBoss Enterprise Web Platform

JBoss Enterprise Web Platform is the ideal solution for light and rich Java applications. Based on Java standards, JBoss Enterprise Web Platform enhances the Java EE Web Profile with enterprise features to provide a flexible platform specifically targeted for lightweight Java applications.

JBoss Enterprise Web Platform is a lighter & slimmer version of JBoss Enterprise Application Platform 5, Red Hat’s solution for full Java EE enterprise applications. Web Platform leverages a slimmed down profile of the JBoss AS, the worlds most popular open source Java application server, and integrates poplar open source frameworks Hibernate, Seam along with JBoss Web Framework Kit to provide an integrated platform form for next generation, standards-based Java applications.

JBoss Enterprise Web Platform is a simple and flexible solution for lightweight Java applications, delivered by the leader in enterprise open source software.


Features and Benefits




JBoss Enterprise SOA Platform


The leaner, faster, more flexible way to integrate applications, services and data.

Why JBoss Enterprise SOA Platform?

JBoss Enterprise SOA Platform (JBoss SOA-P), our next-generation enterprise service bus (ESB) and business process automation (BPA) infrastructure, drives superior business execution, responsiveness, and flexibility in a cost-effective, open platform. It delivers an easy-to-consume SOA integration suite that lets you build, deploy, integrate, orchestrate, and present applications and services


Benefits & Features






Web Services- SOAP,WSDL,UDDI with EBook


Web Services- SOAP,WSDL,UDDI with EBook


Web services can convert your applications into web-applications.web servicesare published, found, and used through the web. By using web services, your application can publish its function or message to the rest of the world.web services use xml to code and to decode data, and soap to transport it using open protocols.
  • Web services are application components
  • Web services communicate using open protocols
  • Web services are self-contained and self-describing
  • Web services can be discovered using UDDI
  • Web services can be used by other applications
  • XML is the basis for Web services
  • Basic Web services platform is XML + HTTP
Web services platform elements includes:
  • SOAP (Simple Object Access Protocol)
  • UDDI (Universal Description, Discovery and Integration)
  • WSDL (Web Services Description Language)
What is SOAP?
SOAP is an XML-based protocol to let applications exchange information over HTTP.
Or more simple: SOAP is a protocol for accessing a Web Service.
  • SOAP stands for Simple Object Access Protocol
  • SOAP is a communication protocol
  • SOAP is a format for sending messages
  • SOAP is designed to communicate via Internet
  • SOAP is platform independent
  • SOAP is language independent
  • SOAP is based on XML
  • SOAP is simple and extensible
  • SOAP allows you to get around firewalls
  • SOAP is a W3C standard
Here are some important syntax rules:
  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope namespace
  • A SOAP message MUST use the SOAP Encoding namespace
  • A SOAP message must NOT contain a DTD reference
  • A SOAP message must NOT contain XML Processing Instructions
What is WSDL?
WSDL is an XML-based language for locating and describing Web services.
  • WSDL stands for Web Services Description Language
  • WSDL is based on XML
  • WSDL is used to describe Web services
  • WSDL is used to locate Web services
  • WSDL is a W3C standard
What is UDDI?
UDDI is a directory service where companies can register and search for Web services.
  • UDDI stands for Universal Description, Discovery and Integration
  • UDDI is a directory for storing information about web services
  • UDDI is a directory of web service interfaces described by WSDL
  • UDDI communicates via SOAP
  • UDDI is built into the Microsoft .NET platform
SOAP Building Blocks
A SOAP message is an ordinary XML document containing the followingelements:
  • An Envelope element that identifies the XML document as a SOAP message
  • A Header element that contains header information
  • A Body element that contains call and response information
  • A Fault element containing errors and status information
  • Skeleton SOAP Message
<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Header>

</soap:Header><soap:Body>

<soap:Fault>

</soap:Fault>
</soap:Body></soap:Envelope>

The SOAP Envelope Element

The required SOAP Envelope element is the root element of a SOAP message. This element defines the XML document as a SOAP message.

Example

<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”>

Message information goes here

</soap:Envelope>

The xmlns:soap Namespace

Notice the xmlns:soap namespace in the example above. It should always have the value of: “http://www.w3.org/2001/12/soap-envelope”.If a different namespace is used, the application generates an error and discards the message.

The encodingStyle Attribute

The encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and applies to the element’s contents and all child elements.

Syntax

soap:encodingStyle=”URI

Example

<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”>

Message information goes here

</soap:Envelope>
The SOAP Header element contains header information.

The SOAP Header Element

The optional SOAP Header element contains application-specific information (like authentication, payment, etc) about the SOAP message.
If the Header element is present, it must be the first child element of theEnvelope element.
<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Header>
<m:Trans xmlns:m=”http://www.javamazon.com/transaction/”
soap:mustUnderstand=”1″>234
</m:Trans>
</soap:Header>


</soap:Envelope>
The example above contains a header with a “Trans” element, a “mustUnderstand” attribute with a value of 1, and a value of 234.
The attributes defined in the SOAP Header defines how a recipient should process the SOAP message.

The mustUnderstand Attribute

The SOAP mustUnderstand attribute can be used to indicate whether a header entry is mandatory or optional for the recipient to process.
If you add mustUnderstand=”1″ to a child element of the Header element it indicates that the receiver processing the Header must recognize the element. If the receiver does not recognize the element it will fail when processing the Header.

Syntax

soap:mustUnderstand=”0|1″

Example

<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Header>
<m:Trans xmlns:m=”http://www.javamazon.com/transaction/”
soap:mustUnderstand=”1″>234
</m:Trans>
</soap:Header>


</soap:Envelope>

The actor Attribute
A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path. However, not all parts of a SOAP message may be intended for the ultimate endpoint, instead, it may be intended for one or more of the endpoints on the message path.
The SOAP actor attribute is used to address the Header element to a specific endpoint.

Syntax

soap:actor=”URI

Example

<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Header>
<m:Trans xmlns:m=”http://www.javamazon.com/transaction/”
soap:actor=”http://www.javamazon.com/appml/”>234
</m:Trans>
</soap:Header>


</soap:Envelope>

The encodingStyle Attribute
The encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and it will apply to that element’s contents and all child elements.
A SOAP message has no default encoding.

Syntax

soap:encodingStyle=”URI

The SOAP Body Element

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.
Immediate child elements of the SOAP Body element may be namespace-qualified.

Example

<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Body>
<m:GetBooks xmlns:m=”http://www.javamazon.com/prices”>
<m:Item>ANDROID</m:Item>
</m:GetBooks>
</soap:Body></soap:Envelope>
The example above requests the price of apples. Note that the m:GetPrice and the Item elements above are application-specific elements. They are not a part of the SOAP namespace.
A SOAP response could look something like this:
<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Body>
<m:GetBooksResponse xmlns:m=”http://www.javamazon.com/prices”>
<m:Price>39.0</m:Price>
</m:GetBooksResponse>
</soap:Body></soap:Envelope>

The SOAP Fault Element

The optional SOAP Fault element is used to indicate error messages.
If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message.
The SOAP Fault element has the following sub elements:
Sub ElementDescription
<faultcode>A code for identifying the fault
<faultstring>A human readable explanation of the fault
<faultactor>Information about who caused the fault to happen
<detail>Holds application specific error information related to the Body element

SOAP Fault Codes

The faultcode values defined below must be used in the faultcode element when describing faults:
ErrorDescription
VersionMismatchFound an invalid namespace for the SOAP Envelopeelement
MustUnderstandAn immediate child element of the Header element, with the mustUnderstand attribute set to “1″, was not understood
ClientThe message was incorrectly formed or contained incorrect information
ServerThere was a problem with the server so the message could not proceed

A SOAP Example

In the example below, a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter that will be returned in the response. The namespace for the function is defined in “http://www.example.org/stock”.

A SOAP request:

POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Body xmlns:m=”http://www.example.org/stock”>
<m:GetText>
<m:RText>SMS</m:RText>
</m:GetText>
</soap:Body></soap:Envelope>

The SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn<?xml version=”1.0″?>
<soap:Envelope
xmlns:soap=”http://www.w3.org/2001/12/soap-envelope”
soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”><soap:Body xmlns:m=”http://www.example.org/stock”>
<m:GetTextResponse>
<m:RText>Honey</m:RText>
</m:GetTextResponse>
</soap:Body></soap:Envelope>
Below is the Video Tutorial on how to create a Web Service