Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Web Service Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

8.3 Further Options

The previous example describes the general procedure for implementing a service. This section discusses some of the issues you may need to consider to create a production quality server.

8.3.1 Multithreading

The Agent creates threads as necessary to handle incoming requests, and multiple threads may enter a servlet at the same time. Objects supplied as parameters to the overridden virtual methods are guaranteed to be active in only a single thread. However, if the servlet maintains state, it must take appropriate precautions to ensure thread safety. See Section 7.5, "Recovering Session State," in the HydraExpress Servlet Development Guide for details.

8.3.1.1 A Note on Allocating Objects in Multithreaded Applications

Because services created with HydraExpress run in multiple threads, it is recommended that you allocate objects on the heap rather than the stack, a general "best practice" for multithreaded applications. This prevents problems with thread stack size.

8.3.2 Service Security

To run a secure service, the client must communicate with the service through an HTTPS transport. Any HydraExpress client can use the HTTPS transport supplied with HydraExpress.

To test a secure client against a Web service running in the Agent, just include in the WSDL or client implementation the path to the default port used for security, 8443, such as:

For an example of creating a secure service, see Chapter 4, "Extending Your Web Service."


Using the HTTPS protocol results in a dependence on the OpenSSL third-party library.

8.3.3 Error Reporting and WSDL-Defined Faults

HydraExpress handles server and client exceptions through rwsf::Exception or one of its derived classes, and SOAP faults through an instance of rwsf::SoapFaultException or one of its generated derivations if a fault is specified in the WSDL file.

A WSDL file can define faults to be caught in the server and returned to the client. One or more faults may be defined for each operation defined in the WSDL. HydraExpress creates a class for each unique fault message type defined. Several faults can use the same message format, so messages are the critical definition needed by HydraExpress to create a mechanism for returning faults to the client.

If faults are defined in the WSDL, the server-side implementation code can detect problems and report them back to the client by throwing one of the defined fault messages.


This discussion reflects a traditional request-response operation. For a solicit-response operation, faults would be handled on the client and returned to the server.

For a discussion on exceptions for both the client and server, as well as WSDL-defined faults, see Section 7.3.3, "WSDL-Defined Faults," in the HydraExpress User Guide.

8.3.4 Implementing a Standalone Server

HydraExpress allows you to implement your service as a standalone server, independent from the Agent. To take advantage of this feature, use the -standalone option when generating code in order to generate a sample standalone server.

For more information, see Section 23.3, "Standalone Server Implementations."

8.3.5 Server-Side Logging

HydraExpress supports both client-side and server-side logging. Logging is not implemented in the sample server application by default (although it is implemented on the client side).

HydraExpress provides two types of loggers: its primary Agent global logger, and a Web services-specific logger.

For server-side code, use the Agent logger, which is best for logging events from services, connectors, transports, and handlers. This book does not include a detailed discussion on using the Agent logger; rather, please see Section 6.2.2, "Using the Default Logger in a Service," in the HydraExpress User Guide.

The Web services logger may provide some use while debugging, as it logs some Fatal and Error level messages. See Section 12.4.2 for more information.

8.3.6 Session Management

The server-side code generated by HydraExpress provides support for session management in Web services. For information on session management in the HydraExpress-generated classes, see Chapter 18, "Sessions and State."

8.3.7 Using a Different Implementation Name

The name of the sample server implementation generated by HydraExpress is based on the port name defined in the WSDL, with the addition of Imp, as in <portType>Imp. The simplest way to implement the Web service is to use the sample implementation directly, without changing the name of the implementation class or the files.

However, there may be circumstances in which you want to change the name of the class that implements the service.

As an example, let's suppose you wanted to change the name of the service implementation for the DayofWeek example from DayOfWeekPortTypeImp to MyDayofWeekImp. These are the changes you would need to make:

Similar changes would need to be made if your application used notification classes and you wished to change the notification implementation.

