Allgemeines
Der Web Application Server (WAS) ist die Weiterentwicklung
des SAP Application Server. Dieser unterstützt nativ die Protokolle
HTTP(S) und SMTP. Dafür war früher der ITS (Internet Transaction
Sever) und das Modul SAP Connect notwendig.
Webanwendungen werden in sogenannten BSP's (Buissines Sever
Pages) erstellt. Hier kann HTML Code mit ABAP gemischt werden. Zur Trennung von
Verarbeitungslogik und Darstellung können verschiedene Events und eine
Anwendungsklasse verwendet werden.
Vorraussetzungen
Für das folgende Projekt wird ein WAS in der Version
6.10 benötigt. Dieser kann als Evaluierungsversion für Linux
kostenlos unter der Adresse:
http://www.sap.com/solutions/technology/linux/eval/was/
bestellt werden.
Vorbereitung
Der WAS muss für den Zugriff auf einen LDAP Sever
konfiguriert werden. Dies ist in der
Web
Application Server Hilfe beschrieben.
Implementation der Anwendungsklasse Z_LDAP_TELEFONBUCH
Zur besseren Kapselung der LDAP Abfragen und Aufbereitung
der Daten wurde die Buisiness Logik in die Anwendungsklasse Z_LDAP_TELEFONBUCH
ausgelagert. Diese Klasse ist im folgenden PDF Dokument erläutert:
z_ldap_telefonbuch
Implementation der BSP Seite - Suche
Seitenattribute
Attribut |
Auto |
Type |
Bezugstyp |
abteilung |
|
TYPE |
STRING |
attribut_typ |
|
TYPE |
CHAR1 |
c |
x |
TYPE |
STRING |
department |
x |
TYPE |
STRING |
dn |
x |
TYPE |
STRING |
givenName |
x |
TYPE |
STRING |
HOLDSESS |
|
TYPE |
LDAPDEFS-HOLD |
it_entry |
|
TYPE |
LDAPETAB |
l |
x |
TYPE |
STRING |
land |
|
TYPE |
STRING |
l_filter |
|
TYPE |
LDAPDEFS-FILT |
ort |
|
TYPE |
STRING |
reset |
x |
TYPE |
STRING |
server |
|
TYPE |
LDAPSERVER-SERVERID |
sn |
x |
TYPE |
STRING |
telefonliste |
|
TYPE |
ZTTELEFONLISTE |
Layout
<%@page language="abap"%>
<html>
<head>
<title> LDAP Suche </title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function f(){
document.s.sn.focus();
}
//-->
</SCRIPT>
</head>
<body ONLOAD="f()">
<form NAME="s">
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="sn" value="<%=sn%>"></td>
<td>Vorname:</td>
<td><input type="text" name="givenName" value="<%=givenName%>"></td>
<td colspan="2" align="center">
<input type="hidden" name="OnInputProcessing(suchen)">
<input type="submit" name="OnInputProcessing(suchen)" value="Suchen">
<input type="submit" name="reset" value="Reset">
</td>
</tr>
<tr>
<td>Abt.:</td>
<td><%=abteilung%></td>
<td>Ort:</td>
<td><%=ort%></td>
<td>Land:</td>
<td><%=land%></td>
</tr>
</table>
</form>
<!-- l_filter = <%=l_filter%> -->
<!-- HOLDSESS = <%=HOLDSESS%> -->
<!-- department = <%=department%> -->
<!-- c = <%=c%> -->
<!-- l = <%=l%> -->
<%
DATA: wa_telefonliste like line of telefonliste.
if telefonliste is not initial. %>
<table border="1">
<tr>
<th>Titel</th>
<th>Name</th>
<th>Vorname</th>
<th>Abt.</th>
<th>Telefon</th>
<th>Fax</th>
<th>Mobil</th>
<th>eMail</th>
<th></th>
</tr><%
loop at telefonliste into wa_telefonliste. %>
<!-- dn = <%=wa_telefonliste-dn%> -->
<tr>
<td><%=wa_telefonliste-title%></td>
<td><%=wa_telefonliste-Name%></td>
<td><%=wa_telefonliste-Vorname%></td>
<td><%=wa_telefonliste-Abteilung%></td>
<td><%=wa_telefonliste-Telefon%></td>
<td><%=wa_telefonliste-Fax%></td>
<td><%=wa_telefonliste-mobile%></td>
<td><% if wa_telefonliste-EMail is not initial.
%><a href="mailto:<%=wa_telefonliste-EMail%>"><%=wa_telefonliste-EMail%></a><%
endif. %></td>
<td><a href="start.htm?OnInputProcessing(detail)&dn=<%=wa_telefonliste-dn%>">Detail</a></td>
</tr><%
endloop. %>
</table><%
endif. %>
</body>
</html>
Eventhandler OnRequest
* the handler is called whenever a request is made for a particular page
* it is used to restore the internal data structures from the request
*
* Select Boxen aufbauen.
*
call method application->get_select_box
exporting
selected = l
name = 'l'
importing
select_box = ort.
call method application->get_select_box
exporting
selected = c
name = 'c'
importing
select_box = land.
call method application->get_select_box
exporting
selected = department
name = 'department'
importing
select_box = abteilung.
Eventhandler OnInitialization
* event handler for data retrieval
data: flag type c,
u_name type string value 'NONE',
session_id type string value 'NONE'.
call method cl_bsp_server_side_cookie=>get_server_cookie
exporting
name = 'Z_LDAP'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = u_name
session_id = session_id
data_name = 'flag'
* IMPORTING
* EXPIRY_DATE =
* EXPIRY_TIME =
changing
data_value = flag.
if flag is initial.
call method application->update_table.
flag = 'X'.
* texte im serverseitigen cookie abspeichern
call method cl_bsp_server_side_cookie=>set_server_cookie
exporting
name = 'Z_LDAP'
application_name = runtime->application_name
application_namespace = runtime->application_namespace
username = u_name
session_id = session_id
data_name = 'flag'
data_value = flag
* EXPIRY_TIME_ABS =
* EXPIRY_DATE_ABS =
expiry_time_rel = 7200
* EXPIRY_DATE_REL =
.
endif.
Eventhandler OnInputProcessing
* event handler for checking and processing user input and
* for defining navigation
*
* Deklarationen
*
data:
wa_telefonliste like line of telefonliste,
wa_entry like line of it_entry,
it_attributes_in type ldapastab,
wa_attributes_in like line of it_attributes_in.
*
* Der Resetknopf wurde betätigt
*
if reset is not initial.
clear: department, l, c.
*
* Select Boxen aufbauen.
*
call method application->get_select_box
exporting
selected = l
name = 'l'
importing
select_box = ort.
call method application->get_select_box
exporting
selected = c
name = 'c'
importing
select_box = land.
call method application->get_select_box
exporting
selected = department
name = 'department'
importing
select_box = abteilung.
endif.
*
* Wurde die Suche gestartet und ist ein Feld gefüllt?
*
if event_id = 'suchen'
and ( sn is not initial or
givenname is not initial or
c is not initial or
l is not initial or
department is not initial ).
*
* Suchstring festlegen
*
l_filter = '(&(objectClass=person)'.
* Name
if sn is not initial.
concatenate l_filter '(sn=' sn '*)' into l_filter.
endif.
* Vorname
if givenname is not initial.
concatenate l_filter '(givenName=' givenname '*)' into l_filter.
endif.
* Abteilung
if department is not initial.
concatenate l_filter '(department=' department ')' into l_filter.
endif.
* Ort
if l is not initial.
concatenate l_filter '(l=' l ')' into l_filter.
endif.
* Land
if c is not initial.
concatenate l_filter '(c=' c ')' into l_filter.
endif.
concatenate l_filter ')' into l_filter.
*
* Welche Attribute sollen gelesen werden
*
wa_attributes_in-typ = 'C'.
wa_attributes_in-name = 'title'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'sn'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'givenname'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'department'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'telephoneNumber'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'facsimileTelephoneNumber'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'mobile'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'mail'.
append wa_attributes_in to it_attributes_in.
*
* LDAP Abfrage
*
call method application->ldap_read
exporting
base = 'DC=company,DC=net'
scope = 2
filter = l_filter
attributes = it_attributes_in
importing
* LDAPRC =
entries = it_entry
exceptions
no_authoriz = 1
conn_outdate = 2
ldap_failure = 3
not_alive = 4
other_error = 5
others = 6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*
* Umsetzung des Abfrageergebnisses in die Telefonliste
*
call method application->get_telefonliste
exporting
it_entry = it_entry
importing
telefonliste = telefonliste.
* Telefonliste Sortieren
sort telefonliste by name vorname abteilung.
elseif event_id = 'detail'.
navigation->set_parameter( name = 'dn' value = dn ).
navigation->next_page( 'detail' ).
endif.
Implementation der BSP Seite - Detail
Seitenattribute
Attribut |
Auto |
Type |
Bezugstyp |
dn |
x |
TYPE |
STRING |
it_entry |
|
TYPE |
LDAPETAB |
telefonliste |
|
TYPE |
ZTTELEFONLISTE |
Layout
<%@page language="abap"%>
<html>
<head>
<title> LDAP Suche - Detailanzeige </title>
</head>
<body>
<h1>Detailanzeige</h1>
<%
DATA: wa_telefonliste like line of telefonliste.
if telefonliste is not initial.
loop at telefonliste into wa_telefonliste. %>
<table border="1">
<tr>
<td>Firma</td>
<td><%=wa_telefonliste-company%></td>
</tr>
<tr>
<td>Abt.</td>
<td><%=wa_telefonliste-Abteilung%></td>
</tr>
<tr>
<td>Kostenstelle</td>
<td><%=wa_telefonliste-kostenstelle%></td>
</tr>
<tr>
<td>Anrede</td>
<td><%=wa_telefonliste-title%></td>
</tr>
<tr>
<td>Name</td>
<td><%=wa_telefonliste-Name%></td>
</tr>
<tr>
<td>Vorname</td>
<td><%=wa_telefonliste-Vorname%></td>
</tr>
<tr>
<td>Strasse</td>
<td><%=wa_telefonliste-STREETADDRESS%></td>
</tr>
<tr>
<td>Postfach</td>
<td><%=wa_telefonliste-POSTOFFICEBOX%></td>
</tr>
<tr>
<td>Postfach PLZ</td>
<td><%=wa_telefonliste-poboxcode%></td>
</tr>
<tr>
<td>PLZ</td>
<td><%=wa_telefonliste-POSTALCODE%></td>
</tr>
<tr>
<td>Ort</td>
<td><%=wa_telefonliste-l%></td>
</tr>
<tr>
<td>Bundesland</td>
<td><%=wa_telefonliste-st%></td>
</tr>
<tr>
<td>Land</td>
<td><%=wa_telefonliste-c%></td>
</tr>
<tr>
<td>Telefon</td>
<td><%=wa_telefonliste-Telefon%></td>
</tr>
<tr>
<td>Fax</td>
<td><%=wa_telefonliste-Fax%></td>
</tr>
<tr>
<td>Mobil</td>
<td><%=wa_telefonliste-mobile%></td>
</tr>
<tr>
<td>eMail</td>
<td><% if wa_telefonliste-EMail is not initial.
%><a href="mailto:<%=wa_telefonliste-EMail%>"><%=wa_telefonliste-EMail%></a><%
endif. %></td>
</tr>
</table><%
endloop.
endif. %>
</body>
</html>
Eventhandler OnInitialization
* event handler for data retrieval
data: it_attributes_in type ldapastab,
wa_attributes_in like line of it_attributes_in,
base type ldap_dns.
*
* Welche Attribute sollen gelesen werden
*
wa_attributes_in-name = 'sn'.
wa_attributes_in-typ = 'C'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'givenname'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'department'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'telephoneNumber'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'facsimileTelephoneNumber'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'mobile'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'mail'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'streetAddress'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'company'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'postOfficeBox'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'postalCode'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'st'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'title'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'l'.
append wa_attributes_in to it_attributes_in.
wa_attributes_in-name = 'c'.
append wa_attributes_in to it_attributes_in.
* POBOXCODE
wa_attributes_in-name = 'extensionattribute1'.
append wa_attributes_in to it_attributes_in.
* KOSTENSTELLE
wa_attributes_in-name = 'extensionattribute4'.
append wa_attributes_in to it_attributes_in.
*
* LDAP Abfrage
*
base = dn.
call method application->ldap_read
exporting
base_string = base
scope = 2
filter = '(&(objectclass=*))'
attributes = it_attributes_in
importing
* LDAPRC =
entries = it_entry
exceptions
no_authoriz = 1
conn_outdate = 2
ldap_failure = 3
not_alive = 4
other_error = 5
others = 6
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*
* Umsetzung des Abfrageergebnisses in die Telefonliste
*
call method application->get_telefonliste
exporting
it_entry = it_entry
importing
telefonliste = telefonliste.
|