The ST: XML Communications feature extends the Web Server Interface (WSI) layer of Web Connection to support XML and handle the incoming server requests. VisualAge XML support provides the AbtXmlWsiHandler, which is a subclass of AbtWsiHandler. You can subclass the AbtXmlWsiHandler to create custom XML request handlers. You must then override the abtWsiHandleWsiTransaction: method in order to handle incoming XML requests.
VisualAge Smalltalk provides a new Part type named XML Request Handler, in the New Part view to simplify the creation of AbtXmlWsiHandler subclasses.
VisualAge Smalltalk provides a new transport called xml-tcp that allows applications to process socket requests without first passing them through an HTTP server. To use the xml-tcp server transport, perform the following steps:
For more information on setting up and using the Web Server Interface, see the VisualAge Smalltalk Web Connection Guide.
This section steps you through the process of building a sample server application. This application is a simple illustration of a customer request handler that uses an XML DOM parser (AbtSampleCustomerRequestHandler). The main steps to create this sample are as follows:
abtHandleWsiTransaction: anAbtWsiTransaction " Handle the incoming AbtWsiTransaction. The expected content is an AbtXmlSampleCustomerRequest passed as XML. This method performs the following steps. 1) Obtain the XML string from the transaction object. 2) Parse the XML string using the DOM parser 3) Use input serialization API to convert the DOM into an AbtXmlSampleCustomerRequest object 4) Process the command specified in the customer request object 5) Create an AbtXmlSampleCustomerResponse object and write its XML representation to the 'response' of the AbtWsiTransaction using output serialization method #abtXmlPrintString " | xmlString customerRequest domDocument | " Get the XML request string from the passed transaction object " xmlString := anAbtWsiTransaction request content. " Parse the XML string while handling any exceptions that occur during parsing " self handleParseExceptionsWhile: [ domDocument := AbtXmlDOMParser newNonValidatingParser parse: xmlString ]. " Construct a customerRequest object from the contents of the incoming domDocument. This requires that the contents of the DOM be 'mapped' into the desired object " domDocument notNil ifTrue: [customerRequest := self customerFromDOM: domDocument ]. " An error occured converting the DOM into a customer object. Pass back some XML to report the error " customerRequest isNil ifTrue: [ anAbtWsiTransaction response content: self createErrorString contentType: 'text/xml' ] ifFalse: [ anAbtWsiTransaction response content: (self processCustomerRequest: customerRequest ) contentType: 'text/xml' ]
This method also checks the object cache for a mapping specification. If a mapping specification is not found, a new mapping specification is created from the external mapping file and cached to the object cache.
customerFromDOM: aDocumentObjectModel " Create a new instance of AbtXmlSampleCustomer using the passed DOM " | mappingDOM mappingSpec object mapFilePath sep | " Check the object cache for the presence of the mappingSpec. If it is not found, create a new mappingSpec from the external mapping file, and add the resulting mappingSpec to the objectCache for future usage " ( mappingSpec := AbtXmlObjectCache current mappingSpecNamed: self mappingSpecName ) isNil ifTrue: [ sep := AbtXmlResourceReader current pathSeparator asString. mapFilePath := '..', sep, 'xml', sep, 'samples', sep, 'customer.map'. self handleParseExceptionsWhile: [ mappingDOM := AbtXmlDOMParser newValidatingParser parseURI: mapFilePath ]. self handleDOMExceptionsWhile: [ mappingSpec := AbtXmlMappingSpec fromMappingDOM: mappingDOM ]. mappingSpec notNil ifTrue: [ mappingSpec addToXmlObjectCache ] ]. mappingSpec notNil ifTrue: [ object := aDocumentObjectModel mapUsing: mappingSpec ]. ^object
processCustomerRequest: anAbtXmlSampleCustomerRequest " Process the command described in the passed customer request " | customerResponse customer | anAbtXmlSampleCustomerRequest isNil ifTrue: [ ^self createErrorString ]. customerResponse := AbtXmlSampleCustomerResponse new. " Simple application code for demonstration purposes " anAbtXmlSampleCustomerRequest request = 'INQUIRY' ifTrue: [ customerResponse customer: anAbtXmlSampleCustomerRequest customer. customerResponse customer lastName = 'Programmer' ifTrue: [ customerResponse customer firstName: 'Joe' ; lastName: 'Programmer' ; email: 'joeprogrammer@us.ibm.com' ; streetAddress: '100 IBM Way' ; city: 'RTP' ; state: 'NC' ; zip: '27609'. customerResponse response: 'Success' ] ifFalse: [ customerResponse response: 'Not found' ] ] ifFalse: [ customerResponse response: 'Not supported' ]. ^customerResponse abtXmlPrintString
handleDOMExceptionsWhile: aBlock " Execute the passed block wrapped in code to handle exceptions that occur while manipulating DOM objects" aBlock when: AbtDOMConstants::AbtDOMException do: [ :aSignal | self logError: aSignal argument printString ]
handleParseExceptionsWhile: aBlock " Execute the passed block wrapped in code to handle SGML exceptions " aBlock when: SgmlExceptions::SgmlException do: [ :aSignal | self logError: aSignal argument printString ].
This section steps you through the process of building a sample customer request handler that uses a SAX parser.
abtHandleWsiTransaction: anAbtWsiTransaction " Handle the incoming AbtWsiTransaction. The expected content is an AbtXmlSampleCustomerRequest passed as XML. This method performs the following steps. 1) Obtain the XML string from the transaction object. 2) Parse the XML string using the SAX parser and custom SAX handler named 'AbtXmlSamplesSaxCustomerContentHandler' 3) Process the command specified in the resulting customer request object 4) Create an AbtXmlSampleCustomerResponse object and write its XML representation to the 'response' of the AbtWsiTransaction using output serialization method #abtXmlPrintString " | xmlString customerRequest | " Get the XML request string from the passed transaction object " xmlString := anAbtWsiTransaction request content. " Parse the XML string while handling any exceptions that occur during parsing " self handleParseExceptionsWhile: [ customerRequest := ( AbtXmlSaxParser newNonValidatingParser contentHandler: AbtXmlSampleSaxCustomerContentHandler new ) parse: xmlString ]. customerRequest isNil ifTrue: [ anAbtWsiTransaction response content: self createErrorString contentType: 'text/xml' ] ifFalse: [ anAbtWsiTransaction response content: (self processCustomerRequest: customerRequest ) contentType: 'text/xml' ]
Before you package an application, make sure that the prerequisites are defined. The following list shows the XML support applications and the features they provide: