kopf.lastig Alles mögliche zu Themen wie Familie, Beruf, Medien etc. …

2013-08-23

Default timeouts for network connections in Java

Filed under: Java — Schlagwörter: , — Erik @ 14:07

You often find the answer to „How do I set default timeouts for (outgoing) network connectins in Java“ is

[sourcecode language=“java“]
System.setProperty(„sun.net.client.defaultReadTimeout“, „30000“);
System.setProperty(„sun.net.client.defaultConnectTimeout“, „30000“);
[/sourcecode]

But this may or may not work. Because, as stated by Sun in 2005:

Yes, it [the default timeout] is cached, or more precisely it is looked up only at startup time. This is by design.

Playing around with the code in the bug database entry linked to above and netcat, I found that it is also true for Java 6. Chances are high that it is true for Java 7, too.

What is meant by „startup time“ is using some network connection, e.g. HttpURLConnection. That means if there has some network connection been used before the properties are programmatically set, no network connections will use these timeout values!! If you set these properties in the JEE ContextListener or some startup-servlet they may have no impact anymore because your web container may already have used a network connection. Better use the commandline to pass these parameters.

2013-08-21

Using Outlook through VB Script

Filed under: Software-Entwicklung — Erik @ 16:45

To automate MS Outlook, you usually use macros (written in Visual Basic for Applications aka VBA). But often, company security policies denies access to Outlook Macros. But you can still use VB Script aka VBS.

Here I show two scripts that copy parts of an Outlook email to the Windows clipboard. A third script forwards all selected mails to an email address. I am not an VBS expert but have put them together from various other scripts and solutions around the web.

I use these scripts with Windows XP and Outlook 2003.

Copy mail content to clipboard

I use Emacs org-mode as an TODO-List and journaling application. When I want to reference an email in a task or journal entry I can either quote the email or link to it. The easiest way is to get the appropiate content into the clipboard and yank it in the org-mode buffer.

As far as I know, the Windows clipboard is directly available to VBA scripts. But not so for VB scripts. According to the net, there are several workarounds. The one I use here makes use of the Internet Explorer Object: it opens the „about:blank“ page and gets access to the clipboard through its „parentwindow“ property. To avoid a security question I added „about:blank“ to the list of local sites in the Internet Explorer security settings.

https://gist.github.com/anonymous/68f74fe8c829c4e3ddbc

In org-mode you can have links and using org-outlook you can have links to specifc outlook message. You need the GUID of the specific message. One caveat here: that GUID changes when you move that message to a different folder.

https://gist.github.com/anonymous/ffcbdb7798afa2204025

Mass forward emails

The Outlook API provides an method to forward a mail. It behaves just like you would hit „forward“ in the GUI. Fill the recipient with a mail address and call the mail’s „send“ method. But wait: there will be a security questions that will ask you to confirm that you really want to send this mail. You have to wait 5 seconds to confirm it. This slows down mass forwarding… The following script loops through all selected mails in Outlook and forwards them.

https://gist.github.com/anonymous/b2f33210d69f5ecafad6

I have seen one trick that claims to await the 5-second-confirmation-dialog: it uses some other VB object to simulate a „Alt-S“ keystroke so that it seems the user himself press „Send“ in the GUI. Don’t know if that works.

Assign keyboard shortcuts

I created shortcuts on the desktop to these scripts. For the first two scripts I assigned keyboard shortcut (C-F7 and C-S-F7 resp.) That way I do not need to navigate to the script to execute it.

Powered by WordPress