Hi Chris,
{A brief recap} I'm the guy that knows very little of Java/Javascript/html
and have been wanting to open up a socket with Applets back to my VMS server
and interact with the html/Javascript form. . .
I said: -
But hey I just want to get this working (hopefully
by this weekend) and if you would be kind enough to look over the code then,
I would be more than happy if you could point out dependencies and where it
will fall over in a screaming heap
On the off chance you (and others) have absolutely nothing better to do this
week-end, I have followed through on my threat to publish the code I've been
working on all this time. I will include the main Applet and html/Javascript
here but the wrapping and formatting will really screw it up so if anyone's
has a passing interest, they can find a better copy at the end of this
thread: -
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1071300
The last two post of mine 27/28 Feb have attachments and explain it all.
I think it's pretty sexy and does what I (and I can't see why not everyone
else) wants, but if you could point out any architectural disasters like
Threading Issues (Synchronization? Serializable), Memory Leaks etc I would
*really* appreciate it! I don't care if I should be using Swing (or
a.n.other) instead of AWT and I will get around to tightening up what
doesn't need to be public to private, but I more interested here in what
might be fundamentaly crap as opposed to what's not pretty. Me? I think it's
shit hot!
Cheers Richard Maher
CornuCopiae.java
================
import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.IOException;
public class CornuCopiae extends Applet
{
private String username = "";
private String password = "";
private boolean pass = false;
public Tier3Socket pipe;
public String stringOut = "";
public int bytesIn;
public void init()
{
if (!authorize())
{
try
{
getAppletContext().showDocument
(new URL (getCodeBase()+"accessdenied.html"),"_top");
}
catch (Exception e) {e.printStackTrace(); }
}
}
public boolean authorize()
{
int port = Integer.parseInt(getParameter("PORT"));
int maxBuf = Integer.parseInt(getParameter("MAXBUF"));
String appl = getParameter("APPLICATION");
String hostCharSet = getParameter("HOSTCHARSET");
pipe = new Tier3Socket(getCodeBase().getHost(),
port,
maxBuf,
hostCharSet);
System.out.println("Step 3");
try {pipe.open();} catch (Exception e) {return false;}
System.out.println("Step 4");
Object parentFrame = getParent();
while ((parentFrame != null) &&
!(parentFrame instanceof Frame))
{
parentFrame = ((Component)parentFrame).getParent();
}
Frame creds = (Frame)parentFrame;
Tier3Logon logon = new Tier3Logon(creds);
requestFocus();
if (logon.logonAborted)
{
System.out.println("Logon Aborted");
}
else
{
username = logon.inUser.getText();
password = logon.inPass.getText();
pass = true;
try {pipe.handShake(username, password);}
catch (Exception e)
{
pass = false;
e.printStackTrace();
System.out.println("Logon Failed");
}
}
if (pass && logon.cb.getState())
{
Tier3Welcome welcome = new Tier3Welcome(creds, appl,
pipe.t3IdBuf);
requestFocus();
welcome.dispose();
}
logon.dispose();
System.out.println("Step 5");
return pass;
}
public void sendMessage (String message)
{
try
{pipe.sendMessage(message);}
catch (IOException e)
{return;}
}
public void sendUrgentData (int oob)
{
try
{pipe.sendUrgentData(oob);}
catch (IOException e)
{return;}
}
public int readMessage () throws IOException
{
try
{bytesIn = pipe.readMessage();}
catch (IOException e)
{return 0;}
return bytesIn;
}
public int readMessage (int bytes) throws IOException
{
try
{bytesIn = pipe.readMessage(bytes);}
catch (IOException e)
{return 0;}
return bytesIn;
}
public String getString (int offset, int length)
{
try
{stringOut = pipe.getString(offset, length);}
catch (ArrayIndexOutOfBoundsException e)
{return null;}
return stringOut;
}
public void destroy()
{
try
{pipe.close();}
catch (IOException e)
{e.printStackTrace();}
super.destroy();
}
}
Example1.html
=============
<html>
<head>
<title>
Example Client for Tier3 demo queue-lookup server
Author: Richard Maher
</title>
<style>
h2
{
color: Turquoise;
}
p.credits
{
color: Turquoise;
}
.green_screen
{
color: Lime;
background-color: Black;
font-family: courier;
}
</style>
<script type="text/javascript">
function enter(nextfield)
{
if (window.event && window.event.keyCode == 13)
{
nextfield.focus();
return false;
}
else
return true;
}
function num_only(numObj)
{
if (isNaN(numObj.value))
{
numObj.value = "";
alert("Numeric value required");
numObj.focus();
return false;
}
else
return true;
}
function job_lookup()
{
if (!num_only(document.getjobs.entry_number))
return true;
var recTypeLen = 2;
var recType = "";
var msgGetInfo = "10";
var jobInfo = "11";
var errorInfo = "00";
var zeroFill = "0000";
var maxRows = "9999";
var outPad = "";
var ok = true;
var selectRef = document.getjobs.job_list;
var msgEntry = "";
selectRef.options[0].selected=true;
var holdHdr = selectRef.options[0];
while (selectRef.options.length > 0)
{
selectRef.remove(selectRef.options[0]);
}
selectRef.options[0] = holdHdr
document.getjobs.job_list.size = 1;
msgEntry = document.getjobs.entry_number.value;
outPad = zeroFill.substring(0, (zeroFill.length - msgEntry.length));
var chan = document.getElementById("CornuCopiae");
chan.sendMessage(msgGetInfo.concat(outPad,msgEntry,maxRows));
if (chan.readMessage(recTypeLen) != recTypeLen)
{
alert ("Error receiving reply from server");
return false;
}
recType = chan.getString(0,recTypeLen);
if (recType == jobInfo)
{
ok = process_jobs(chan);
}
else
{
if (recType == errorInfo)
{
ok = process_error(chan);
}
else
{
alert ("Unknown message type " + recType);
return false;
}
}
if (!ok) return false;
document.getjobs.entry_number.focus();
return true;
}
function process_error(chan)
{
document.getjobs.rec_count.value = 0;
var errMsgLen = 0;
var errLenLen = 3;
var alertMsg = "Error retrieving job entry information\n";
if (chan.readMessage() < errLenLen)
{
alert ("Error receiving Error Length from server");
return false;
}
errMsgLen = parseInt(chan.getString(0,errLenLen),10);
alertMsg = alertMsg + chan.getString(errLenLen,errMsgLen);
alert(alertMsg);
return true;
}
function process_jobs(chan)
{
var recTypeLen = 2;
var recType = "";
var jobInfo = "11";
var eofInfo = "99";
var eofLen = 3;
var jobMsgLen = 109;
var jobMsg = "";
var rc = 1;
var eofInfo = "99";
var selectRef = document.getjobs.job_list;
for (;

{
rc = rc + 1;
if (rc < 6)
document.getjobs.job_list.size = rc;
if (chan.readMessage(jobMsgLen) != jobMsgLen)
{
alert ("Error receiving Job Information from server");
return false;
}
jobMsg = chan.getString(0,4) + "|" +
chan.getString(4,39) + "|" +
chan.getString(43,15) + "|" +
chan.getString(58,31) + "|" +
chan.getString(89,10) + "|" +
chan.getString(99,10);
selectRef.options[selectRef.options.length] = new Option (jobMsg);
if (chan.readMessage(recTypeLen) != recTypeLen)
{
alert ("Error receiving reply from server");
return false;
}
recType = chan.getString(0,recTypeLen);
if (recType != jobInfo)
break;
}
if (recType != eofInfo)
return false;
if (chan.readMessage(eofLen) != eofLen)
{
alert ("Error receiving reply from server");
return false;
}
document.getjobs.rec_count.value = (rc - 1);
return true;
}
</script>
</head>
<body>
<h2>Example Client for Tier3 DEMO application server on VMS</h2><hr>
<form name="getjobs">
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width= "0" height= "0" name="CornuCopiae"
id="CornuCopiae">
<param name="archive" value="tier3.jar">
<param name="codebase"
value="
http://1.2.3.6/">
<param name="code"
value="CornuCopiae">
<param name="mayscript" value="yes">
<param name="scriptable" value="true">
<param name="name"
value="CornuCopiae">
<param name="PORT" value="1024">
<param name="HOSTCHARSET"
value="ISO-8859-1">
<param name="MAXBUF" value="512">
<param name="APPLICATION" value="DEMO">
</object>
<br />Enter Job Entry Number [Default is All jobs]:
<input
type="text"
onkeypress="return enter(document.getjobs.send)"
name="entry_number"
maxlength=4
size=4
dir="rtl"
/>
<input
type="button"
onmouseup="job_lookup()"
name="send"
value="Get Job Info."
/>
Jobs Found:
<input
type="text"
name="rec_count"
readonly
value="0"
size=5
/>
<br /><br />
<select
name="job_list"
id="Job_list"
class="green_screen"
size=1>
<option
value="lovhdr"
selected=true
disable=true
Nbr--Job-Name--------------------------------Job Status------Queue
Name----------------------Queue Type-Status----</option>
</select>
<br />
</form>
<p>
This is an example of a browser-based, html and JavaScript,
client interacting with a VMS hosted Tier3 Application Server
in a connection-oriented and context-rich environment.<br /><br />
You would have noticed that, when this page was initially displayed,
you were immediately prompted for your VMS Username and Password.
Once authorization is successful your credentials, and an accompanying
Persona, are automatically made available to your 3GL User Action
Routines each time their Server Process is chosen to perform work on
behalf of the client. In this example, the user only gets to see those
Print and Batch jobs that they have privileges to view. You can find
the corresponding server code for this example (demo_uars.cob) in your
t3$examples directory.<br /><br />
The session and server connection are terminated when you change
web pages or refresh this page.
</p>
<hr>
<p class="credits">
"Tier3" is a registered trademark of Tier3 Software Ltd<br />
"CornuCopiae" is a trademark of Richard Maher
</p>
</body>
</html>
Richard Maher said:
Hi Chris,
Before responding to your post (and going to bed) can I ask you a quick
question: -
I'm calling my Applet like this 'var chan =
document.getElementById("myApplet")' and inside my class definition that
extends applet I have a variable "pipe" that is an instance of the
Tier3Socket class and I want JavaScript to be able to invoke methods in
"pipe" and I am getting a null pointer error if I try and say "byte_count =
chan.pipe.readMessage(2)".
a) Can I only call public methods at the Applet Class level from JS? (No big
deal)
b) If I say "var getClass = chan.pipe" can I then invoke getClass.xxx()
methods?
c) Is it just that I haven't said "public" when I declared "Tier3Socket
pipe;" (What is the default anyway?)
I will try it out but If you've got time to reply then please do.
That suggests that you may currently be relying on MS's implementation
of
Java
for your applets. If so then the relationship between Java and
JavaScript
may
be closer than you'll find it easy to achieve otherwise[*]. I don't
know
for
sure if that's true -- this is just a warning to check your design (discussed
in other threads here) to see if it's still practical when using a real
JVM/plug-in.
Everything I'm looking at (control panel, console etc) says "Sun
Microsystems Inc. Java HotSpot Client VM 1.6.0-b105"; short of running
Microsofts MSJVM remover tool, I don't know what else to do. Then Daniel
Dyer said this: -
[As far as I am
aware, there are two plugins - both wrapping the same JVM. One is an
ActiveX control and is used by Internet Explorer. The other is a plugin
that conforms to the Netscape/Mozilla plugin interface and is used by
Mozilla-based browsers.]
This would explain the difference between my Appletviewer retrieval of the
JAR file and that of IE. But hey I just want to get this working (hopefully
by this weekend) and if you would be kind enough to look over the code then,
I would be more than happy if you could point out dependencies and where it
will fall over in a screaming heap
Cheers Richard Maher
Chris Uppal said:
That suggests that you may currently be relying on MS's implementation
of
Java
for your applets. If so then the relationship between Java and
JavaScript
may
be closer than you'll find it easy to achieve otherwise[*]. I don't
know
for
sure if that's true -- this is just a warning to check your design (discussed
in other threads here) to see if it's still practical when using a real
JVM/plug-in.
-- chris
[*] If my distant memory is correct, the MS JVM exposes all Java classes as COM
objects, and their JavaScript implementation can call COM directly. Neither
are true in other environments.