URLs in a Morfik Application

Morfik Web Applications follow the same basic pattern as all other Web Applications. They respond to http Requests that are received in the form of URLs. A URL conveys the necessary information about the resource being requested so as to enable the Web application to fulfil the request.

In Morfik Web Applications all the various aspects of URL processing are handled by the Morfik Application Framework. Upon the arrival of a request, the Morfik framework parses the URL and its associated parameters and decides how to serve the request.

Before discussing various aspects of URLs in a Morfik application it is useful to learn about different parts within a URL and how to access them in the framework.


URL Anatomy

Consider the following sample URL, taken from the current Morfik website:

http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}


This carries several distinct pieces of information: the network protocol being used, the server being contacted, and the name and parameters of the resource being requested.


URL Fragment Description
Network protocol The network protocol being used to make the request is indicated at the start of the URL:
http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

The network protocol can be obtained from either of the following:


Server-side:

THttpRequest.Protocol : String;    // possible values: 'http', 'https'
THttpRequest.Https    : Boolean;   // possible values:  false,  true

Browser side:

 window.location.protocol : String; // possible values: 'http:', 'https:'
Host Identity The second piece of information conveyed by the URL is the identity (either a host name or an IP address) of the server being contacted:
http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

This can be obtained from the following property:


Server-side:

THttpRequest.Host : String;

Browser-side:

 window.location.host : String;

In some circumstances is may be desirable to detect whether the request is coming from the local host (i.e., whether the client and server machines are the same). This information can be obtained from the following property:


Server-side:

THttpRequest.IsLocalHost : Boolean;
Port Number The URL may also include a port number:
http://www.morfik.com:9119/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

(if no port number is specified in the URL, the default port number of 80 [for Http] or 443 [for Https] is assumed). The port number can be obtained from the following:


Server-side:

THttpRequest.ServerPort : String;

Browser-side:

 window.location.port : String;
Requested Resource The remainder of the URL identifies the resource being requested:
http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

This string can be obtained from the following property:

THttpRequest.URL : String;

To obtain the name part, including the extension:

http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

use this:


Server-side:

THttpRequest.URLFileName : String;

Browser-side:

 window.location.pathname : String;


To obtain the name part, without the extension:

http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

use this:

THttpRequest.URLDocumentName : String;
Parameters The final component of the URL is the parameter string:
http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

This string can be obtained as follows:


Server-side:

THttpRequest.Query : String;

Browser-side:

 window.location.search : String;


Server-side: Individual URL parameters can be accessed either by numerical index:

THttpRequest.URLParameters.Count    : Integer;   // = 3
THttpRequest.URLParameters[0].Name  : String;    // = 'cls'
THttpRequest.URLParameters[0].Value : String;    // = 'code'
THttpRequest.URLParameters[1].Name  : String;    // = 'sid'
...

or by name:

THttpRequest.GetURLParameterByName('cls').Value  // = 'code'
THttpRequest.GetURLParameterValue ('cls')        // = 'code'

URL Special Parameters

There are a number of special URL parameters defined by the Morfik Application Framework which convey system-level information from the browser side to the server side of of the framework. The following table lists the special URL parameters defined in the Morfik Application Framework.


URL Parameter Description
cls

(eg. cls=form)

