Using scriptmaps for request routing in Web Connection |
http://www.west-wind.com/wconnect/nocode.wc
where Nocode.wc contains both script and FoxPro script code using Active Server like syntax.
But scriptmaps can be useful even beyond the traditional sense of mapping files. You can also use it in Web Connection as a request routing mechanism. Let's say you have CompanyX and CompanyY and you set up script maps for each of them, .CMX and .CMY respectively.
Now instead of calling WC.DLL directly you'd always call an .CMX link instead. Script mapping makes the following legal, even if the .CMX page doesn't exist:
http://www.west-wind.com/myPath/wc.cmx?SomeMethod
First notice that we don't have to reference wc.dll explicitly and we can stay in our app path (mypath) rather than pointing back at /wconnect/wc.dll, which is very convenient. Second notice that there's no 'application' parameter on the query string. A typical Web Connection URL would be:
wc.dll?ApplicationPrg~SomeMethod
Instead, we use the CMX extension as the application routing mechanism. To set this up you can do the following in WCMAIN or your mainline program:
lcExtension = UPPER(JUSTEXT(THIS.oCGI.GetPhysicalPath()))
DO CASE
CASE lcExtension = 'CMX'
Do CompanyXPRG WITH THIS
CASE lcExtension = 'CMY'
DO CompanyYPRG WITH THIS
...
ENDCASE
http://www.west-wind.com/myapp/SomeMethod.cmx
To make this work you need to change your CASE statement in your wwProcess subclass:
************************************************************************
* SomeApp :: Process
***************************
*** Function: This is the callback program file that handles
*** processing a CGI request
************************************************************************
FUNCTION Process
LOCAL lcParameter, lcOutFile, lcIniFile, lcOldError
PRIVATE Request, Response, lcPhysicalPath
Request = THIS.oRequest
Response = THIS.oResponse
lcParameter=UPPER(Request.QueryString(2)) && Optional CGI parameters following EXE name
*** Check for Script Mapped files for: .CMX
lcPhysicalPath=Request.GetPhysicalPath()
lcPagename = JUSTSTEM(lcPhysicalPath) && Potential Method name
lcExtension = UPPER(JUSTEXT(lcPhysicalPath)) && Extension name
DO CASE
*** Add any 'invalid' method calls here
CASE INLIST(lcParameter,'PROCESS','LOAD','INIT','DESTROY')
THIS.ErrorMsg('Invalid Method: ' +lcParameter,'This method name is illegal...')
*** Procedure from the URL Parameter
CASE !EMPTY(lcParameter) AND PEMSTATUS(THIS,lcParameter,5)
=EVALUATE('THIS.'+lcParameter+'()')
*** CMX Page name - SomeMethod.cmx runs SomeMethod.cmx method etc.
CASE !EMPTY(lcPageName) AND PEMSTATUS(THIS,lcPagename,5)
=EVALUATE('THIS.'+lcPageName+'()')
*** Catch actual CMX script pages and 'run' them
CASE !EMPTY(lcExtension) and lcExtension = 'CMX'
THIS.oResponse.ExpandTemplate(lcPhysicalPath)
CASE EMPTY(lcParameter)
THIS.DefaultPage()
OTHERWISE
*** Unhandled method - display error page
THIS.ErrorMsg('The server was unable to respond '+;
'to this request',;
'Parameter Passed: <b>'+PROPER(lcParameter)+'</b><BR>'+;
'Error: <b>Unhandled Method</b>')
#IF WWC_SENDEMAIL_ONERROR
THIS.oServer.SendMail(WWC_MAILSERVER,WWC_ADMINISTRATOR_EMAIL, ;
WWC_ADMINISTRATOR_EMAIL,;
WWC_ADMINISTRATOR_EMAIL,'', ;
'Web Connection Error Message - Unhandled request',;
'The request Query String is: ' +THIS.oRequest.cQueryString + CR+;
' DLL or Script: ' +THIS.oRequest.GetCGIVar('Executable Path') + CR+;
' Server Name: ' + THIS.oRequest.GetServerName())
#ENDIF
ENDCASE
RETURN .T.
ENDFUNC
By doing all of this you can now do the following:
Last Updated: 10/03/98