Configuring Data Services

Requires Platform 4.5+

Configuring Data Services

Configure data services primarily in the nexaweb-data.xml file.

You also configure the sql data service by defining statementHandlerDefinitions in the nexaweb-sql.xml file

Configuring the nexaweb-data.xml File

The nexaweb-data.xml file contains the following sections:

Configuration SectionDescription
requestProcessorDefinitionsDefines the pre- and post-processors that you can use: globally for all services requests; per data service type; in dataRequestDefinitions.
globalProcessorsLists pre- and post-processors that the data service applies to all service requests of any data service type.
dataServiceDefinitionsDefines the types of data services available through the data services plug-in. Also specifies data service type pre- and post-processors for each service request using that data service type.
dataRequestDefinitionsDefines information on the server to obtain data from external SQL or web services type data services.

requestProcessorDefinitions

Processors format data requests or results into the appropriate structures.

In the requestProcessorDefinitions section, you define the pre- and post-processors that you can assign as global processors, data service type processors, or in dataRequestDefinitions.

The requestProcessorDefinitions section includes the following elements:

ElementDescription
preProcessorDefinitionsLists pre-processors definitions.
postProcessorDefinitionsLists post-processors definitions.

Use the processorDefinition tag to define a processor in either the preProcessorDefinition or postProcessorDefinition elements.

The following table describes the processorDefinition tag attributes:

AttributesDescription
ClassSpecifies the implementing class for the processor.
IDSpecifies an ID by which to uniquely identify the processor so that you can reference it when using it as a global or data service type-specific processor, or in a dataRequestDefinition.

Processors use the following implementing classes:

Processor TypeImplementing ClassDescription
Pre-processorsDataRequestPreProcessorInterface to modify data request information. The data service calls pre-processors prior to making the data service request to the associated data service.
Post-processorsDataRequestPostProcessorInterface to modify raw data on its way to the client. The data service calls post-processors prior to sending the data service result back to the originating client

For example:

<requestProcessorDefinitions>
  <preProcessorDefinitions>
    <processorDefinition id="a" class="DataRequestPreProcessor"/> 
    <processorDefinition id="b" class="DataRequestPreProcessor"/> 
  </preProcessorDefinitions>
  <postProcessorDefinitions>
    <processorDefinition id="1" class="DataRequestPostProcessor"/> 
    <processorDefinition id="2" class="DataRequestPostProcessor"/> 
  </postProcessorDefinitions>
</requestProcessorDefinitions>

In addition, you can specify statementHandlerDefinitions in the nexaweb-sql.xml and nexaweb-webservices.xml files to format data for SQL statements or REST or SOAP requests defined in those files.

globalProcessors

This section lists the pre- and post-processors required to format all data accessed through all data service types into the appropriate structures.

The globalProcessors section includes the following elements:

ElementDescription
preProcessorsReferences pre-processors to use as global processors.
postProcessorsReferences post-processors to use as global processors.

Use the processor tag to specify the ID of a processor defined in the requestProcessorDefinitions element as a pre- or post-processor to use globally.

For example:

<globalProcessors>
  <preProcessors>
    <processor="a"> </processor>
  </preProcessor>
  <postProcessors>
    <processor="1"> </processors>
  </postProcessors>
</globalProcessors>

dataServiceDefinitions

The dataServiceDefinitions section of the nexaweb-data.xml file contains an entry for each type of data service available for accessing external data sources.

Currently, Nexaweb supports the following data service types:

Data Service TypeDescription
SQLProvides a means for Nexaweb applications to obtain and update data from external databases through Java Database Connectivity (JDBC).
Web servicesProvides means for Nexaweb applications to obtain and update data from web services through REST and SOAP.

In addition, you can specify pre- and post-processors per data service type to format data for all serviceRequests using that data service type.

The dataServiceDefinitions section includes the following elements:

ElementDescription
processorsLists all processors for all requests using this data service type.
preProcessorsReferences pre-processors to use for all requests using this data service type.
postProcessorsReferences post-processors to use for all requests using this data service type.

Use the processor tag to specify the ID of a processor defined in the requestProcessorDefinitions section as a pre- or post-processor for all serviceRequests using the SQL or web services type data service.

