• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IE - Java app communication

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know how to add, let's say 3, items to the context menu of internet explorer (the menu that pops up after a right click in IE).

Question: what is the simplest way to notify a concurrent java application that such an event (clicking an item on the context menu) took place, as well as to identify which one of the 3 context menu items was selected ?

Jawin ? a thread listening to Toolkit..SystemEventQueue ? JNI ?


[ August 23, 2004: Message edited by: Jan van Doorn ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My project used JNI pretty happily. We experimented with Jacob from DanAdler.com but couldn't get to the interfaces we needed in IE.
 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stan,

I checked http://www.danadler.com/jacob/index.html (came across it before), but this is java to COM, I need the other way around. I want to send notifications from my browser to a running java program. Actually, I do not need to send complex objects, a simple string (containing 1, 2 or 3) would do.

Currently thinking of using javascript... it is possible to convert a context menu click into starting a javascript contained in html. But then, how to communicate with the java program ? RMI won't work.

System events ? but how ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me your Java application could be listening on a socket - Javascript can open a HttpURLConnection to localhost:##### with a string as part of the url..
Bill
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, the limits you hit are why we stopped with Jacob for that. You can make Jacob listen for COM events, but not the ones you need from IE.
 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,

That sounds very promissing. Found on an IBM site a nice example of applying sockets:

http://www-106.ibm.com/developerworks/edu/j-dw-javasocks-i.html
(registration necessary).

Found other code snippets that showed that sockets can indeed be invoked from javascript: http://developer.netscape.com/support/faqs/champions/javascript.html#7-2

So, all I need to do is try to translate the client from the IBM-example into javascript.

Thanks for your thougths !
 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not that easy after all.. IE5 does not support java in javascript like netscape does and I have no knowledge of the microsoft stuff like VBScript, .NET, etc. But I have to work with IE5, so it is not possible to work with HttpURLConnection in javascript as William suggested.

I guess the javascript on the client side should look something like this:

<SCRIPT language="JavaScript">
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST", "http://127.0.0.1:3000", false);
xmlhttp.Send("<timesheet>An impossibly useless timesheet fragment</timesheet>");
</SCRIPT>


On the server side (standalone java application on the same machine as the IE5 browser) I have this:


public class Server {
int listenPort;
public Server(int aListenPort) {
listenPort = aListenPort;
}

public void acceptConnections() {
try {
ServerSocket server = new ServerSocket(listenPort);
Socket incomingConnection = null;
while (true) {
incomingConnection = server.accept();
handleConnection(incomingConnection);
}
} catch (BindException e) {
System.out.println("Unable to bind to port " + listenPort);
} catch (IOException e) {
System.out.println("Unable to instantiate a ServerSocket on port: " + listenPort);
}
}

public void handleConnection(Socket incomingConnection) {
try {
OutputStream outputToSocket = incomingConnection.getOutputStream();
InputStream inputFromSocket = incomingConnection.getInputStream();

BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputFromSocket));
System.out.println("Msg from client: " + streamReader.readLine());
streamReader.close();
} catch (Exception e) {
System.out.println("Error handling a client: " + e);
}
}
public static void main(String[] args) {
Server server = new Server(3000);
server.acceptConnections();
}
}


The Server class works fine in conjunction with java Client class on the same machine (originating from the IBM example classes mentioned earlier).

I invoke the javascript via the registry after a context menu selection made in IE5, however I get the following error (I translate from dutch): "Line 4, token 3: source can not be found; code 0 URL: file://c:\url.htm" (url.htm contains the javascript listed above and nothing else).

Where is the catch ??

[ August 26, 2004: Message edited by: Jan van Doorn ]
[ August 26, 2004: Message edited by: Jan van Doorn ]
 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody an idea ?
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic