Download Technical White Paper

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Technical White Paper
Installing
Java Mail and Run
Command
Installation
With this document you can install the Caffo Java Mail and Run Command. There must
be also a SMTP mail server. The version of your database must be at least 8i with the
JServer installed. You can check this by logging on to the Oracle Database with
SQL*Plus. Normally you should get the following message:
SQL*Plus: Release 8.1.7.0.0 - Production on Tue Jan 16 17:55:53 2001
(c) Copyright 2000 Oracle Corporation.
All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production
SQL>
When the JServer is installed, you can upload the java-objects into the database. This can
be done with the “loadjava” tool from Oracle.
First you must open a command prompt. Then go to the folder with the Caffo Java
Objects (ex. c:\caffo10\Java\Database\classes). Type the following command in the
command prompt (don’t forget to adjust the username and password!!!):
loadjava -force -resolve -user am/am@caffo10
be/rhea/database/mail/Base64OutputStream.class
be/rhea/database/mail/InetDate.class
be/rhea/database/mail/InetOutputStream.class
be/rhea/database/mail/SMTPMessage.class
be/rhea/database/mail/SMTPEngine.class
be/rhea/database/mail/SendMail.class
be/rhea/database/runcommand/RunCommand.class
This command will upload all the java-classes into the database. To check if everything is
ok you must logon in SQL*Plus with the AM-schema owner.
Use the following select:
Column class format a40;
SELECT dbms_java.longname(object_name) class, status FROM
user_objects
WHERE object_type='JAVA CLASS'
AND dbms_java.longname(object_name) like 'be/rhea/database%'
Normally you should get the following output:
CLASS
---------------------------------------be/rhea/database/mail/InetOutputStream
be/rhea/database/mail/SendMail
be/rhea/database/mail/SMTPMessage
be/rhea/database/mail/Base64OutputStream
be/rhea/database/runcommand/RunCommand
be/rhea/database/mail/SMTPEngine
be/rhea/database/mail/InetDate
STATUS
------VALID
VALID
VALID
VALID
VALID
VALID
VALID
When the object status is not VALID you can change this with the following commands:
alter
alter
alter
alter
alter
alter
alter
java
java
java
java
java
java
java
class
class
class
class
class
class
class
"be/rhea/database/mail/InetOutputStream" compile;
"be/rhea/database/mail/SendMail" compile;
"be/rhea/database/mail/SMTPMessage" compile;
"be/rhea/database/mail/Base64OutputStream" compile;
"be/rhea/database/runcommand/RunCommand" compile;
"be/rhea/database/mail/SMTPEngine" compile;
"be/rhea/database/mail/InetDate" compile;
If all the objects are valid, than you can create the java wrapper functions. You can do
this with the following commands (you can also use “<Caffo-dir>\am\sql\
Caffo_Java_Mail.sql”):
DROP PUBLIC SYNONYM CAFFO_SEND_MAIL;
REVOKE EXECUTE ON Caffo_Send_Mail FROM AM_ADMIN10, AM_USERS10;
Create or Replace FUNCTION Caffo_Send_Mail (body
IN Varchar2,
dest
IN VARCHAR2,
subj
IN VARCHAR2,
cc
IN VARCHAR2,
sender
IN VARCHAR2,
server
IN VARCHAR2,
file
IN VARCHAR2,
port
IN VARCHAR2,
username IN VARCHAR2,
password IN VARCHAR2)
RETURN Varchar2 AUTHID DEFINER IS
LANGUAGE JAVA NAME 'be.rhea.database.mail.SendMail.send
(java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String,
java.lang.String) return
java.lang.String';
/
Create public synonym Caffo_Send_Mail for Caffo_Send_Mail;
GRANT EXECUTE ON Caffo_Send_Mail TO AM_ADMIN10, AM_USERS10;
DROP PUBLIC SYNONYM RUNCOMMAND;
REVOKE EXECUTE ON RUNCOMMAND FROM AM_ADMIN10;
Create or Replace FUNCTION RUNCOMMAND10 (command
IN Varchar2,
waitforexit IN VARCHAR2) RETURN number AUTHID DEFINER
IS
LANGUAGE JAVA NAME
'be.rhea.database.runcommand.RunCommand.run(java.lang.String,
java.lang.String) return int';
/
Create public synonym RUNCOMMAND for RUNCOMMAND;
GRANT EXECUTE ON RUNCOMMAND TO AM_ADMIN10;
After this you must grant the AM owner the necessary rights to create a socket
connection to the mail server, and execute programs on the operating system. Therefore
you must connect with the SYSTEM user and execute the command (parameter 1 is the
name of the AM owner and parameter 3 is the IP-address of the mail server):
Begin
Dbms_java.grant_permission('AM','java.net.SocketPermission','10.0.10
.70:25','connect, resolve’);
End;
commit;
The AM owner must also have rights to read and execute any files on the filesystem. This
is important for sending mails with attachments and executing os-commands with the job
scheduler. Please execute the following command with the SYSTEM user (parameter 1 is
the name of the AM-owner, parameter 3 is the folder where the users can read the files):
.
Begin
Dbms_java.grant_permission('AM','java.io.FilePermission','<<ALL
FILES>>','read,execute');
Dbms_java.grant_permission('AM','java.lang.RuntimePermission','write
FileDescriptor',null);
Dbms_java.grant_permission('AM','java.lang.RuntimePermission','readF
ileDescriptor',null);
End;
commit;
If everything is ok, you can send mail, and execute commands from the database. Use the
following script to test this functionality.
DECLARE
return_value VARCHAR2(2000);
BEGIN
-- Now call the stored program
-- FUNCTION Caffo_Send_Mail (body
IN Varchar2,
-dest
IN Varchar2, (multiple
recipents are seperated with a comma ",")
-subj
IN Varchar2,
-cc
IN Varchar2, (multiple
recipents are seperated with a comma ",")
-sender IN Varchar2,
-server IN Varchar2,
-file
IN Varchar2, (multiple files
are seperated with a comma ",")
-port
IN Varchar2,
-username IN Varchar2, (for
authentication)
-password IN Varchar2)
-- RETURN VARCHAR2
return_value := caffo_send_mail('test body',
'[email protected]',
'test subject',
null, --No CC
'[email protected]',
'10.0.10.70', --Mailserver
null, -- No file attached
null, -- default 25
null, -- No username
null -- No password);
-- Output the results
Dbms_output.put_line (SubStr ('return_value = '||return_value,
1,255));
- Now call the stored program
return_value := runcommand('Calc',’TRUE’);
-- Output the results
dbms_output.put_line(SubStr('return_value =
'||TO_CHAR(return_value), 1, 255));
END;
The returning value of the mail call can be:
0: Normal
1: Missing parameters
2: unable to connect with server
3: wrong initial response from server
4: error in negotiation with server
5: wrong from address
6: error while sending recipients
7: error while sending CC
8: error while sending data
9: error in end negotiation
The returning value of the runcommand call is the return code of the command being called.