Very Simple Object Access Protocol with Java
To begin with, I would like to make a few necessary remarks about topics that will be discussed in this article and about the minimal level of knowledge the reader should have. The topics are in the title of article—we will talk about SOAP technology, and will try to explain it as quickly and easily as possible, and, it goes without saying, we will include the usual "Hello World!" example to show the reader what it looks like. To my mind, it is always harder to start learning new technology if you have only the official documentation, with huge examples, explaining all the features and advantages, but doesn't explain what it looks like. In this article, I'm not supposed just to be able to explain SOAP technology superficially, but whether it will turn out—clearly. Nevertheless, from our side, we will assume that the reader is familiar with the Java language, Web technologies, and (better, much better!) with the XML language, basics of XML Namespaces, and XML Schema. In this case, there should be no difficulties in understanding any part of this material. Although, even without such knowledge, we will explain everything as simply as possible, but you will get in trouble when you will start doing your own SOAP applications. So, it is a good idea to spend some time learning them.
From a technical standpoint, it is necessary to mention that we are using the Windows XP OS with Java 2 SDK 1.4.1, Apache SOAP 2.3.1, JAF 1.0.2, JavaMail 1.3.1, and Xerces 2.6.0. Everything mentioned above works properly with the Tomcat 4.1.29 JSP/Servlet container. All software is free, so you can easily download it and install for yourself, on any platform you like—Windows or UNIX. Java SDK, JAF, and JavaMail are located on Sun Microsystems' official site, http://java.sun.com, and everything else is on the Jakarta project's official site, http://jakarta.apache.org. Probably you already became a bit nervous once you saw how many different packages we need, but in reality you should not be afraid of this. It's rather easy once you understand the basics properly. Installation is not a hard thing; you just need to be very careful when setting your environment variables, such as (for example) CATALINA_HOME, CLASSPATH, JAVA_HOME, and so forth. All these tricks are in manuals; I just would like to concentrate your attention on them once again, so you will pass with this process as quickly as possible. I've just added the next few strings into Tomcat's bin/setclasspath.bat:
... set CATALINA_HOME=C:\Tomcat4.1.29 set CLASSPATH=%JAVA_HOME%\lib\tools.jar set CLASSPATH=%JAVA_HOME%\soap-2.3.1\lib\soap.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\javamail-1.3.1\mail.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\jaf-1.0.2\activation.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xercesImpl.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xercesSamples.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xml-apis.jar set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\xerces-2_6_0\xmlParserAPIs.jar set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\common\lib\servlet.jar set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\common\lib\tools.jar ...
You need to correct them in case your installation paths are not the same as those used above, shut down, and restart Tomcat. Then, you will have everything ready to work with SOAP. But for now, I would like to forget about the technical part, and learn a bit of theory information.
SOAP means Simple Object Access Protocol. Strangely enough, it is really simple. It is the protocol based on XML that allows program components and applications to interact with each other, using a standard Internet protocol—HTTP. SOAP is an independent platform, it does not depend on the programming language, and it is simple, flexible, and easily expandable. Nowadays, applications can interact with each other using Remote Procedure Calls (RPC) that are based on the DCOM and CORBA technologies, but HTTP was not projected for these purposes. RPC is too difficult to adapt for the Internet. They represent a number of the problems connected to compatibility and safety because firewalls and proxy servers usually block the given kind of the traffic. The best kind of interaction between applications is the use of HTTP because HTTP is supported by all Internet browsers and servers. SOAP was created to achieve the same purposes.
So, what does everything look like? For example, one application (A) needs to interact with another application (B) with the help of SOAP. They will interact using the following scheme:
The SOAP envelope is an XML document that consists of the following parts:
As you can see, it's pretty simple; it looks exactly like a normal letter or any of your e-mail. Do you want to see it in action? Here we go! We are a few steps away from creating and running our own "Hello World" application with SOAP, but because we are going to keep it very simple, I would like to show you the scheme of how it will work.
Our "Hello World" example will consist of a SOAP Service to which our SOAP Client will send its name and try to get some answer. This SOAP Service will need to be deployed with a SOAP Admin Tool, so that the SOAP (Proxy) RPC Router that will redirect all requests will know with which service it should work. In general, this will looks like that:
Page 1 of 2