Specify the type of Http[ request. The possible values for this parameter are:

code - request for JavaScript code module

form  - request for form HTML
soap  - request is a Soap call
spxy  - request is a proxy soap call through server
res   - request for a registered resource eg. images, etc
rep   - request for Report PDF
blob  - request for a Blob field content in a database table
upl   - request is a file upload
uplv2 - request is a file upload (version 2)
uplS3 - request is a file upload (version 3)
file  - request for an unregistered file
dfcss - request for data form CSS file
rss   - request for RSS feed
dbg   - request is a browser debug message
tzo

(eg. tzo=-10)

Specifies the time zone of the region the request originates from.
lng

(eg. lng=fr)

Specifies the language that the response should be composed in .
sid Specifies the current Session ID. This is read from the global variable, SecurityId, in the System module in the browser side.
xid A value that uniquely identifies the project code-base for which the JavaScript files were generated.
cbf Specifies the call-back function that is to be called after a script is downloaded.
thm The name of the current theme. Not used.
ins The instance name of a Form object.
serviceurl Specifies the end-point URL when making a SOAP call through a SOAP proxy server
soapaction Specifies the SOAP function name


Certain parameters used by the Morfik framework have specific functions for accessing their values:

THttpRequest.GetTimeZoneOffset : Integer;        // 'tzo' parameter
THttpRequest.RequestKind       : TRequestKind;   // 'cls' parameter
THttpRequest.SecurityID        : String;         // 'sid' parameter
THttpRequest.Language          : String;         // 'lng' parameter


For parameters that have no specific function one of the two following methods could be used:

THttpRequest.GetURLParameterByName('cls').Value  // = 'code'
THttpRequest.GetURLParameterValue ('cls')        // = 'code'

Published URLs vs Internal URLs

Morfik URLs fall into two distinct categories of URLs, Published URLs and Internal URLs.

Published URLs are designed to make a Morfik Web application accessible to conventional web clients including search crawlers, robots as well as providing a more friendly format for bookmarking and general human use.

eg. http://forum.morfik.com/posts/234


Currently, Published URLs can only be used in connection with Virtual Pages. All other application resources can only be accessed through Internal URLs.

Internal URLs are used when the two sides of the Morfik Application Framework interact. As such they are regarded as internal and not suitable for direct access from external source. It is important to note however that Internal URLs are not protected and can be used by external sources.

eg. http://www.morfik.com/MorfikSite.js?cls=code&sid=&xid={7166F464-9484-4DE3-8F44-F00CF7C9C74B}

BaseURL Property

Since Morfik Published URLs can be defined in an arbitrary way there is a need for explicit definition of the application’s root URL. This property is critical for proper installation of Apache and IIs-plug-ins as well as all internal references within the application code to resources such as images, Flash files, etc. There are design-time and run-time aspects to this property.

Design-time

At design-time, the BaseURL property is used only for XApps compiled as Apache or IIS plug-ins. It has no effect on stand-alone XApps or XApps deployed onto Morfik deployment platform. The BaseURL property can be set by switching to Project View, and activating the Properties panel. Its default value is empty.

Please note, in all the following examples we assume that the project name is “project1”. BaseURL should not include quotes.

Apache plug-ins

In the case of Apache plug-ins the BaseURL property has to be set to the name of virtual folder handled by the XApp. For example, if XApp is to handle “/dir” folder, BaseURL has to be set to “/dir”, and inside httpd.conf the module has to be registered with

LoadModule project1_module modules/project1.dll
<Location /dir>
    Options Indexes FollowSymLinks MultiViews +ExecCGI 
	SetHandler project1-handler
    Order deny,allow
    Allow from all
</location>


If the BaseURL property is not assigned, it is treated as if it was set to “/project1”, so if Apache virtual directory name matches Morfik project name, the BaseURL property can be left empty.


IIS plug-in

In the case of an IIS plug-in, If virtual directory is used, the BaseURL property has to be set to “/directory/project1.dll”. On the other hand, If the IIS plug-in is registered without virtual directory, the BaseURL property has to be set to “/project1.dll".

For example, if you were to to access the page “PageName” in your XApp from a web browser using the following URL:

http://website.com/sitedir/project1.dll/DocumentName


then the BaseURL property has to be set to “/sitedir/project1.dll”

On the other hand, if it was accessed using http://website.com/project1.dll/DocumentName , then the BaseURL property has to be set to “/project1.dll”. If BaseURL is not assigned, it is treated as if it was set to “/project1/project1.dll”, so if virtual directory is used, and its name matches Morfik project name, the BaseURL property can be left empty.


Run-time

At run-time, when a reference to a URL doesn’t include the complete path information (relative URL) the browser resolves reference using the full address defined in its address bar which is the address of the current page. For example, if the current page is www.mysite.com/download/ and the URL is “video.swf”, it gets resolved to www.mysite.com/download/video.swf Since Morfik XApps can publish multiple (virtual) pages, it is important to make sure that all resource files are referenced in a way that allows unambiguous resolution regardless of the current page name. To achieve this one has to use use the Catalog.BaseURL property both at server- and browser-side code.

For example, here’s how one might add an external JavaScript file in the OnPrintHTMLHeader handler on the server-side:

Response.WritelnString('<script type="text/javascript" src="' + Catalog.BaseURL + 'swfobject.js?cls=res"></script>');

Related Topics

Back to top