In addition, if your application contained generated datatype classes (located in your code generation directory's codegen\data and include\data directories, you would need to:

8.3.8 Wrapped Style Operations

HydraExpress recognizes the wrapped document style. This feature allows you to generate an "unwrapped" interface for the proxy and server. Here are the WSDL requirements:

If you generate code using the -wrapped option, and your WSDL meets the above requirements, HydraExpress will "unwrap" the top level element, and treat each of the element's parts as arguments to the operation.

Both input and output elements are unwrapped, effectively removing the "wrapper" or top-level element from the generated interface.

8.3.8.1 Developing a WSDL to Support the Wrapped Style

Here is how this style looks in WSDL:

//1

The WSDL types element (or the XML Schema) defines a complex type with just one attribute, name, containing only elements, in this case the two elements Unit and identifier.

//2

The message's input part contains just a single part element, prevDay.

//3

The operation prevDay must have the same name as the related Schema element.

//4

The WSDL-SOAP binding specifies document style.

8.3.8.2 Generating Code with the -wrapped Option

You can generate code using the -wrapped option, as follows:

8.3.8.3 Looking at the Generated Code

The resulting generated service operation method for the prevDay operation would not include the complex type sns::PreviousDay at all, instead using its elements Unit and identifier as parameters:

By comparison, the same WSDL without the -wrapped option results in a generated service operation method that takes an input parameter of type sns::PreviousDay, as follows:

Some WSDLs cannot be used with the -wrapped option. If this is the case, the HydraExpress Agent will return an error:

8.3.9 Turning off Text Escaping to Improve Performance

If you are certain that the data you are sending will not contain any special characters that must be escaped, you may get better performance in your applications by setting the property RWSF:doEscape to false in the service's handler configuration file. (For more customizations to configuration files, see Section 8.3.11).

This property controls whether or not the skeleton escapes content when writing responses. The default is true.

To reset this property on the server side, set the RWSF:doEscape property to false in the server-side configuration file <servicecontextname>_handlers.xml. (For more information on this handlers file, see Section 8.3.11.3.)

By default the RWSF:doEscape property is "true".

To turn off text escaping, add the RWSF:doEscape property to <servicecontextname>__handlers.xml and set it to "false". For instance, given the DayofWeek example:

8.3.10 Accessing the Request URL

The service implementation may access the URL for requests that arrive via HTTP or HTTPS from the rwsf::CallInfo object.

To access the property RWSF:requestURL:

8.3.11 Customizing the Service Configuration Files

Among the generated files are a series of XML-based configuration files. Using the configuration files allows you to build a high degree of flexibility into your application. HydraExpress generates these configuration files automatically based on default values in the WSDL, so you don't have to deal with them unless you wish to customize your application.

The ability to use configuration files to link a transport with a service, or a service with a binding, effectively decouples these objects in your application. This allows you to change how your service works without changing your binding, or to use a new service with the same binding, or to change any number of other elements in your application without having to regenerate code or recompile.

The primary configuration files on the server side are

8.3.11.1 Transport Configuration File: transports.xml

The transports.xml file includes all available transports for your service. This file is not generated, but rather copied from the template files in the <installdir>\conf\webservice directory each time the code generator is invoked. Use this file to configure additional transports that you have included in your application, or to customize existing transports.

For more information, see Chapter 11, "Custom Transports and Listeners."

8.3.11.2 Servlet Configuration File: web.xml

The <servicecontextname>_web.xml file includes servlet configuration information. This includes

When you deploy your service, HydraExpress copies all config files, including this <servicecontextname>_web.xml file to the appropriate context directory in your <installdir>\apps\servlets directory.

For more information on this file and defining servlets, see Section 23.4, "About the Servlet Used by the Service."

Following is the contents of dayofweek_web.xml.

//1

The element servlet contains an attribute <servlet-name> identifying the name of the servlet that is the entry point to the service, DayOfWeekPortService, an instance of rwsf::WebServiceServlet, the class from which all Web services in HydraExpress are derived.

//2

DayOfWeekPortService is initialized using three initialization parameters, which are defined in <init-param> elements. The first is the configuration file, or configFile, for the servlet, identified as <servicecontextname>_handlers.xml. This configuration file defines the message handler chains for the service. (The file <servicecontextname>_handlers.xml is located in both the code generation directory and in the deployment directory for the service: RWSF_HOME\apps\servlets\<servicecontextname>.)

//3

Defines the service name to use in <servicecontextname>_handlers.xml. Note that the serviceName attribute DayofWeekPortService above maps to the name attribute in the <servicecontextname>_handlers.xml file. (See Section 8.3.11.3.)

//4

The optional parameter wsdlFileName simply specifies the name of the WSDL file that defined this service. If the parameter is specified, an HTTP GET request sent to the service's URL (the SOAP address in the WSDL) returns the WSDL file. (The WSDL file is located in the directory RWSF_HOME\apps\servlets\<servicecontextname>.)

//5

The url-pattern element within a servlet-mapping element associates a servlet with a set of URLs. When a request arrives, the Agent uses a simple procedure for matching the URL in the request with a url-pattern in the web.xml file. See Section 4.8.2, "Mapping Servlets to URLs," in the HydraExpress Servlet Development Guide for more information.

The excerpt here shows the default configuration elements contained in the generated <servicecontextname>_web.xml file. Other optional configuration elements may be added to define session timeout values and to configure error pages.

For more information on setting a timeout value for your session, see Section 18.4, "Configuring Session Timeouts." For more information, on error pages, see Section 4.11, "Configure Error Pages," in the HydraExpress Servlet Development Guide.

8.3.11.3 Service Chains Configuration File: handlers.xml

The configuration file <servicecontextname>_handlers.xml is generated as part of the server side components. It chains together the handlers for this service and contains initialization parameters. For more information on handlers, see Chapter 14, "SOAP Message Handlers."

Following is an excerpt from dayofweek_handlers.xml:

//1

The attribute name identifies the name of the service, and maps from the serviceName attribute in web.xml. When the servlet identified in web.xml receives a message, it passes it to the DayofWeekPortService to handle.

//2

The request is passed to any transport handlers that might exist (none in this case) and then on to any bindings defined in the request-handlers element. (In this example, there is just one binding -- the SOAP message handle.) The request is then dispatched to the server implementation.

//3

The element service-endpoint identifies the service implementation and its location.


The element transport-handlers should not be confused with the transport itself. An optional transport handler might add message encryption, compression, or special encoding. A transport handler manipulates the request before passing it to the request handlers, the response after any response handlers, and just before it is sent by the transport.

8.3.11.4 Named Objects Configuration File: objects.xml

A named object is a unit of compiled code with a name that allows it to be found and used by any service within a given service context. The configuration file for defining named objects is <servicecontextname>_objects.xml.

HydraExpress uses this mechanism for service execution. You can also use it to load and use objects that extend your services in a limitless variety of ways. The code can be a small, self-contained bit of functionality, or it might be an entry point to a large back end application, or anything in between.

For more information on named objects, see Chapter 16, "Named Objects."



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo are registered trademarks of Rogue Wave Software, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.