For example:

<dataServiceDefinitions>
  <dataService id="sql" 
    class="com.nexaweb.server.data.services.sqlDataService">
    <processors>
      <preProcessors>
        <processor="b"> </processor>
      </preProcessor>
      <postProcessors>
        <processor="2"> </processors>
      </postProcessors>
    </processors>
 </dataService>
</dataServiceDefinitions>

dataRequestDefinitions

In this section you define any dataRequestDefinitions to use to access data sources from the server.

A dataRequestDefintion defines on the server the primary components of a serviceRequest, the information required to access external data, so that you do not need to specify all of this information in the client UI file. In addition, use a dataRequestDefinition to define the primary components of a serviceRequest in order to create a serviceRequest that uses arguments.

The following table describes the elements of a dataRequestDefinition:

EelementsDescriptionRequired
IDSpecifies ID to uniquely identify this dataRequestDefinition to reference it in a serviceRequest.Yes
serviceResourceDefinitionSpecifies the sql statement, REST or SOAP request to execute using the associated data service.A dataRequestDefinition must specify either a serviceResourceDefinition or a serviceResourceReference.
serviceResourceReferenceSpecifies the ID of the sql statement, REST or SOAP request defined in the nexaweb-sql.xml or nexaweb-webservices.xml file to execute.A dataRequestDefinition must specify either a serviceResourceDefinition or a serviceResourceReference.
parameterMapSpecifies a named parameter map for this definition.No
processorsSpecifies IDs of any pre- or post-processors required to format data for this definition.No

The dataRequestDefinitions section includes the following elements:

ElementDescription
processorsLists all processors for this dataRequestDefinition.
preProcessorsReferences pre-processors to use for this dataRequestDefinition.
postProcessorsReferences post-processors to use for this dataRequestDefinition.

Use the processor tag to specify the ID of a processor defined in the requestProcessorDefinitions section as a pre- or post-processor for this dataRequestDefinition.

serviceResourceReference Example

Specify a dataRequestDefinition using a serviceResourceDefinition similar to the following: 

<dataRequestDefinition id="FlickrSearchRest">
<serviceResourceReference dataServiceId="WebService" serviceResourceId="searchFlickrParam" />

The nexaweb-data.xml file defines the dataRequestDefinition, FlickrSearchRest, that references a WebService type data service request, searchFlickrParam, defined in the nexweb-webservice.xml file.

serviceResourceDefinition Example

Specify a dataRequestDefinition using a serviceResourceDefinition similar to the following: 

<dataRequestDefinition id=”getDepartments”> 
   <serviceResourceDefinition>
    <sqlStatement connectionId="engineering" 
      xmlns=”http://nexaweb.com/service/data/sql”>
     <statement>
       SELECT * FROM department where dept=’’{0}’’
     </statement> 
    </sqlStatement> 
   </serviceResourceDefinition>

  <parameterMap>
   <parameterMapping name=”deptId”>
    <default>engineering</default>
   </parameterMapping>
  </parameterMap>
</dataRequestDefinition> 

In this example, the dataRequestDefinition, getDepartments, inlcudes a serviceResourceDefinition that accesses an external data source though an SQL statement. The SQL statement selects from deptartment where dept is a variable. The parameterMap provides a means to pass a user-specified value for the dept variable, deptID, or thedefault value of engineering, if a user does not supply a value.

You use a dataRequestDefinition, defined on the server in the nexaweb-data.xml file, in a serviceRequest defined in the client UI file.  You can create a serviceRequest in the client UI file to use this dataRequestDefinition similar to the following:

<serviceRequest id=” getDepartmentRequest” dataRequestId=” 
   getDepartments” xmlns=”http://nexaweb.com/service/data”>
<parameters>
<parameter name=”deptId”>{0}</parameter>
</parameters>
</serviceRequest>

The serviceRequest, getDepartmentRequest, references as the dataRequestID, the dataRequestDefinition, getDepartments. It specifies the parameter, deptId, which accepts user-specified values to pass to the deptID parameter mapping defined in the getDepartments dataRequestDefinition.