Title: IA304 Building Web Applications with EAServer
1IA304Building Web Applications with EAServer
Mike Barlotta Director of Technology AEGIS
Consulting mike.barlotta_at_aegisconsulting.com
2Todays Agenda
- Web Applications
- What is EAServer?
- PowerDynamo development
- Web and Jaguar CTS
- Sybase in Action
- Q A
3The Internet is not the Web
- Internet
- Global TCP/IP network
- World Wide Web (WWW)
- service available over the Internet
- HTTP
- Stateless network protocol runs over TCP/IP
- HTML, XML
4What is the Web
- World Wide Web (WWW) cont.
- Web server
- responds to HTTP requests
- retrieves documents and resources
- Web browser
- requests documents and resources from Web server
- interprets HTML, XML
5History of the Web
- Al Gore is not the father of the Internet that
distinction belongs to DARPA engineers. - Tim Berners-Lee invented the Web in 1990
writing the first Web server and browser. - Marc Andreesen exposed the Web to the masses with
Mosaic the first GUI Web browser in 1993. - The rest is history...
6Static vs Dynamic Web Site
Static Web Site
- HTML page content is same for each request
- Change to content requires HTML page edit
- No user interaction
- No access to live data
- Web Site
HTTP
Web Browser
Web Server
7Static vs Dynamic Web Site cont.
Dynamic Web Site
- HTML pages dynamically generated for each request
- Content changes based on data, user login, etc.
- Allows user interaction
- Access to data real-time
- Web Application
HTTP
Web Server
Web Browser
DBMS
Dynamic Page Server
8Dynamic Web Sites
- Web server
- responds to HTTP requests and retrieves resources
- Expand Web server capabilities by providing a
gateway between it and external programs - Common Gateway Interface (CGI)
- uses standard I/O
- new process for each request
- slow and inefficient
9Dynamic Web Sites cont.
- NSAPI, ISAPI
- Web Server API
- runs in-process, making it faster than CGI
- Java Servlets
C
Perl
Python
CGI, NSAPI, ISAPI
- Business processing
- Data access
- Transactions
- HTML generation
Web server
10Todays Agenda
- Web Applications
- What is EAServer?
- PowerDynamo development
- Web and Jaguar CTS
- Sybase in Action
- Q A
11What is EAServer?
- EAServer Jaguar CTS PowerDynamo
- Jaguar CTS
- Component Transaction Server
- PowerDynamo
- Dynamic Web Page Server
12EAServer Development Tools
- Jaguar CTS
- PowerBuilder
- PowerJ, Java IDE
- PowerDynamo
- PowerSite
- Sybase Central
- HTML editors
Jaguar CTS
PowerDynamo
13Jaguar CTS
Component Application Server component-centric
development
- CORBA/IIOP
- Multiple languages
- Interoperability between components
- Share transactions between
- components
Jaguar CTS
Power Builder
COM
C/C
Java
- Visual Basic
- Delphi
- Visual C
14What is PowerDynamo?
- Dynamic Page Server
- Page-centric development
- Utlra-thin clients (HTML only)
- Serves dynamic content
- Not a Web server
- Not a component server
- PowerDynamo requires a
- Web Server to deliver Web resources
15PowerDynamo Interfaces
- CGI, ISAPI, NSAPI
- interface between PowerDynamo and the Web server
CGI, NSAPI, ISAPI
Web server
PowerDynamo
16Managing PowerDynamo Web site
- Web Site resources
- HTML, XML documents
- Images, Multi-media etc.
- Templates, Scripts
- Web Site resources management
- Database system
- File system
PowerDynamo
17PowerDynamo Web Site overview
Web Browser
1. Request Dynamo page
7. Return HTML page
Web Server
6. Return dynamic HTML page
2. Pass Request to Dynamo
PowerDynamo
- Database Connection
- Caching
- Page Caching
- Script Interpreter
4. Execute Template, Script
3. Retrieve Template, Script
5. Access Data
Web Site
Application Data
18EAServer Review
- Building Applications
- Jaguar CTS
- Component Transaction Server
- CORBA compliant components accessible over IIOP
- PowerDynamo
- Dynamic Page Server
- Application accessible only from Web
- Jaguar CTS PowerDynamo
- Application built with reusable components
accessible from multiple clients and Web
19Sybase supports the Enterprise Architecture
Web Server
HTTP
PowerDynamo
RDBMS
Browser
IIOP
DirectConnect
IIOP
CORBA Client
COM/ IIOP
JaguarCTS
COM Client
DB/2
AS/400
20Todays Agenda
- Web Applications
- What is EAServer?
- PowerDynamo development
- Web and Jaguar CTS
- Sybase in Action
- Q A
21Sample Application
ASA application database Jaguar Database
Connection Cache Jaguar Components AutoNet
package PowerDynamo Web site PowerDynamo pages
22Creating the Dynamo Web Site
1. Create an ASA database for Web site 2. Create
an ODBC profile 3. Create Connection Profile
23URL Mapping for Dynamo site
- 4. Connect to Web site database
- connect through Sybase Central
- provide name for root folder
- import system files
- 5. Add a mapping
24Importing existing resources
6. Create an images folder 7. Import images 8.
Create a scripts folder 9. Import scripts
25Sample Application
- ASA application database
- Jaguar Database Connection Cache
- Jaguar Components
- AutoNet package
- PowerDynamo Web site
- PowerDynamo pages
26PowerDynamo Building Blocks
- Templates
- HTML, XML, graphics etc.
- DynaScript
- Dynamo tags
- Scripts
- contain DynaScript
- Extendable
- Database connections
- Components
ltHTMLgt lt!--SCRIPT ... --gt lt/HTMLgt
DBMS
Application Server
27DynaScript
- Based on ECMAscript
- JavaScript syntax
- extended to support database-driven content
- case-sensitive
- object-oriented
- provides way to declare object types and derive
new classes from an existing class. - Interpreted
28Embedding DynaScript
- DynaScript is placed in SCRIPT tags
- Embedded within HTML comment tags
- lt!--SCRIPT
- // script goes here
- --gt
- pre-defined objects
- document object
- session object
- java object
29Building Dynamo Script - code
lt!--SCRIPT function getTodayDate() myDate
new Date() iMonth myDate.getMonth()
iDate myDate.getDate() iYear
myDate.getFullYear() switch (iMonth)
case 0 sMonth "January"
break case 1 sMonth "February"
break ... case 11 sMonth
"December" break
CurrentDate sMonth " " iDate ", "
iYear return CurrentDate --gt
Saved as getdate.ssc
30document object
- represents a document in your Web site.
- methods properties to access document
- write and writeln methods used to generate
dynamic HTML. - redirect property used to direct current page to
a new URL. - value property used to access page parameters.
31Building Dynamo Template - code
ltHTMLgtltHEADgtltTITLEgtAutoNetlt/TITLEgtlt/HEADgt ltBODY
topMargin0 leftMargin0gt ltPgtnbsplt/PgtltPgtnbsplt/
Pgt ltTABLE aligncenter border0gt ... ltTRgt
ltTD colspan3gt ltA HREF""gtltIMG
src"images/autonet_big.jpg" border0gtlt/Agt
lt/TDgt lt/TRgt ltTRgt
ltTDgtnbsplt/TDgt ltTD alignright
colspan2gtltFONT facearial size2gt
Today's date is lt!--SCRIPT
import scripts/getdate.ssc
document.writeln(getTodayDate()) --gt
lt/TDgt lt/TRgt lt/TABLEgt lt/BODYgt lt/HTMLgt
Saved as welcome.stm
32Relative addressing in scripts
- Can use relative addressing to specify a path
relative to the current directory. - import scripts/getdate.ssc
- import /autonet/scripts/getdate.ssc
- Current directory is one specified in the URL
that called the page. - http//localhost/autonet/welcome.stm
33Relative addressing cont.
- The use of ../ in a directory path specifies the
directory back one level. - The use of in a directory path specifies the
root folder. - import /scripts/getdate.ssc
- Going back further than root folder causes an
error.
34Passing data to a Dynamo Page
- Uniform Resource Locator (URL)
- http//SERVER_HOST/POWERDYNAMO_MAPPING/PATH/RESOUR
CE - Information is passed through a URL
- ? Seperates location and resource information in
the URL from the data - data passed as namevalue pairs
- additional data seperated by
- http//localhost/autonet/page.stm?arg1value1arg2
value2arg3value3
35Passing data to a Dynamo Page
- Anchor tags and document.redirect
- data passed back is specified directly in the URL
- HTML FORMS
- data passed to URL specified in ACTION property
- data automatically appended to URL when submitted
- METHOD property (GET vs. POST)
- INPUT tags (text, password, hidden, checkbox,
radio) - SELECT
- TEXTAREA
36Anchor tag - code
lt!--SCRIPT // Get Page Parameter - Type ID passed
in ... // Create a Dynamic HyperLink document.wri
teln(ltA HREFAuto_By_Type.stm?type_id) docume
nt.writeln(myTypeID) document.writeln(gt) docu
ment.writeln(Last Auto Typelt/Agt) ... --gt gener
ates ltA HREFAuto_By_Type.stm?type_id100gtLast
Auto Typelt/Agt When user clicks on the link the
URL passes page parameter type_id100 to
Auto_By_Type.stm
37document.redirect - code
// Get page parameters UserID
document.value.userid PWD document.value.passw
ord // Validate Logon if (UserID PWD)
... document.redirect"logonok.stm"
exit else ... Url
AutoNetError.stm?error_messageInvalid Logon
attempt. document.redirectUrl exit
38HTML FORM - code
ltFORM action"validatelogon.ssc"
methodpostgt ltTABLEgt ltTRgt ltTD
alignrightgtUser ID lt/TDgt ltTD
alignleftgt ltINPUT nameuseridgtlt/TDgt lt/TRgt lt
TRgt ltTD alignrightgtPassword lt/TDgt ltTD
alignleftgt ltINPUT namepassword
typepasswordgtlt/TDgt lt/TRgt ltTRgt ltTD
alignmiddle colSpan2gt ltINPUT value"Log on"
nameLogon typesubmitgtlt/TDgt lt/TRgt lt/TABLEgt lt/F
ORMgt
39Getting Page Parameters in PowerDynamo
- Direct access in HTML page
- can use value of page parameter without SCRIPT
- prefix page parameter with in HTML
- ltH1gtpage_paramlt/H1gt
- In SCRIPT through document.value
- if (exists(document.value.userid))
- UserID document.value.userid
-
- else
- UserID ""
40Getting Page Parameters - code
// Get page parameters if (exists(document.value.
userid)) UserID document.value.userid
else UserID "" ... // Validate
Logon if (UserID PWD) // Store values in
Session session.UserIDUserID
session.PWDPWD // Clear potential
logon error message session.lasterror""
// Redirect User to page
document.redirect"logonok.stm" ...
41session object
- HTTP is stateless.
- no information is stored between requests by the
client. - Session object
- one session object for each Web client.
- used to maintain information about a session for
a given Web client as they navigate the Web site. - is accessible from all templates scripts.
42session object cont.
- Session duration is determined by PD.
- default is 5 minutes
- after idle time expires session is removed
- Properties are defined by pages
- session.UserID Mike
- Implemented using a cookie.
43Accessing session data - code
ltHTMLgt ltBODYgt ltH1gtltIMG src"images/autonet_big.jpg
"gtlt/H1gt ltH1gtnbspnbspnbspnbspnbspnbspn
bsp nbsp Welcome to AutoNet, lt!--SCRIPT if
(exists(session.UserID)) document.writeln(sess
ion.UserID) else session.lasterror"Plea
se login..." document.redirect"logon.stm"
exit --gt lt/H1gt lt/BODYgt lt/HTMLgt
44Enhancing the Dynamo Site
- Turn off Directory browsing
- autoexec.ssc under system folder
- // Remove this line to turn off directory
browsing - //site.OnEvent('Directory','Get','','','contview
.ssc') - Setup default document
- autoexec.ssc under system folder
- // Add this line to call script
- site.OnEvent('Directory','Get','','',/default.ssc
') - redirect request to the first document
- lt!--SCRIPT
- // default.ssc
- document.redirect"/autonet/Welcome.stm"
- --gt
45Todays Agenda
- Web Applications
- What is EAServer?
- PowerDynamo development
- Web and Jaguar CTS
- Sybase in Action
- Q A
46Accessing Jaguar CTS from the Web
- Java Applet
- Robust client interface
- Stateful IIOP connection to Jaguar CTS
- Requires Java-enabled browser on client
- Java sandbox limits capabilities on Internet
- Java Servlet
- Ultra-thin client
- HTML generated in Java code
47Accessing Jaguar CTS from the Web cont.
- Dynamic Page Server
- Ultra-thin client
- PowerDynamo
- Microsoft ASP
- Cold Fusion
- Java Server Pages
- available in Jaguar CTS 3.6 and PowerJ 3.6
- uses Java Servlets
48PowerDynamo and Jaguar CTS
Web Browser
Access to Jaguar components 1. ActiveX 2. Java
3. MASP 4. COMPONENT tag
HTTP
Web Server
CGI, ISAPI, NSAPI
PowerDynamo
ActiveX
Java
MASP
COM
ODBC, Open Client
JagProxy.dll
IIOP
IIOP
Jaguar CTS
49Setup PowerDynamo to use Java
- 1. Configure PD to use Sun VM
- 2. PATH
- Java Bin
- D\Program Files\Sybase\Shared\Sun\jdk117\bin
50Setup PowerDynamo to use Java cont.
- 3. CLASSPATH
- Java Lib classes.zip
- D\Program Files\Sybase\Shared\Sun\jdk117\lib\clas
ses.zip - Java Stubs base path
- JAGUAR\html\classes
- PD on separate machine from Jaguar CTS
- Install JagClient.exe on PD machine
- Put path to JagClient.zip in CLASSPATH
51Accessing Jaguar CTS - Java
- Access via CORBA/ IIOP
- Jaguar uses IDL to describe components and
generate stubs. - Java stubs
- Allow PD scripts to access Jaguar components
through java object. - Generation of stubs required for new components
and when IDL is changed. - Jaguar component does not have to be written in
Java.
52Accessing Jaguar CTS - Java cont.
PowerDynamo
ltHTMLgt lt!--SCRIPT ... JagObj.myFunc() --gt lt/HTMLgt
Jaguar CTS
java
Java stub
Jaguar component
53Accessing Jaguar CTS - Java cont.
- 1. Create Java stubs for components
- 2. Compile Java stubs
- 3. Stop and Start PowerDynamo
- Flush PowerDynamo cache
- Done by stopping and starting Web server
54java object
- Allows access to Java classes within PowerDynamo
scripts. - No properties
- Methods
- CreateComponent Access Jaguar component through
Java using CORBA naming services. - CreateObject Instantiates a Java class object.
- CallStaticMethod Calls a static Java method.
55java.CreateComponent
ltHTMLgt lt!--SCRIPT ... java.CreateComponent JagObj.
myFunc() --gt lt/HTMLgt
PowerDynamo
Jaguar CTS
java
Jaguar component
Java VM
.class file
Java stub
56java.CreateObject
ltHTMLgt lt!--SCRIPT java.CreateObject() JavaObj.my
Func() --gt lt/HTMLgt
PowerDynamo
java
Java VM
.class file
Java Class
57java.CallStaticMethod
ltHTMLgt lt!--SCRIPT ... java.CallStaticMethod --gt lt/
HTMLgt
PowerDynamo
java
Java VM
.class file myFunc()
58Accessing a Jaguar Component -code
// Create Jaguar component JagServer
iiop//localhost9000 JagAuto
java.CreateComponent(AutoNet/auto, JagServer,
, ) // check if object is OK if (JagAuto
null) // Error document.writeln(site.GetEr
rorInfo()) else // Perform Processing
...
59Centralizing the Jaguar server location
// JagUtils.ssc function getJagObject(component_c
lass) var JagLoginUser"" var
JagLoginPwd"" return getJagObjectLogin(comp
onent_class, JagLoginUser, JagLoginPwd) functi
on getJagObjectLogin(component_class,
JagLoginUser, JagLoginPwd) var
JagServer"iiop//localhost9000" JagObject
java.CreateComponent(component_class,
JagServer, JagLoginUser, JagLoginPwd) return
JagObject
60Accessing a Jaguar Component - code
import scripts/JagUtils.ssc // Create Jaguar
component JagAuto getJagObject(AutoNet/auto)
// check if object is OK if (JagAuto null)
// Error document.writeln(site.GetErrorInfo()
) else // Perform Processing ...
61Calling methods on Jaguar component
- Call methods using DynaScript syntax
- convert any variables to proper CORBA-Java
data-types before calling method - import scripts/JagUtils.ssc
- // Create Jaguar component
- JagAuto getJagObject(AutoNet/auto)
- // check if object is OK
- if (JagAuto ! null)
- rc JagAuto.myFunc()
62Passing arguments by reference
- Java cannot pass simple data types by reference
- Java can pass objects by reference
- CORBA IDL provides mechanism (Holder)
- CORBA inout parameter is same as by reference
- Holder object used to pass inout parameters
- Holder object described with IDL and generated by
Jaguar CTS automatically
63Passing arguments by reference cont.
- CORBA inout parameter is actually different data
type in Java
Java data type (in parameter)
Jaguar/CORBA data type
Java data type (inout, out parameter)
java.lang.String
string
org.omg.CORBA.StringHolder
64Passing arguments by reference cont.
Holder class for String final public class
StringHolder public String value public
StringHolder() public StringHolder(String
initial_value) value initial_value
65Passing arguments by reference cont.
Holder class example // declare String
variable var Msg // Create
Holder MsgHolder java.CreateObject(org.omg.COR
BA.StringHolder,Msg) // Call Jaguar
method-pass string by reference rc
JagComp.myFunc(MsgHolder)
66CORBA Holder
PowerDynamo
Jaguar CTS
java
String Mike
Jaguar component
Java VM
StringHolder value
.class file
Mike
Mike
.class file
Java stub
67CORBA Holder cont.
PowerDynamo
Jaguar CTS
java
String Angela
Jaguar component
Java VM
StringHolder value
.class file
Angela
Angela
.class file
Java stub
68Getting value out of the Holder
- PowerDynamo cannot access properties of Java
class via dot notation unless they have get and
set methods. - Use Dave Wolfs JavaWrappers.ssc file
- import JavaWrappers.ssc
- ...
- // Call Jaguar method-pass string by reference
- rc JagComp.myFunc(MsgHolder)
- // Get a JavaHelper to access the Holder class
- jHelper new JavaFieldHelper(MsgHolder)
- // Get the value out of the Holder
- Msg jHelper.getString("value")
69Handling a structure
- Structure described in IDL as a data type and the
Java class is generated automatically by Jaguar
CTS - Structure
- Cannot have structure with more than 22 elements.
- Need to initialize elements before creating
structure - Cannot access elements using dot notation - use
JavaWrappers.ssc
Java data type (in parameter)
Jaguar/CORBA data type
Java data type (inout, out parameter)
str_auto
str_auto
str_autoHolder
70Handling a structure - code 1
// Initialize Auto Structure elements
AutoName"" AutoMakerID0
AutoMakerName"" AutoTypeID0
AutoTypeName"" AutoPicture""
AutoDesc"" MSRP"" AutoYear""
...
71Handling a structure - code 2
... // Create Auto Structure str_auto
java.CreateObject("AutoNet/str_auto",
parseInt(AutoID), AutoName, parseInt(AutoMakerID),
AutoMakerName, parseInt(AutoTypeID),
AutoTypeName, AutoDesc, AutoPicture, MSRP,
AutoYear ) // determine if object is OK if
(str_auto null) document.writeln(site.GetErr
orInfo()) // Create Auto Structure
Holder str_autoHolder java.CreateObject("AutoNet
/str_autoHolder", str_auto) if (str_autoHolder
null) document.writeln(site.GetErrorInfo())
...
72Handling a structure - code 3
// Get Auto Info rc JagAuto.getauto(AutoID,
str_autoHolder) if (rc 1) // Get Data from
Auto Structure // Get Auto Structure from
Holder str_autoHolder_jHelper new
JavaFieldHelper(str_autoHolder) str_auto
str_autoHolder_jHelper.getObject("value")
// Get values out of Auto
Structure str_auto_jHelper new
JavaFieldHelper(str_auto) AutoName
str_auto_jHelper.getString("name") AutoMakerID
str_auto_jHelper.getInt("auto_maker_name") .
.. AutoYear str_auto_jHelper.getString("year")
...
73Handling a ResultSet
- Useful for passing multiple instances of data
- Need to convert to/from CORBA result set and JDBC
result set - Work with JDBC result set same as in Java
- com.sybase.CORBA.jdbc11.SQL
- com.sybase.CORBA.jdbc11.IDL
Java data type (in parameter)
Jaguar/CORBA data type
Java data type (inout, out parameter)
TabularResults.ResultSet
TabularResultsResultSet
TabularResults.ResultSetHolder
74Handling a ResultSet - code
// Get resultset from Jaguar rs
JagAutoColor.getlistbyauto(AutoID) // Convert
IDL ResultSet to java.sql.ResultSet jQuery
java.CallStaticMethod("com.sybase.CORBA.jdbc11.SQL
", "getResultSet", rs) // Dynamically create
SELECT (dropdownlist) document.writeln("ltSELECT
NAMEauto_color_idgt") // Loop through the
rows while (jQuery.next()) // Get
ColumnValues autocolor jQuery.getString("col
or") autocolorID jQuery.getInt("auto_color_
id") document.writeln('ltOPTION
VALUE"' autocolorID '"gt')
document.writeln(autocolor)
document.writeln("lt/OPTIONgt") // end while
loop document.writeln("lt/SELECTgt")
75PowerDynamo ResultSet file
- PowerDynamo includes a script to handle Result
Sets - javaqry.ssc located in system/utils folder
- import /system/utils/javaqry.ssc
- // Get resultset from Jaguar
- rs JagAutoColor.getlistbyauto(AutoID)
- // get JavaQuery class
- jQuery new JavaQuery(rs)
- // move pointer to first row
- jQuery.moveNext()
- ...
76Handling an array
- PowerDynamo cannot use Java array indexes
- use java.lang.reflect.Array class
- CORBA IDL and arrays
- sequence is unbounded 1 dimensional array of any
IDL defined type. - sequence maps to a Java array
- sequence IDL data type generated automatically by
Jaguar - Passing an inout parameter requires a Holder
77Handling an array - code
... // PowerDynamo Array PDArray new
Array PDArray0 "Test1" // Java Array -
CORBA sequence // 1. Create datatype for
array JavaString_Class java.CallStaticMethod("ja
va.lang.Class", "forName", "java.lang.String")
// 2. Create array JavaArray
java.CallStaticMethod("java.lang.reflect.Array",
"newInstance", JavaString_Class, 2) // 3.
Populate Java array from PD array for (var
i0iltPDArray.lengthi) java.CallStaticMethod
("java.lang.reflect.Array", "set", JavaArray, i,
PDArrayi) // 4. Call Jaguar Component
method x JagData.sendarray(JavaArray)
78Sample Application AutoNet
- ASA application database
- Jaguar Database Connection Cache
- Jaguar Components
- AutoNet package
- PowerDynamo Web site
- PowerDynamo pages
79Sybase in Action Sites using EAServer
www.vactionoutlet.com
www.france98.com
www. eappraiseit.com
www.nsga.com
www.sybaseopen.com
80Q A