| 1 |
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 5 |
<title>Axis Developer's Guide</title> |
| 6 |
<link href="axis.css" rel=stylesheet type=text/css> |
| 7 |
</head> |
| 8 |
<body text="#000000" bgcolor="#FFFFFF"> |
| 9 |
|
| 10 |
<center> |
| 11 |
<h1> |
| 12 |
<img SRC="images/axis.jpg" height=96 width=176></h1></center> |
| 13 |
|
| 14 |
<h1> |
| 15 |
Axis Developer's Guide</h1> |
| 16 |
<i>1.4 Version</i> |
| 17 |
<br><i>Feedback: <a href="mailto:[email protected]">[email protected]</a></i> |
| 18 |
<h3> |
| 19 |
Table of Contents</h3> |
| 20 |
<a href="#Introduction">Introduction</a> |
| 21 |
<br><a href="#General Guidelines">General Guidelines</a> |
| 22 |
<br><a href="#Development Environment">Development Environment</a> |
| 23 |
<br><a href="#Pluggable-Components">Pluggable-Components</a> |
| 24 |
<br> <a href="#Discovery">Discovery</a> |
| 25 |
<br> <a href="#Logging/Tracing">Logging/Tracing</a> |
| 26 |
<br> <a href="#Axis Servlet Query String Plug-ins">Axis Servlet Query String Plug-ins</a> |
| 27 |
<br><a href="#Configuration Properties">Configuration Properties</a> |
| 28 |
<br><a href="#Exception Handling">Exception Handling</a> |
| 29 |
<br><a href="#Compile And Run">Compile and Run</a> |
| 30 |
<br><a href="#Internationalization">Internationalization</a> |
| 31 |
<br> <a href="#Extending Message Files">Extending Message Files</a> |
| 32 |
<br><a href="#Adding Testcases">Adding Testcases</a> |
| 33 |
<br><a href="#TestStructure">Test and Samples Structure</a> |
| 34 |
<br><a href="#CodeChecks">Adding Source Code Checks</a> |
| 35 |
<br><a href="#JUnit">JUnit and Axis</a> |
| 36 |
<br><a href="#Debugging">Debugging</a> |
| 37 |
<br><a href="#TCK">Running the JAX-RPC Compatibility Tests</a> |
| 38 |
<br> |
| 39 |
<h2> |
| 40 |
<a NAME="Introduction"></a>Introduction</h2> |
| 41 |
This guide is a collection of topics related to developing code for Axis. |
| 42 |
<h2> |
| 43 |
<a NAME="General Guidelines"></a>General Guidelines</h2> |
| 44 |
|
| 45 |
<ul> |
| 46 |
<li> |
| 47 |
Axis specific information (svn repository access, mailing list info, etc.) |
| 48 |
can be found on the <a href="http://ws.apache.org/axis/index.html">Axis |
| 49 |
Home Page</a>.</li> |
| 50 |
|
| 51 |
<li> |
| 52 |
Axis uses the <a href="http://jakarta.apache.org/site/guidelines.html">Jakarta |
| 53 |
Project Guidelines.</a></li> |
| 54 |
|
| 55 |
<li> |
| 56 |
Code changes should comply with <a href="http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html">"Code |
| 57 |
Conventions for the Java Programming Language"</a></li> |
| 58 |
|
| 59 |
<li> |
| 60 |
When fixing a <a href="http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Axis&short_desc=&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&order=bugs.bug_id"> |
| 61 |
"Axis Bugzilla Bug"</a> include the href of the |
| 62 |
bug in the svn commit message.</li> |
| 63 |
|
| 64 |
<li> |
| 65 |
Incompatible changes to |
| 66 |
<a href="user-guide.html#published interfaces">published Axis interfaces</a> |
| 67 |
should be avoided where possible. |
| 68 |
When changes are necessary, for example to maintain or improve the overall |
| 69 |
modularity of Axis, the |
| 70 |
impact on users must be considered and, preferably, documented.</li> |
| 71 |
|
| 72 |
<li> |
| 73 |
If you are making a big change that may affect interoperability, please |
| 74 |
run the <a href="http://xml.apache.org/~rubys/echotest.pl">echotest2 round 2 interop test</a> to ensure that your change does not result in any new interop failures. You will also need the <a href="http://xml.apache.org/~rubys/client_deploy.wsdd">client_deploy.wsdd</a>. Here are the <a href="http://xml.apache.org/~rubys/ApacheClientInterop.html">nightly interop test results</a>. |
| 75 |
</ul> |
| 76 |
|
| 77 |
<h2> |
| 78 |
<a NAME="Development Environment"></a>Development Environment</h2> |
| 79 |
The following packages are required for axis development: |
| 80 |
<ul> |
| 81 |
<li> |
| 82 |
<a href="http://jakarta.apache.org/ant/index.html">ant </a>- Java based build tool. <B>Please Note: Version 1.5 OR HIGHER is required</B></li> |
| 83 |
|
| 84 |
<li> |
| 85 |
<a href="http://www.junit.org">junit</a> - testing package</li> |
| 86 |
|
| 87 |
<li> |
| 88 |
<a href="http://xml.apache.org/dist/xerces-j">xerces</a> - xml processor</li> |
| 89 |
|
| 90 |
<li> |
| 91 |
Install Java 1.3.1 JDK (or later).</li> |
| 92 |
</ul> |
| 93 |
|
| 94 |
<p><br>The Axis jar files are built in the <tt>xml-axis/java/build/lib</tt> |
| 95 |
directory. Here is an example CLASSPATH, which I use when developing |
| 96 |
code: |
| 97 |
<blockquote> |
| 98 |
<blockquote><tt><font color="#009900">D:\\xerces\\xerces-1_4_2\\xerces.jar</font></tt> |
| 99 |
<br><tt><font color="#009900">G:\\junit3.7\\junit.jar</font></tt> |
| 100 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\lib\\commons-discovery.jar</font></tt> |
| 101 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\lib\\commons-logging.jar</font></tt> |
| 102 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\lib\\wsdl4j.jar</font></tt> |
| 103 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\lib\\axis.jar</font></tt> |
| 104 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\lib\\log4j-1.2.8.jar</font></tt> |
| 105 |
<br><tt><font color="#009900">G:\\xml-axis\\java\\build\\classes</font></tt></blockquote> |
| 106 |
</blockquote> |
| 107 |
If you access the internet via a proxy server, you'll need to set an environment |
| 108 |
variable so that the Axis tests do the same. Set ANT_OPTS to, for example: |
| 109 |
<blockquote> |
| 110 |
<blockquote><tt><font color="#009900">-Dhttp.proxyHost=proxy.somewhere.com |
| 111 |
-Dhttp.proxyPort=80 -Dhttp.nonProxyHosts="localhost"</font></tt></blockquote> |
| 112 |
</blockquote> |
| 113 |
|
| 114 |
<h2> |
| 115 |
<a NAME="Pluggable-Components"></a>Pluggable-Components</h2> |
| 116 |
The <a href="architecture-guide.html">Axis Architecture Guide</a> |
| 117 |
explains the requirements for pluggable components. |
| 118 |
|
| 119 |
<h3> |
| 120 |
<a NAME="Discovery"></a>Discovery</h3> |
| 121 |
An Axis-specific component factory should be created of the form: |
| 122 |
<ol> |
| 123 |
org.apache.axis.components.<componentType>.<factoryClassName> |
| 124 |
</ol> |
| 125 |
For example, <code>org.apache.axis.components.logger.LogFactory</code> is the factory, |
| 126 |
or discovery mechanism, for the logger component/service. |
| 127 |
<p> |
| 128 |
The <code>org.apache.axis.components.image</code> package demonstrates |
| 129 |
both a factory, and supporting classes for different image tools used |
| 130 |
by Axis. This is representative of a pluggable component that uses |
| 131 |
external tooling, isolating it behind a 'thin' wrapper to Axis that |
| 132 |
provides only a limited interface to meet Axis minimal requirements. |
| 133 |
This allows future designers |
| 134 |
and implementors to gain an explicit understanding of the Axis's |
| 135 |
specific requirements on these tools. |
| 136 |
<h3> |
| 137 |
<a NAME="Logging/Tracing"></a>Logging/Tracing</h3> |
| 138 |
Axis logging and tracing is based on the Logging component of the |
| 139 |
<a href="http://jakarta.apache.org/commons/index.html">Jakarta Commons</a> |
| 140 |
project, or the Jakarta Commons Logging (JCL) SPI. |
| 141 |
The JCL provides a Log interface with thin-wrapper implementations for |
| 142 |
other logging tools, including |
| 143 |
<a href="http://jakarta.apache.org/log4j/docs/index.html">Log4J</a>, |
| 144 |
<a href="http://jakarta.apache.org/avalon/logkit/index.html">Avalon LogKit</a>, |
| 145 |
and |
| 146 |
<a>JDK 1.4</a>. |
| 147 |
The interface maps closely to Log4J and LogKit. |
| 148 |
<h4>Using the Logger SPI</h4> |
| 149 |
<p> |
| 150 |
To use the JCL SPI from a Java class, |
| 151 |
include the following import statements: |
| 152 |
<ul> |
| 153 |
<code> |
| 154 |
import org.apache.commons.logging.Log; |
| 155 |
<br> |
| 156 |
import org.apache.axis.components.logger.LogFactory; |
| 157 |
<br> |
| 158 |
</code> |
| 159 |
</ul> |
| 160 |
For each class definition, declare and initialize a |
| 161 |
<code>log</code> attribute as follows: |
| 162 |
<ul> |
| 163 |
<code> |
| 164 |
public class CLASS |
| 165 |
<br>{ |
| 166 |
<br> private static Log log = LogFactory.getLog(CLASS.class); |
| 167 |
<br> ... |
| 168 |
<br> |
| 169 |
</code> |
| 170 |
</ul> |
| 171 |
<p> |
| 172 |
Messages are logged to a <i>logger</i>, such as <code>log</code> |
| 173 |
by invoking a method corresponding to <i>priority</i>: |
| 174 |
The <code>Log</code> interface defines the following methods for use |
| 175 |
in writing log/trace messages to the log: |
| 176 |
<ul> |
| 177 |
<code> |
| 178 |
log.fatal(Object message); |
| 179 |
<br>log.fatal(Object message, Throwable t); |
| 180 |
<br>log.error(Object message); |
| 181 |
<br>log.error(Object message, Throwable t); |
| 182 |
<br>log.warn(Object message); |
| 183 |
<br>log.warn(Object message, Throwable t); |
| 184 |
<br>log.info(Object message); |
| 185 |
<br>log.info(Object message, Throwable t); |
| 186 |
<br>log.debug(Object message); |
| 187 |
<br>log.debug(Object message, Throwable t); |
| 188 |
<br>log.trace(Object message); |
| 189 |
<br>log.trace(Object message, Throwable t); |
| 190 |
</code> |
| 191 |
</ul> |
| 192 |
While semantics for these methods are ultimately |
| 193 |
defined by the implementation of the Log interface, |
| 194 |
it is expected that the severity of messages is ordered |
| 195 |
as shown in the above list. |
| 196 |
<p> |
| 197 |
In addition to the logging methods, the following are provided: |
| 198 |
<ul> |
| 199 |
<code> |
| 200 |
log.isFatalEnabled(); |
| 201 |
<br>log.isErrorEnabled(); |
| 202 |
<br>log.isWarnEnabled(); |
| 203 |
<br>log.isInfoEnabled(); |
| 204 |
<br>log.isDebugEnabled(); |
| 205 |
<br>log.isTraceEnabled(); |
| 206 |
</code> |
| 207 |
</ul> |
| 208 |
These are typically used to guard code that |
| 209 |
only needs to execute in support of logging, |
| 210 |
and that introduces undesirable runtime overhead |
| 211 |
in the general case (logging disabled). |
| 212 |
|
| 213 |
<h4>Guidelines</h4> |
| 214 |
<h5>Message Priorities</h5> |
| 215 |
It is important to ensure that log message are |
| 216 |
appropriate in content and severity. |
| 217 |
The following guidelines are suggested: |
| 218 |
<ul> |
| 219 |
<li>fatal - Severe errors that cause the Axis server to terminate prematurely. |
| 220 |
Expect these to be immediately visible on a console, |
| 221 |
and MUST be internationalized.</li> |
| 222 |
<br> |
| 223 |
<li>error - Other runtime errors or unexpected conditions. |
| 224 |
Expect these to be immediately visible on a console, |
| 225 |
and MUST be internationalized.</li> |
| 226 |
<br> |
| 227 |
<li>warn - Use of deprecated APIs, poor use of API, Almost errors, other |
| 228 |
runtime situations that are undesirable or unexpected, but not |
| 229 |
necessarily "wrong". |
| 230 |
Expect these to be immediately visible on a console, |
| 231 |
and MUST be internationalized.</li> |
| 232 |
<br> |
| 233 |
<li>info - |
| 234 |
Interesting runtime events (startup/shutdown). |
| 235 |
Expect these to be immediately visible on a console, |
| 236 |
so be conservative and keep to a minimum. |
| 237 |
These MUST be internationalized.</li> |
| 238 |
<br> |
| 239 |
<li>debug - detailed information on flow of through the system. |
| 240 |
Expect these to be written to logs only. |
| 241 |
These NEED NOT be internationalized, but it never hurts...</li> |
| 242 |
<br> |
| 243 |
<li>trace - more detailed information. |
| 244 |
Expect these to be written to logs only. |
| 245 |
These NEED NOT be internationalized, but it never hurts...</li> |
| 246 |
</ul> |
| 247 |
|
| 248 |
<h4><a NAME="Configuring the Logger">Configuring the Logger</a></h4> |
| 249 |
The Jakarta Commons Logging (JCL) SPI |
| 250 |
can be configured to use different logging toolkits. |
| 251 |
To configure which logger is used by the JCL, see the |
| 252 |
<a href="integration-guide.html">Axis System Integration Guide</a>. |
| 253 |
<p> |
| 254 |
Configuration of the behavior of the JCL ultimately depends upon the |
| 255 |
logging toolkit being used. |
| 256 |
The JCL SPI (and hence Axis) uses |
| 257 |
<a href="http://jakarta.apache.org/log4j/docs/index.html">Log4J</a> |
| 258 |
by default if it is available (in the CLASSPATH). |
| 259 |
<h5>Log4J</h5> |
| 260 |
As |
| 261 |
<a href="http://jakarta.apache.org/log4j/docs/index.html">Log4J</a> |
| 262 |
is the prefered/default logger for Axis, |
| 263 |
a <i>few</i> details are presented herein to get the developer going. |
| 264 |
<p> |
| 265 |
Configure Log4J using system properties and/or a properties file: |
| 266 |
<ul> |
| 267 |
<li><strong>log4j.configuration=<i>log4j.properties</i></strong> |
| 268 |
<p> |
| 269 |
Use this system property to specify the name of a Log4J configuration file. |
| 270 |
If not specified, the default configuration file is <i>log4j.properties</i>. |
| 271 |
A <i>log4j.properties</i> file is provided in <code>axis.jar</code>. |
| 272 |
<p>This properties file can sometimes be overridden by placing a file of |
| 273 |
the same name so as to appear before <code>axis.jar</code> in the CLASSPATH. |
| 274 |
However, the precise behaviour depends on the classloader that is in use |
| 275 |
at the time, so we don't recommend this technique. |
| 276 |
<p> |
| 277 |
A safe way of overriding the properties file is to replace it in axis.jar. |
| 278 |
However, this isn't very convenient, especially if you want to tweak the |
| 279 |
properties during a debug session to filter out unwanted log entries. |
| 280 |
A more convenient alternative is to use an absolute file path to specify |
| 281 |
the properties file. This will even ignore web app's and their classloaders. |
| 282 |
So, for example on Linux, you could specify the system property: |
| 283 |
<pre> |
| 284 |
log4j.configuration=file:/home/fred/log4j.props |
| 285 |
</pre> |
| 286 |
</li> |
| 287 |
<li><strong>log4j.debug</strong> |
| 288 |
A good way of telling where log4j is getting its configuration from is to |
| 289 |
set this system property and look at the messages on standard output. |
| 290 |
<br> |
| 291 |
</li> |
| 292 |
<li><strong>log4j.rootCategory=<i>priority</i> [, <i>appender</i>]*</strong> |
| 293 |
Set the default (root) logger priority. |
| 294 |
|
| 295 |
<br> |
| 296 |
</li> |
| 297 |
<li><strong>log4j.logger.<i>logger.name</i>=<i>priority</i></strong> |
| 298 |
Set the priority for the named logger |
| 299 |
and all loggers hierarchically lower than, or below, the |
| 300 |
named logger. |
| 301 |
<i>logger.name</i> corresponds to the parameter of |
| 302 |
<code>LogFactory.getLog(<i>logger.name</i>)</code>, |
| 303 |
used to create the logger instance. Priorities are: |
| 304 |
<code>DEBUG</code>, |
| 305 |
<code>INFO</code>, |
| 306 |
<code>WARN</code>, |
| 307 |
<code>ERROR</code>, |
| 308 |
or <code>FATAL</code>. |
| 309 |
<p> |
| 310 |
Log4J understands hierarchical names, |
| 311 |
enabling control by package or high-level qualifiers: |
| 312 |
<code>log4j.logger.org.apache.axis.encoding=DEBUG</code> |
| 313 |
will enable debug messages for all classes in both |
| 314 |
<code>org.apache.axis.encoding</code> |
| 315 |
and |
| 316 |
<code>org.apache.axis.encoding.ser</code>. |
| 317 |
Likewise, setting |
| 318 |
<code>log4j.logger.org.apache.axis=DEBUG</code> |
| 319 |
will enable debug message for all Axis classes, |
| 320 |
but not for other Jakarta projects. |
| 321 |
<p> |
| 322 |
A combination of settings will enable you to see the log events that |
| 323 |
you are interested in and omit the others. |
| 324 |
For example, the combination: |
| 325 |
<pre> |
| 326 |
log4j.logger.org.apache.axis=DEBUG |
| 327 |
log4j.logger.org.apache.axis.encoding=INFO |
| 328 |
log4j.logger.org.apache.axis.utils=INFO |
| 329 |
log4j.logger.org.apache.axis.message=INFO |
| 330 |
</pre> |
| 331 |
cuts down the number of a log entries produced by a single request to |
| 332 |
a manageable number. |
| 333 |
<br> |
| 334 |
</li> |
| 335 |
<li><strong>log4j.appender.<i>appender</i>.Threshold=<i>priority</i></strong> |
| 336 |
Log4J <i>appenders</i> correspond to different output devices: |
| 337 |
console, files, sockets, and others. |
| 338 |
If appender's <i>threshold</i> |
| 339 |
is less than or equal to the message priority then |
| 340 |
the message is written by that appender. |
| 341 |
This allows different levels of detail to be appear |
| 342 |
at different log destinations. |
| 343 |
<p> |
| 344 |
For example: one can capture DEBUG (and higher) level information in a logfile, |
| 345 |
while limiting console output to INFO (and higher). |
| 346 |
</li> |
| 347 |
</ul> |
| 348 |
<h3> |
| 349 |
<a name="Axis Servlet Query String Plug-ins">Axis Servlet Query String Plug-ins</h3> |
| 350 |
Any servlet that is derived from the <code>org.apache.axis.transport.http.AxisServlet</code> class |
| 351 |
supports a number of standard query strings (<i>?list</i>, <i>?method</i>, and <i>?wsdl</i>) that |
| 352 |
provide information from or perform operations on a web service (for instance, <i>?method</i> is |
| 353 |
used to invoke a method on a web service and <i>?wsdl</i> is used to retrieve the WSDL document for |
| 354 |
a web service). Axis servlets are not limited to these three query strings and developers may |
| 355 |
create their own "plug-ins" by implementing the <code>org.apache.axis.transport.http.QSHandler</code> |
| 356 |
interface. There is one method in this interface that must be implemented, with the following signature: |
| 357 |
<pre> |
| 358 |
public void invoke (MessageContext msgContext) throws AxisFault; |
| 359 |
</pre> |
| 360 |
The <code>org.apache.axis.MessageContext</code> instance provides the developer with a number of useful |
| 361 |
objects (such as the Axis engine instance, and HTTP servlet objects) that are accessible by its |
| 362 |
<code>getProperty</code> method. The following constants can be used to retrieve various objects provided |
| 363 |
by the Axis servlet invoking the query string plug-in: |
| 364 |
<ul> |
| 365 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_NAME</strong><br> |
| 366 |
A <code>String</code> containing the name of the query string plug-in. For instance, if the query string <i>?wsdl</i> is |
| 367 |
provided, the name of the plugin is <i>wsdl</i>. |
| 368 |
<br><br> |
| 369 |
</li> |
| 370 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_SERVICE_NAME</strong><br> |
| 371 |
A <code>String</code> containing the name of the Axis servlet that inovked the query string plug-in. |
| 372 |
<br><br> |
| 373 |
</li> |
| 374 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_IS_DEVELOPMENT</strong><br> |
| 375 |
A <code>Boolean</code> containing <code>true</code> if this version of Axis is considered to be in development |
| 376 |
mode, <code>false</code> otherwise. |
| 377 |
<br><br> |
| 378 |
</li> |
| 379 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_ENABLE_LIST</strong><br> |
| 380 |
A <code>Boolean</code> containing <code>true</code> if listing of the Axis server configuration is allowed, |
| 381 |
<code>false</code> otherwise. |
| 382 |
<br><br> |
| 383 |
</li> |
| 384 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_ENGINE</strong><br> |
| 385 |
A <code>org.apache.axis.server.AxisServer</code> object containing the engine for the Axis server. |
| 386 |
<br><br> |
| 387 |
</li> |
| 388 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST</strong><br> |
| 389 |
The <code>javax.servlet.http.HttpServletRequest</code> object from the Axis servlet that invoked the |
| 390 |
query string plug-in |
| 391 |
<br><br> |
| 392 |
</li> |
| 393 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETRESPONSE</strong><br> |
| 394 |
The <code>javax.servlet.http.HttpServletResponse</code> object from the Axis servlet that invoked the |
| 395 |
query string plug-in |
| 396 |
<br><br> |
| 397 |
</li> |
| 398 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_WRITER</strong><br> |
| 399 |
The <code>java.io.PrintWriter</code> object from the Axis servlet that invoked the |
| 400 |
query string plug-in |
| 401 |
<br><br> |
| 402 |
</li> |
| 403 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_LOG</strong><br> |
| 404 |
The <code>org.apache.commons.logging.Log</code> object from the Axis servlet that invoked the query |
| 405 |
string plug-in, which is used to log messages. |
| 406 |
<br><br> |
| 407 |
</li> |
| 408 |
<li><strong>org.apache.axis.transport.http.HTTPConstants.PLUGIN_EXCEPTION_LOG</strong><br> |
| 409 |
The <code>org.apache.commons.logging.Log</code> object from the Axis servlet that invoked the query |
| 410 |
string plug-in, which is used to log exceptions. |
| 411 |
<br><br> |
| 412 |
</li> |
| 413 |
</ul> |
| 414 |
Query string plug-in development is much like normal servlet development since the same basic |
| 415 |
information and methods of output are available to the developer. Below is an example query string |
| 416 |
plug-in which simply displays the value of the system clock (<code>import</code> statements have been |
| 417 |
omitted for brevity): |
| 418 |
<pre> |
| 419 |
public class QSClockHandler implements QSHandler { |
| 420 |
public void invoke (MessageContext msgContext) throws AxisFault { |
| 421 |
PrintWriter out = (PrintWriter) msgContext.getProperty (HTTPConstants.PLUGIN_WRITER); |
| 422 |
HttpServletResponse response = (HttpServletResponse) msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLETRESPONSE); |
| 423 |
|
| 424 |
response.setContentType ("text/html"); |
| 425 |
|
| 426 |
out.println ("<HTML><BODY><H1>" + System.currentTimeMillis() + "</H1></BODY></HTML>"); |
| 427 |
} |
| 428 |
} |
| 429 |
</pre> |
| 430 |
Once a query string plug-in class has been created, the Axis server must be set up to recognize the |
| 431 |
query string which invokes it. See the section <a href="reference.html#Deployment">Deployment (WSDD) Reference</a> in the |
| 432 |
<a href="reference.html">Axis Reference Guide</a> for information on how the HTTP transport section of the Axis server configuration |
| 433 |
file must be set up. |
| 434 |
|
| 435 |
|
| 436 |
<h2> |
| 437 |
<a NAME="Configuration Properties"></a>Configuration Properties</h2> |
| 438 |
Axis is in the process of moving away from using system properties |
| 439 |
as the primary point of internal configuration. |
| 440 |
Avoid calling <code>System.getProperty()</code>, |
| 441 |
and instead call <code>AxisProperties.getProperty</code>. |
| 442 |
<code>AxisProperties.getProperty</code> will |
| 443 |
call <code>System.getProperty</code>, and will (eventually) |
| 444 |
query other sources of configuration information. |
| 445 |
<p> |
| 446 |
Using this central point of access will allow the |
| 447 |
global configuration system to be redesigned |
| 448 |
to better support multiple Axis engines in a |
| 449 |
single JVM. |
| 450 |
|
| 451 |
<h2> |
| 452 |
<a NAME="Exception Handling"></a>Exception Handling</h2> |
| 453 |
Guidelines for Axis exception handling are based on best-practices |
| 454 |
for exception handling. |
| 455 |
While there are details specific to Axis in these guidelines, |
| 456 |
they apply in principle to any project; |
| 457 |
they are included here for two reasons. |
| 458 |
First, because they are not listed elsewhere in the |
| 459 |
Apache/Jakarta guidelines (or haven't been found). |
| 460 |
Second, because adherence to these guidelines is |
| 461 |
considered crucial to enterprise ready middleware. |
| 462 |
<p> |
| 463 |
These guidelines are fundamentally independent of programming language. |
| 464 |
They are based on experience, but proper credit must be given to |
| 465 |
<i>More Effective C++</i>, by Scott Meyers, |
| 466 |
for opening the eyes of the innocent(?) many years ago. |
| 467 |
<p> |
| 468 |
Finally, these are guidelines. |
| 469 |
There will always be exceptions to these guidelines, |
| 470 |
in which case all that can be asked (as per these guidelines) |
| 471 |
is that they be logged in the form of comments in the code. |
| 472 |
<p> |
| 473 |
<ul> |
| 474 |
<li><h3>Primary Rule: Only Catch An Exception If You Know What To Do With It</h3></li> |
| 475 |
If code catches an exception, it should know what to do with it |
| 476 |
at that point in the program. |
| 477 |
Any exception to this rule must be documented with a GOOD reason. |
| 478 |
Code reviewers are invited to put on their vulture beaks and peck away... |
| 479 |
<p> |
| 480 |
There are a few corrollaries to this rule. |
| 481 |
<p> |
| 482 |
<ul> |
| 483 |
<li><h4>Handle Specific Exceptions in Inner Code</h4></li> |
| 484 |
Inner code is code <i>deep</i> within the program. |
| 485 |
Such code should catch specific exceptions, |
| 486 |
or categories of exceptions (parents in exception hierarchies), |
| 487 |
<u>if and only if</u> the exception can be resolved |
| 488 |
and normal flow restored to the code. |
| 489 |
Note that behaviour of this sort may be significantly |
| 490 |
different between non-interactive code versus an interactive tool. |
| 491 |
<p> |
| 492 |
<li><h4>Catch All Exceptions in Outermost Flow of Control</h4></li> |
| 493 |
Ultimately, all exceptions must be dealt with at one level or another. |
| 494 |
For command-line tools, this means the <code>main</code> |
| 495 |
method or program. |
| 496 |
For a middleware component, this is the entry point(s) into the component. |
| 497 |
For Axis this is <code>AxisServlet</code> or equivalent. |
| 498 |
<p> |
| 499 |
After catching specific exceptions which can be resolved internally, |
| 500 |
the outermost code must ensure that all internally generated exceptions |
| 501 |
are caught and handled. |
| 502 |
While there is generally not much that can be done, |
| 503 |
at a minimum the code should <u>log the exception</u>. |
| 504 |
In addition to logging, the Axis Server wraps all such exceptions |
| 505 |
in AxisFaults and returns them |
| 506 |
to the client code. |
| 507 |
<p> |
| 508 |
This may seem contrary to the primary rule, |
| 509 |
but in fact we are claiming that Axis does know |
| 510 |
what to do with this type of exception: |
| 511 |
exit gracefully. |
| 512 |
</ul> |
| 513 |
<p> |
| 514 |
<li><h3>Catching and Logging Exceptions</h3></li> |
| 515 |
When an Exception is going to cross a component boundry |
| 516 |
(client/server, or system/business logic), |
| 517 |
the exception must be caught and logged by the |
| 518 |
throwing component. |
| 519 |
It may then be rethrown, or wrapped, as described below. |
| 520 |
<p> |
| 521 |
When in doubt, log the exception. |
| 522 |
<p> |
| 523 |
<ul> |
| 524 |
<li><h4>Catch and Throw</h4></li> |
| 525 |
If an exception is caught and rethrown (unresolved), |
| 526 |
logging of the exception is at the discretion of the coder and reviewers. |
| 527 |
If any comments are logged, the exception should also be logged. |
| 528 |
<p> |
| 529 |
When in doubt, log the exception and any related local information |
| 530 |
that can help to identify the complete context of the exception. |
| 531 |
<p> |
| 532 |
Log the exception as an <i>error</i> (<code>log.error()</code>) |
| 533 |
if it is known to be an unresolved or unresolvable error, |
| 534 |
otherwise log it at the <i>informative</i> level (<code>log.info()</code>). |
| 535 |
<p> |
| 536 |
<li><h4>Catch and Wrap</h4></li> |
| 537 |
When exception <code>e</code> is caught and wrapped |
| 538 |
by a new exception <code>w</code>, |
| 539 |
log exception <code>e</code> before throwing <code>w</code>. |
| 540 |
<p> |
| 541 |
Log the exception as an <i>error</i> (<code>log.error()</code>) |
| 542 |
if it is known to be an unresolved or unresolvable error, |
| 543 |
otherwise log it at the <i>informative</i> level (<code>log.info()</code>). |
| 544 |
<p> |
| 545 |
<li><h4>Catch and Resolve</h4></li> |
| 546 |
When exception <code>e</code> is caught and resolved, |
| 547 |
logging of the exception is at the discretion of the coder and reviewers. |
| 548 |
If any comments are logged, the exception should also be logged (<code>log.info()</code>). |
| 549 |
Issues that must be balanced are performance and problem resolvability. |
| 550 |
<p> |
| 551 |
Note that in many cases, ignoring the exception may be appropriate. |
| 552 |
<p> |
| 553 |
</ul> |
| 554 |
<li><h3>Respect Component Boundries</h3></li> |
| 555 |
There are multiple aspects of this guideline. |
| 556 |
On one hand, this means that business logic |
| 557 |
should be isolated from system logic. |
| 558 |
On the other hand, this means that |
| 559 |
client's should have limited exposure/visibility to |
| 560 |
implementation details of a server - particularly |
| 561 |
when the server is published to outside parties. |
| 562 |
This implies a well designed server interface. |
| 563 |
<p> |
| 564 |
<ul> |
| 565 |
<li><h4>Isolate System Logic from Business Logic</h4></li> |
| 566 |
Exceptions generated by the Axis runtime |
| 567 |
should be handled, where possible, |
| 568 |
within the Axis runtime. |
| 569 |
In the worst case the details of an exception are to be logged |
| 570 |
by the Axis runtime, |
| 571 |
and a generally descriptive Exception raised to the Business Logic. |
| 572 |
<p> |
| 573 |
Exceptions raised in the business logic |
| 574 |
(this includes the server and Axis handlers) |
| 575 |
must be delivered to the client code. |
| 576 |
<p> |
| 577 |
<li><h4>Protect System Code from User Code</h4></li> |
| 578 |
Protect the Axis runtime from uncontrolled user business logic. |
| 579 |
For Axis, this means that dynamically configurable |
| 580 |
<code>handlers</code>, <code>providers</code> and other |
| 581 |
user controllable hook-points must be guarded |
| 582 |
by <code>catch(Exception ...)</code>. |
| 583 |
Exceptions generated by user code and caught by system code should be: |
| 584 |
<ul> |
| 585 |
<li>Logged, and</li> |
| 586 |
<li>Delivered to the client program</li> |
| 587 |
</ul> |
| 588 |
<p> |
| 589 |
<li><h4>Isolate Visibility into Server from Client</h4></li> |
| 590 |
Specific exceptions should be logged at the server side, |
| 591 |
and a more general exception thrown to the client. |
| 592 |
This prevents clues as to the nature of the server |
| 593 |
(such as handlers, providers, etc) |
| 594 |
from being revealed to client code. |
| 595 |
The Axis component boundries that should be respected are: |
| 596 |
<ul> |
| 597 |
<li>Client Code <--> AxisClient</li> |
| 598 |
<li>AxisClient <--> AxisServlet (AxisServer/AxisEngine)</li> |
| 599 |
<li>AxisServer/AxisEngine <--> Web Service</li> |
| 600 |
</ul> |
| 601 |
</ul> |
| 602 |
<p> |
| 603 |
<li><h3>Throwing Exceptions in Constructors</h3></li> |
| 604 |
Before throwing an exception in a constructor, |
| 605 |
ensure that any resources owned by the object are cleaned up. |
| 606 |
For objects holding resources, |
| 607 |
this requires catching <u>all</u> exceptions thrown by methods called |
| 608 |
within the constructor, cleaning up, and rethrowing the exceptions. |
| 609 |
<p> |
| 610 |
</ul> |
| 611 |
</ul> |
| 612 |
|
| 613 |
<h2> |
| 614 |
<a NAME="Compile And Run"></a>Compile and Run</h2> |
| 615 |
The <tt>xml-axis/java/build.xml</tt> file is the primary 'make' file used |
| 616 |
by ant to build the application and run the tests. The <tt>build.xml</tt> |
| 617 |
file defines ant build <i>targets</i>. Read the build.xml file for |
| 618 |
more information. Here are some of the useful targets: |
| 619 |
<br> |
| 620 |
<ul> |
| 621 |
<li> |
| 622 |
<tt>compile -> compiles the source and creates xml-axis/java/build/lib/axis.jar</tt></li> |
| 623 |
|
| 624 |
<li> |
| 625 |
<tt>javadocs -> creates the javadocs in xml-axis/java/build/javadocs</tt></li> |
| 626 |
|
| 627 |
<li> |
| 628 |
<tt>functional-tests -> compiles and runs the functional tests</tt></li> |
| 629 |
|
| 630 |
<li> |
| 631 |
<tt>all-tests -> compiles and runs all of the tests</tt></li> |
| 632 |
|
| 633 |
<br> </ul> |
| 634 |
To compile the source code: |
| 635 |
<blockquote><tt>cd xml-axis/java</tt> |
| 636 |
<br><tt>ant compile</tt></blockquote> |
| 637 |
To run the tests: |
| 638 |
<blockquote><tt>cd xml-axis/java</tt> |
| 639 |
<br><tt>ant functional-tests</tt></blockquote> |
| 640 |
<b>Note: </b>these tests start a server on port 8080. If this clashes with |
| 641 |
the port used by your web application server (such as Tomcat), you'll need |
| 642 |
to change one of the ports or stop your web application server when running |
| 643 |
the tests. |
| 644 |
<p><b>Please run <tt><font color="#009900">ant functional-tests</font></tt> |
| 645 |
and <tt><font color="#009900">ant all-tests</font></tt> before checking |
| 646 |
in new code.</b> |
| 647 |
<h2> |
| 648 |
<a NAME="Internationalization"></a>Internationalization</h2> |
| 649 |
If you make changes to the source code that results in the generation of |
| 650 |
text (error messages or debug information), you must follow the following |
| 651 |
guidelines to ensure that your text is properly translated. |
| 652 |
<h3> |
| 653 |
<a NAME="Developer Guidelines"></a>Developer Guidelines</h3> |
| 654 |
<ol> |
| 655 |
<li> |
| 656 |
Your text string should be added as a property to the resource.properties |
| 657 |
file (xml-axis/java/src/org/apache/axis/i18n/resource.properties). |
| 658 |
Note that some of the utility applications (i.e. tcpmon) have their own |
| 659 |
resource property files (tcpmon.properties). |
| 660 |
</li> |
| 661 |
<br> |
| 662 |
<li> |
| 663 |
The resource.properties file contains translation and usage instructions. |
| 664 |
Entries in a message resource file are of the form |
| 665 |
<font color="#009900"><key>=<message></font>. |
| 666 |
Here is an example message:</li> |
| 667 |
<p> |
| 668 |
<p><font color="#009900">sample00=My name is {0}, and my title is {1}.</font> |
| 669 |
<br> |
| 670 |
<ol> |
| 671 |
<li> |
| 672 |
sample00 is the key that the code will use to access this message.</li> |
| 673 |
<li> |
| 674 |
The text after the = is the message text.</li> |
| 675 |
<li> |
| 676 |
The <font color="#009900">{<i>number</i>}</font> syntax defines the location |
| 677 |
for inserts.</li> |
| 678 |
<p> |
| 679 |
</ol> |
| 680 |
<li> |
| 681 |
The code should use the |
| 682 |
static method org.apache.axis.i18n.Messages.getMessage |
| 683 |
to obtain the text and add inserts. Here is an example usage:</li> |
| 684 |
<p> |
| 685 |
<p><font color="#009900">Messages.getMessage("sample00", "Rich Scheuerle", |
| 686 |
"Software Developer");</font> |
| 687 |
|
| 688 |
<br> |
| 689 |
<li> |
| 690 |
<font color="#000000">All keys in the properties file should use the syntax |
| 691 |
<string><2-digit-suffix>.</font></li> |
| 692 |
|
| 693 |
<br> |
| 694 |
<ol> |
| 695 |
<li> |
| 696 |
<font color="#000000"><b>Never change the message text in the properties |
| 697 |
file. </b>The message may be used in multiple places in the code. |
| 698 |
Plus translation is only done on new keys.</font></li> |
| 699 |
|
| 700 |
<br> |
| 701 |
<li> |
| 702 |
<font color="#000000">If a code change requires a change to a message, |
| 703 |
create a new entry with an incremented 2-digit suffix.</font></li> |
| 704 |
|
| 705 |
<br> |
| 706 |
<li> |
| 707 |
<font color="#000000">All new entries should be placed at the bottom of |
| 708 |
the file to ease translation.</font></li> |
| 709 |
|
| 710 |
<br> |
| 711 |
<li> |
| 712 |
<font color="#000000">We may occasionally want to trim the properties file of old data, but this should only be done on major releases. </font></li> |
| 713 |
</ol> |
| 714 |
</ol> |
| 715 |
|
| 716 |
<h4> |
| 717 |
<a NAME="Example"></a>Example</h4> |
| 718 |
|
| 719 |
Consider the following statement: |
| 720 |
<p><code> |
| 721 |
if ( operationName == null )</code> |
| 722 |
<br><code> |
| 723 |
throw new AxisFault( "No operation name specified" );</code> |
| 724 |
<p> |
| 725 |
We will add an entry into |
| 726 |
org/apache/axis/i18n/resource.properties: |
| 727 |
<p><code> noOperation=No operation name specified.</code> |
| 728 |
<p>And change the code to read: |
| 729 |
<p><code> |
| 730 |
if ( operationName == null )</code> |
| 731 |
<br><code> |
| 732 |
throw new AxisFault(Messages.getMessage("noOperation"));</code> |
| 733 |
|
| 734 |
<h3> |
| 735 |
<a NAME="Interface"></a>Interface</h3> |
| 736 |
|
| 737 |
Axis uses the standard Java internationalization class |
| 738 |
<code>java.util.ResourceBundle</code> |
| 739 |
to access property files and message strings, |
| 740 |
and uses <code>java.text.MessageFormat</code> |
| 741 |
to format the strings using variables. |
| 742 |
Axis provides a single class <code>org.apache.axis.i18n.Messages</code> |
| 743 |
that manages both ResourceBundle and MessageFormat classes. |
| 744 |
Messages methods are: |
| 745 |
|
| 746 |
<p><code>public static java.util.ResourceBundle getResourceBundle();</code> |
| 747 |
<p><code>public static String getMessage(String key) throws java.util.MissingResourceException;</code> |
| 748 |
<p><code>public static String getMessage(String key, String var) throws java.util.MissingResourceException;</code> |
| 749 |
<p><code>public static String getMessage(String key, String var1, String var2) throws java.util.MissingResourceException;</code> |
| 750 |
<p><code>public static String getMessage(String key, String[] vars) throws java.util.MissingResourceException;</code> |
| 751 |
|
| 752 |
<p>Axis programmers can work with the resource bundle directly via a call |
| 753 |
to <code>Messages.getResourceBundle()</code>, |
| 754 |
but the <code>getMessage()</code> |
| 755 |
methods should be used instead for two reasons: |
| 756 |
<ol> |
| 757 |
<li> |
| 758 |
It's a shortcut. It is cleaner to call</li> |
| 759 |
|
| 760 |
<ol><code>Messages.getMessage("myMsg00");</code></ol> |
| 761 |
than |
| 762 |
<ol><code>Messages.getResourceBundle().getString("myMsg00");</code></ol> |
| 763 |
|
| 764 |
<br> |
| 765 |
<li> |
| 766 |
The <code>getMessage</code> methods enable messages with variables.</li> |
| 767 |
</ol> |
| 768 |
|
| 769 |
<h4> |
| 770 |
The getMessage methods</h4> |
| 771 |
If you have a message with no variables |
| 772 |
<ol><code>myMsg00=This is a string.</code></ol> |
| 773 |
then simply call |
| 774 |
<ol><code>Messages.getMessage("myMsg00");</code></ol> |
| 775 |
|
| 776 |
<p><br>If you have a message with variables, use the syntax |
| 777 |
<font face="Courier New,Courier">"{X}"</font> |
| 778 |
where <code>X</code> is |
| 779 |
the number of the variable, starting at 0. For example: |
| 780 |
<ol><code>myMsg00=My {0} is {1}.</code></ol> |
| 781 |
then call: |
| 782 |
<ol><code>Messages.getMessage("myMsg00","name", "Russell");</code></ol> |
| 783 |
and the resulting string will be: "My name is Russell." |
| 784 |
<p>You could also call the String array version of <font face="Courier New,Courier"><font size=-1>getMessage</font></font>: |
| 785 |
<ol><code>Messages.getMessage("myMsg00", new String[] {"name", "Russell"});</code></ol> |
| 786 |
|
| 787 |
<p><br>The String array version of <font face="Courier New,Courier"><font size=-1>getMessage</font></font> |
| 788 |
is all that is necessary, but the vast majority of messages will have 0, |
| 789 |
1 or 2 variables, so the other <font face="Courier New,Courier"><font size=-1>getMessage</font></font> |
| 790 |
methods are provided as a convenience to avoid the complexity of the String |
| 791 |
array version. |
| 792 |
<p>Note that the <font face="Courier New,Courier"><font size=-1>getMessage</font></font> |
| 793 |
methods throw <font face="Courier New,Courier"><font size=-1>MissingResourceException</font></font> |
| 794 |
if the resource cannot be found. And ParseException if there are |
| 795 |
more {X} entries than arguments. These exceptions are <font face="Courier New,Courier"><font size=-1>RuntimeException'</font></font>s, |
| 796 |
so the caller doesn't have to explicitly catch them. |
| 797 |
<p>The resource bundle properties file is org/apache/axis/i18n/resource.properties. |
| 798 |
|
| 799 |
<h3> |
| 800 |
<a NAME="Extending Message Files"></a>Extending Message Files</h3> |
| 801 |
Generally, |
| 802 |
within Axis all messages are placed in |
| 803 |
org.apache.axis.i18n.resource.properties. |
| 804 |
There are facilities for extending the messages without |
| 805 |
modifying this file for integration or 3rd party extensions to Axis. |
| 806 |
See the <a href="integration-guide.html#Extending Message Files"/>Integration Guide</a> for details. |
| 807 |
|
| 808 |
<h2> |
| 809 |
<a NAME="Adding Testcases"></a><font color="#000000">Adding Testcases</font></h2> |
| 810 |
<P>See Also: <a href="#TestStructure">Test and Samples Structure</a></P> |
| 811 |
<font color="#000000"><b>Editor's Note: </b>We need more effort to streamline |
| 812 |
and simplify the addition of tests. We also need to think about categorizing |
| 813 |
tests as the test bucket grows.</font> |
| 814 |
<br> |
| 815 |
<p><font color="#000000">If you make changes to Axis, please add a test |
| 816 |
that uses your change. Why?</font> |
| 817 |
<ul> |
| 818 |
<li> |
| 819 |
<font color="#000000">The test validates that your new code works.</font></li> |
| 820 |
|
| 821 |
<li> |
| 822 |
<font color="#000000">The test protects your change from bugs introduced |
| 823 |
by future code changes.</font></li> |
| 824 |
|
| 825 |
<li> |
| 826 |
<font color="#000000">The test is an example to users of the features of |
| 827 |
Axis.</font></li> |
| 828 |
|
| 829 |
<li> |
| 830 |
<font color="#000000">The test can be used as a starting point for new |
| 831 |
development.</font></li> |
| 832 |
</ul> |
| 833 |
|
| 834 |
<p><br><font color="#000000">Some general principles:</font> |
| 835 |
<ul> |
| 836 |
<li> |
| 837 |
<font color="#000000">Tests should be self-explanatory.</font></li> |
| 838 |
|
| 839 |
<li> |
| 840 |
<font color="#000000">Tests should not generate an abundance of output</font></li> |
| 841 |
|
| 842 |
<li> |
| 843 |
<font color="#000000">Tests should hook into the existing junit framework.</font></li> |
| 844 |
|
| 845 |
<li> |
| 846 |
<font color="#000000">Each test or group of related tests should have its |
| 847 |
own directory in the <tt>xml-axis/java/test</tt> directory</font></li> |
| 848 |
</ul> |
| 849 |
|
| 850 |
<p><br><font color="#000000">One way to build a test is to "cut and paste" |
| 851 |
and existing tests, and then modify the test to suit your needs. |
| 852 |
This approach is becoming more complicated as the different kinds of tests |
| 853 |
grow.</font> |
| 854 |
<P> |
| 855 |
A good "non-wsdl" test for reference is test/saaj. |
| 856 |
</P> |
| 857 |
<h4> |
| 858 |
<font color="#000000">Creating a WSDL Test</font></h4> |
| 859 |
<font color="#000000">Here are the steps that I used to create the <tt>sequence</tt> |
| 860 |
test, which generates code from a wsdl file and runs a sequence validation |
| 861 |
test:</font> |
| 862 |
<br> |
| 863 |
<ol> |
| 864 |
<li> |
| 865 |
<font color="#000000">Created a <tt>xml-axis/java/test/wsdl/sequence</tt> |
| 866 |
directory.</font></li> |
| 867 |
|
| 868 |
<br> |
| 869 |
<li> |
| 870 |
<font color="#000000">Created a <tt>SequenceTest.wsdl</tt> file defining |
| 871 |
the webservice.</font></li> |
| 872 |
<BR> |
| 873 |
<li> |
| 874 |
<font color="#000000">Ran the Wsdl2java emitter to create Java files:</font></li> |
| 875 |
<p><tt><font color="#993366">java org.apache.axis.wsdl.Wsdl2java -t -s |
| 876 |
SequenceTest.wsdl</font></tt> |
| 877 |
<br> |
| 878 |
<ol> |
| 879 |
<li> |
| 880 |
<font color="#000000">The -t option causes the emitter to generate a *TestCase.java |
| 881 |
file that hooks into the test harness. This file is operational without |
| 882 |
any additional changes. Copy the *TestCase.java file into the same |
| 883 |
directory as your wsdl file. (Ideally only the Java files that are |
| 884 |
changed need to be in your directory. So this file is not needed, |
| 885 |
but please make sure to modify your <wsdl2java ...> clause (described |
| 886 |
below) to emit a testcase.</font></li> |
| 887 |
<li> |
| 888 |
<font color="#000000">The -s option causes the emitter to generate a *SOAPBindingImpl.java |
| 889 |
file. The Java file contains empty methods for the service. |
| 890 |
You probably want to fill them in with your own logic. Copy the *SOAPBindingImpl.java |
| 891 |
file into the same directory as your wsdl file. (If no changes are |
| 892 |
needed in the Java file, you don't need to save it. But you will |
| 893 |
need to make sure that your <wsdl2java ...> clause generates a skeleton).</font></li> |
| 894 |
<li> |
| 895 |
<font color="#000000">Remove all of the Java files that don't require modification. |
| 896 |
So you should have three files in your directory (wsdl file, *TestCase.java, |
| 897 |
and *SOAPBindingImpl.java). My sequence test has an another file |
| 898 |
due to some additional logic that I needed.</font></li> |
| 899 |
</ol> |
| 900 |
<tt><font color="#993366"></font></tt> |
| 901 |
<BR> |
| 902 |
<li> |
| 903 |
<font color="#000000">The <tt>test/wsdl/sequence/build.xml</tt> file |
| 904 |
controls the building of this test. Locate the "compile" target. |
| 905 |
Add a clause that runs the Wsdl2java code. I would recommend stealing something from the |
| 906 |
test/wsdl/roundtrip/build.xml file (it does a LOT of wsdl2java and java2wsdl calls). |
| 907 |
Here is the one for SequenceTest:</font></li> |
| 908 |
<p><tt><font color="#663366"> </font><font color="#993366"><!-- |
| 909 |
Sequence Test --></font></tt> |
| 910 |
<br><tt><font color="#993366"> <wsdl2java url="${axis.home}/test/wsdl/sequence/SequenceTest.wsdl"</font></tt> |
| 911 |
<br><tt><font color="#993366"> |
| 912 |
output="${axis.home}/build/work"</font></tt> |
| 913 |
<br><tt><font color="#993366"> |
| 914 |
deployscope="session"</font></tt> |
| 915 |
<br><tt><font color="#993366"> |
| 916 |
skeleton="yes"</font></tt> |
| 917 |
<br><tt><font color="#993366"> |
| 918 |
messagecontext="no"</font></tt> |
| 919 |
<br><tt><font color="#993366"> |
| 920 |
noimports="no"</font></tt> |
| 921 |
<br><tt><font color="#993366"> |
| 922 |
verbose="no"</font></tt> |
| 923 |
<br><tt><font color="#993366"> |
| 924 |
testcase="no"></font></tt> |
| 925 |
<br><tt><font color="#993366"> |
| 926 |
<mapping namespace="urn:SequenceTest2" package="test.wsdl.sequence"/></font></tt> |
| 927 |
<br><tt><font color="#993366"> </wsdl2java></font></tt> |
| 928 |
<br> |
| 929 |
<li> |
| 930 |
<font color="#000000">Enable the <font color="#993366">run</font><font color="#000000"> target in the new |
| 931 |
build.xml file.</font> You need to choose from the execute-Component and the (soon to be introduced) |
| 932 |
execute-Simple-Test target. These control HOW the test is invoked when run as a single component. |
| 933 |
The <font color="#993366">execute-Component</font> sets up the tcp-server and http-server prior to running the test, as |
| 934 |
well as handles deploying and services that may be needed. The <font color="#993366">execute-Simple-test</font> |
| 935 |
simply invokes the raw test class file.<BR> |
| 936 |
<BR> |
| 937 |
<li> |
| 938 |
<font color="#000000">Done. Run </font><tt><font color="#993366">ant |
| 939 |
functional-tests</font><font color="#000000"> </font></tt><font color="#000000">to |
| 940 |
verify. Check in your test.</font></li> |
| 941 |
|
| 942 |
<br> </ol> |
| 943 |
|
| 944 |
<h2><a NAME="TestStructure"></a>Test Structure</H2> |
| 945 |
<a href="AxisTestRedesign.html">The Test and Samples Redesign Document is here</a><BR> |
| 946 |
<P> |
| 947 |
As of Axis 1.0, RC1, we have moved to a "componentized" test structure. Instead of having one high-level large |
| 948 |
recursive function, there are smaller, simple "component" build.xml files in the leaf level of the test/** and |
| 949 |
samples/** trees.</P> |
| 950 |
<P> |
| 951 |
These "component" files have a common layout. Their primary targets are:<BR> |
| 952 |
<UL> |
| 953 |
<LI>clean - reset the build destination(s) |
| 954 |
<LI>compile - javac, wsdl2java, java2wsdl instructions |
| 955 |
<LI>run - "executes" the test |
| 956 |
</UL> |
| 957 |
</P> |
| 958 |
<P>A "sample" test xml file can be found in test/templateTest</P> |
| 959 |
<h2> |
| 960 |
<a NAME="CodeChecks"></a>Adding Source Code Checks</h2> |
| 961 |
The Axis build performs certain automated checks of the files in the |
| 962 |
source directory (java/src) to make sure certain conventions are |
| 963 |
followed such as using internationalised strings when issuing messages. |
| 964 |
<p> |
| 965 |
If a convention can be reduced to a regular expression match, |
| 966 |
it can be enforced at build time by updating |
| 967 |
java/test/utils/TestSrcContent.java. |
| 968 |
<p> |
| 969 |
All that is necessary is to add a pattern to the static FileNameContentPattern |
| 970 |
array. |
| 971 |
Each pattern has three parameters: |
| 972 |
<ol> |
| 973 |
<li>a pattern that matches filenames that are to be checked,</li> |
| 974 |
<li>a pattern to be searched for in the chosen files, and</li> |
| 975 |
<li>a boolean indicating whether the pattern is to be allowed |
| 976 |
(typically false indicating not allowed).</li> |
| 977 |
</ol> |
| 978 |
<p> |
| 979 |
A reasonable summary of the regular expression notation is provided in |
| 980 |
the <a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html">Jakarta ORO javadocs</a>. |
| 981 |
|
| 982 |
<h2> |
| 983 |
<a NAME="JUnit"></a>JUnit and Axis</h2> |
| 984 |
|
| 985 |
<p> |
| 986 |
You try to run some JUnit tests on an Axis client that invokes a web service, |
| 987 |
and you always get this exception: |
| 988 |
<pre> |
| 989 |
java.lang.ExceptionInInitializerError |
| 990 |
at org.apache.axis.client.Service.<init>(Service.java:108) |
| 991 |
... |
| 992 |
|
| 993 |
Caused by: org.apache.commons.logging.LogConfigurationException: ... |
| 994 |
org.apache.commons.logging.impl.Jdk14Logger does not implement Log |
| 995 |
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance |
| 996 |
(LogFactoryImpl.java:555) |
| 997 |
... |
| 998 |
</pre> |
| 999 |
<p> |
| 1000 |
Actually, the Jdk14Logger does implement Log. What you have is a JUnit classloading |
| 1001 |
issue. JUnit's graphical TestRunner has a feature where it will dynamically |
| 1002 |
reload modified classes every time the user presses the "Run" button. This way, |
| 1003 |
the user doesn't need to relaunch the TestRunner after every edit. For this, |
| 1004 |
JUnit uses its own classloader, junit.runner.TestCaseClassLoader. As of JUnit |
| 1005 |
3.8.1, confusion can arise between TestCaseClassLoader and the system class |
| 1006 |
loader as to which loader did or should load which classes. |
| 1007 |
<p> |
| 1008 |
There are two ways to avoid this problem. |
| 1009 |
<ul> |
| 1010 |
<li>Sure and simple fix. Turn off dynamic class reloading by running |
| 1011 |
junit.swingui.TestRunner with the -noloading argument. |
| 1012 |
</li> |
| 1013 |
<p> |
| 1014 |
<li>Finicky and fancy fix, only necessary if you want dynamic class reloading. |
| 1015 |
Tell TestCaseClassLoader to ignore certain packages and their sub-packages, |
| 1016 |
deferring them to the system classloader. You can do this using a file located |
| 1017 |
in junit.jar, junit/runner/excluded.properties. Its content appears as follows: |
| 1018 |
<pre> |
| 1019 |
# |
| 1020 |
# The list of excluded package paths for the TestCaseClassLoader |
| 1021 |
# |
| 1022 |
excluded.0=sun.* |
| 1023 |
excluded.1=com.sun.* |
| 1024 |
excluded.2=org.omg.* |
| 1025 |
excluded.3=javax.* |
| 1026 |
excluded.4=sunw.* |
| 1027 |
excluded.5=java.* |
| 1028 |
excluded.6=org.w3c.dom.* |
| 1029 |
excluded.7=org.xml.sax.* |
| 1030 |
excluded.8=net.jini.* |
| 1031 |
</pre></li> |
| 1032 |
</ul> |
| 1033 |
<p> |
| 1034 |
Copy this file, preserving the directory path, into another location, e.g. |
| 1035 |
deployDir. So the copied properties file's path will be |
| 1036 |
deployDir/junit/runner/excluded.properties. Add an extra entry to the end of |
| 1037 |
this file: |
| 1038 |
<pre> |
| 1039 |
excluded.9=org.apache.* |
| 1040 |
</pre> |
| 1041 |
<p> |
| 1042 |
Edit your classpath so that deployDir appears before junit.jar. This way, the |
| 1043 |
modified excluded.properties will be used, rather than the default. (Don't add |
| 1044 |
the path to excluded.properties itself to the classpath.) |
| 1045 |
<p> |
| 1046 |
This fix will prevent the commons-logging exception. However, other |
| 1047 |
classloading problems might still arise. For example: |
| 1048 |
<pre> |
| 1049 |
Dec 10, 2002 7:16:16 PM org.apache.axis.encoding.ser.BeanPropertyTarget set |
| 1050 |
SEVERE: Could not convert [Lfoo.bar.Child; to bean field 'childrenAsArray', |
| 1051 |
type [Lfoo.bar.Child; |
| 1052 |
Dec 10, 2002 7:16:16 PM org.apache.axis.client.Call invoke |
| 1053 |
SEVERE: Exception: |
| 1054 |
java.lang.IllegalArgumentException: argument type mismatch |
| 1055 |
at org.apache.axis.encoding.ser.BeanPropertyTarget.set |
| 1056 |
(BeanPropertyTarget.java:182) |
| 1057 |
at org.apache.axis.encoding.DeserializerImpl.valueComplete |
| 1058 |
(DeserializerImpl.java:284) |
| 1059 |
... |
| 1060 |
</pre> |
| 1061 |
<p> |
| 1062 |
In this case, you have no choice but to give up on dynamic class reloading and |
| 1063 |
use the -noloading argument. |
| 1064 |
<p> |
| 1065 |
One other heads-up about JUnit testing of an Axis web service. Suppose you have |
| 1066 |
run JUnit tests locally on the component that you want to expose as a web |
| 1067 |
service. You press the "Run" button to initiate a series of tests. Between each |
| 1068 |
test, all your data structures are re-initialized. Your tests produce a long |
| 1069 |
green bar. Good. |
| 1070 |
<p> |
| 1071 |
Suppose you now want to run JUnit tests on an Axis client that is connecting to |
| 1072 |
an application server running the Axis web application and with it your web |
| 1073 |
service. Between each test, JUnit will automatically re-initialize your client. |
| 1074 |
<p> |
| 1075 |
Your server-side data structures are a different matter. If you're checking |
| 1076 |
your server data at the end of each test (as you should be) and you run more |
| 1077 |
than one test at a time, the second and later tests will fail because they are |
| 1078 |
generating cumulative data on the Axis server based on preceding tests rather |
| 1079 |
than fresh data based only on the current one. |
| 1080 |
<p> |
| 1081 |
This means that, for each test, you must manually re-initialize your web |
| 1082 |
service. One way to accomplish this is to add to your web service interface a |
| 1083 |
re-initialize operation. Then have the client call that operation at the start |
| 1084 |
of each test. |
| 1085 |
|
| 1086 |
|
| 1087 |
<h2> |
| 1088 |
<a NAME="Debugging"></a>Debugging</h2> |
| 1089 |
|
| 1090 |
<h4>Using <code>tcpmon</code> to Monitor Functional Tests.</h4> |
| 1091 |
<p> |
| 1092 |
Here is an easy way to monitor the messages while running |
| 1093 |
<code>functional-tests</code> (or <code>all-tests</code>). |
| 1094 |
<br>Start up tcpmon listening on 8080 and forwarding to a different port: |
| 1095 |
<blockquote><tt>java org.apache.axis.utils.tcpmon 8080 localhost 8011</tt></blockquote> |
| 1096 |
Run your tests, but use the forwarded port for the SimpleAxisServer, and |
| 1097 |
indicate that functional-tests should continue if a failure occurs. |
| 1098 |
<blockquote><tt>ant functional-tests -Dtest.functional.SimpleAxisPort=8011 |
| 1099 |
-Dtest.functional.fail=no</tt></blockquote> |
| 1100 |
The SOAP messages for all of the tests should appear in the tcpmon window. |
| 1101 |
<p> |
| 1102 |
<code>tcpmon</code> is described in more detail in the |
| 1103 |
<a href="user-guide.html#tcpmon">Axis User's Guide</a>. |
| 1104 |
|
| 1105 |
<h4>Using <code>SOAP Monitor</code> to Monitor Functional Tests.</h4> |
| 1106 |
<p> |
| 1107 |
If you are debugging code that is running as a web application using |
| 1108 |
a web application server (such as Tomcat) then you may also use the |
| 1109 |
SOAP Monitor utility to view the SOAP request and response messages. |
| 1110 |
<br>Start up the SOAP monitor utility by loading the SOAP monitor applet |
| 1111 |
in your web browser window: |
| 1112 |
<blockquote><tt>http://localhost:<port>/axis/SOAPMonitor</tt></blockquote>. |
| 1113 |
As you run your tests, the SOAP messages should appear in the SOAP |
| 1114 |
monitor window. |
| 1115 |
<p> |
| 1116 |
<code>SOAP Monitor</code> is described in more detail in the |
| 1117 |
<a href="user-guide.html#soapmon">Axis User's Guide</a>. |
| 1118 |
|
| 1119 |
<h4>Running a Single Functional Test</h4> |
| 1120 |
In one window start the server: |
| 1121 |
<br> |
| 1122 |
<blockquote><tt>java org.apache.axis.transport.http.SimpleAxisServer -p 8080</tt></blockquote> |
| 1123 |
In another window, first deploy the service you're testing: |
| 1124 |
<blockquote><tt>java org.apache.axis.client.AdminClient deploy.wsdd</tt></blockquote> |
| 1125 |
Then bring up the JUnit user interface with your test. For example, to run the the multithread test case: |
| 1126 |
<blockquote><tt>java junit.swingui.TestRunner -noloading test.wsdl.multithread.MultithreadTestCase</tt></blockquote> |
| 1127 |
|
| 1128 |
<h4>Turning on Debug Output</h4> |
| 1129 |
This section is oriented to the Axis default logger: Log4J. |
| 1130 |
For additional information on Log4J, see the section |
| 1131 |
<a href="#Configuring the Logger">Configuring the Logger</a>. |
| 1132 |
<p> |
| 1133 |
<ul> |
| 1134 |
<li><h5>Overriding Log4J properties</h5></li> |
| 1135 |
The <code>log4j.properties</code> file |
| 1136 |
is packaged in <code>axis.jar</code> with reasonable |
| 1137 |
default settings. |
| 1138 |
Subsequent items presume changes to these settings. |
| 1139 |
There are multiple options open to the developer, |
| 1140 |
most of which involve |
| 1141 |
extracting <code>log4j.properties</code> from <code>axis.jar</code> |
| 1142 |
and modifying as appropriate. |
| 1143 |
<ul> |
| 1144 |
<p> |
| 1145 |
<li> |
| 1146 |
If you are building and executing <code>Java</code> programs from |
| 1147 |
a command line or script file, |
| 1148 |
include the JVM option |
| 1149 |
<code>-Dlog4j.configuration=<i>yourConfigFile</i></code>. |
| 1150 |
</li> |
| 1151 |
<p> |
| 1152 |
<li> |
| 1153 |
Set <code>CLASSPATH</code> such that |
| 1154 |
your version of <code>log4j.properties</code> appears |
| 1155 |
prior to <code>axis.jar</code> in the <code>CLASSPATH</code>. |
| 1156 |
</li> |
| 1157 |
<p> |
| 1158 |
<li> |
| 1159 |
If you are building and executing your programs using <code>ant</code> |
| 1160 |
(this includes building Axis and running it's tests), |
| 1161 |
set the environment variable <code>ANT_OPTS</code> to <code>-Dlog4j.configuration=<i>yourConfigFile</i></code>. |
| 1162 |
</li> |
| 1163 |
<p> |
| 1164 |
<li> |
| 1165 |
If you are building Axis, you can change <code>src/log4j.properties</code> |
| 1166 |
directly. Be sure NOT to commit your change(s). |
| 1167 |
</li> |
| 1168 |
</ul> |
| 1169 |
|
| 1170 |
<br> |
| 1171 |
<li><h5>Turning on ALL DEBUG Output</h5></li> |
| 1172 |
<ul> |
| 1173 |
<li> |
| 1174 |
Set the <code>log4j.rootCategory</code> <i>priority</i> to |
| 1175 |
<code>DEBUG</code>. |
| 1176 |
</li> |
| 1177 |
<p> |
| 1178 |
<li> |
| 1179 |
Set the <i>priority</i> threshold for an appender to <code>DEBUG</code> |
| 1180 |
(The <code>log4j.properties</code> file in Axis defines two appenders: |
| 1181 |
<code>CONSOLE</code> and <code>LOGFILE</code>). |
| 1182 |
</li> |
| 1183 |
</ul> |
| 1184 |
|
| 1185 |
<br> |
| 1186 |
<li><h5>Selective DEBUG Output</h5></li> |
| 1187 |
<ul> |
| 1188 |
<li> |
| 1189 |
Set the <code>log4j.rootCategory</code> <i>priority</i> to |
| 1190 |
<code>INFO</code> or higher. |
| 1191 |
</li> |
| 1192 |
<p> |
| 1193 |
<li> |
| 1194 |
Set the <code>log4j.logger.<i>logger.name</i></code> <i>priority</i> to |
| 1195 |
<code>DEBUG</code> for the loggers that you are interested in. |
| 1196 |
</li> |
| 1197 |
<p> |
| 1198 |
<li> |
| 1199 |
Set the <i>priority</i> threshold for an appender to <code>DEBUG</code> |
| 1200 |
(The <code>log4j.properties</code> file in Axis defines two appenders: |
| 1201 |
<code>CONSOLE</code> and <code>LOGFILE</code>). |
| 1202 |
</li> |
| 1203 |
<p> |
| 1204 |
<li> |
| 1205 |
If you are still seeing more than you want to see, |
| 1206 |
you will need to use other tools to extract the information |
| 1207 |
you are interested in from the log output. |
| 1208 |
Use appropriate key words in log messages |
| 1209 |
and use tools such as <code>grep</code> to |
| 1210 |
search for them in log messages. |
| 1211 |
</li> |
| 1212 |
</ul> |
| 1213 |
</ul> |
| 1214 |
|
| 1215 |
<h4>Writing Temporary Output</h4> |
| 1216 |
Remember that Axis is targeted for use in a number |
| 1217 |
of open-source and other web applications, |
| 1218 |
and so it needs to be a good citizen. |
| 1219 |
Writing output using <code>System.out.println</code> or |
| 1220 |
<code>System.err.println</code> |
| 1221 |
should be avoided. |
| 1222 |
<p> |
| 1223 |
Developers may be tempted to use <code>System.out.println</code> |
| 1224 |
while debugging or analyzing a system. |
| 1225 |
If you choose to do this, you will need to disable the |
| 1226 |
<code>util/TestSrcContent</code> test, |
| 1227 |
which enforces avoidance of |
| 1228 |
<code>System.out.println</code> and <code>System.err.println</code>. |
| 1229 |
It follows that you will need to remove your statements |
| 1230 |
before checking the code back in. |
| 1231 |
<p> |
| 1232 |
As an alternative, |
| 1233 |
we strongly encourage you to |
| 1234 |
take a few moments and introduce debug statements: |
| 1235 |
<code>log.debug("reasonably terse and meaningful message")</code>. |
| 1236 |
If a debug message is useful for understanding a problem now, |
| 1237 |
it may be useful again in the future to you or a peer. |
| 1238 |
|
| 1239 |
<h2> |
| 1240 |
<a NAME="TCK"></a>Running the JAX-RPC Compatibility Tests</h2> |
| 1241 |
As well as a specification, JAX-RPC has a Technology Compatibility Kit (TCK) |
| 1242 |
which is available to members of the JAX-RPC Expert Group (and others?). |
| 1243 |
<p> |
| 1244 |
The kit comes as a zip file which you should unzip into a directory of your |
| 1245 |
choosing. |
| 1246 |
The installation instructions are in the JAX-RPC Release Notes document which |
| 1247 |
is stored in the docs directory. |
| 1248 |
If you open the index.html file in the docs directory using a web browser, |
| 1249 |
you'll see a list of all the documents supplied with the kit. |
| 1250 |
<p> |
| 1251 |
Note that the kit includes the JavaTest test harness which is used for running |
| 1252 |
the compatibility tests. |
| 1253 |
<p> |
| 1254 |
If any more information is needed about running these tests, please add |
| 1255 |
it here! |
| 1256 |
</body> |
| 1257 |
</html> |