Sunday, July 31, 2016

IReport issues with Java 8

So IReport does not work  properly with Java 8... and I had to find that out the hard way ;-)

Here I have some tips for those of you who still use IReport (3 to 5)


When running with java 8 IReport3 will not show 'library' window contents  - where you usually expect to find 'buttons' like totals, page number, current date etc. and as far as I remember IReport5 will not launch at all.
You can check which java version is used by the IReport if you go Help->About->System Properties. There you can find 'java.version' variable.

So for ireport3 the workaround is to use ireport.bat file which is located in the ireport3 root directory.
Just add to the bat file something like path="C:\Program Files\Java\jdk1.6.0_26"
so that proper java will be used to launch IReport.

For irepor 5 you can edit  ireport.conf file (e.g. iReport-5.6.0\etc\ireport.conf)
and add  jdkhome="C:\Program Files\Java\jdk1.6.0_26"   

Note that you should have java6 jdk also installed on your system for the above to work.

That's it for today... 

Monday, January 25, 2016

Thunderbird Ldap address autocomplete problem...

Recently I installed Thunderbird (email client) and hooked it up to Ldap.

I set up the LDAP server as follows:

Port(default)   :  389
Base DN          :  dc=organization, dc=com
Bind  DN         :  myuser@organization.com
Filter(default) :  (objectclass=*)


The Problem:

1. Whenever I tried  to compose a new mail - the auto-complete feature of the "To" field either wasn't working at all or brought limited number of names from the Ldap server - without bringing the name that I was looking for.

On the other hand within the address book everything worked fine (searching / finding etc).

Very strange behavior...

2. Another thing I noticed was, that whenever I tried to create local replica of LDAP catalog - download failed.

Solution:

Solution I found for those two problems was to change the default port to 3268 which is apparently port for searching in Global Catalog.

Tuesday, August 25, 2015

Is My Intranet Web Server Down?

O.K.
Without further delay -  here is a python script that will e-mail you in case a Http server you are monitoring is down (based on failed ping or failed http connection) :

http_ping.py

-------------------------------------------------------------------------------------------------------------------
import smtplib
from email.mime.text import MIMEText
import optparse, subprocess, os, sys
import re, time, datetime
from optparse import OptionParser
from os import stat
from os.path import abspath
from stat import ST_SIZE
import httplib
import sys

SLEEP_TIME = 60
email_from = ""
email_to = ""
smtp_server=""
ssl=False
smtp_user=None
smtp_password=None

def runProcess(exe):
    FNULL = open(os.devnull, 'w')
    p = subprocess.call(exe, stdout=FNULL, stderr=FNULL)

    if p == 0:
        return True
    else:
        return False

def sendAlert(state, host, debug,what):
    subject = ""
    statetext = ""

    if state == 0:
        statetext = "up"
    elif state == 1:
        statetext = "down"

    subject = "Host %s is %s" % (host, statetext)

    ts = time.time()
    f_ts = str(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))

    text = "Host " + host + " went " + statetext + " at " + f_ts + " based on " + what

    msg = MIMEText(text)
    msg[ 'From' ] = email_from
    msg[ 'To' ] = ", " + email_to
    msg[ 'Subject' ] = subject
    try:
       
        #if ssl/tls smtp
        if ssl:
            s = smtplib.SMTP_SSL(smtp_server)
            if debug: print "SSL SERVER:" +  smtp_server
        #if not encrypted
        else:
            s = smtplib.SMTP(smtp_server)
            if debug: print "PLAIN SMTP SERVER:" +  smtp_server
        if debug:
            s.set_debuglevel(True)
        #if authentication required
        if smtp_user!=None and smtp_password!=None:
            if debug: print "user and pass are set"
            s.login(smtp_user,smtp_password)
        s.sendmail(email_from, [email_to], msg.as_string())
        s.quit()
    except Exception as e:
        if debug: print "error sending email:"
        #if debug: print msg
        if debug: print e

def main():
    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    parser.add_option('-d', '--debug', action='store_true', dest='debug', default=False, help='enable debugging')
    parser.add_option('-e', '--encrypted', action='store_true', dest='ssl', default=False, help='ssl/tls smtp')
    parser.add_option('-p', '--ping', action='store', dest='host', default=None, help='specify host to ping')
    parser.add_option('-s', '--smtp', action='store', dest='smtp', default=None, help='Specify Mail Server (SMTP)')
    parser.add_option('-t', '--to', action='store', dest='mail_to', default=None, help='Specify Mail Receiver addresses')
   
   
    parser.add_option('-f', '--from', action='store', dest='mail_from', default='Http Ping', help='Specify Mail Sender address')
   
    parser.add_option('-u', '--smtp_user', action='store', dest='smtp_user', default=None, help='SMTP user (optional)')
    parser.add_option('-w', '--smtp_password', action='store', dest='smtp_password', default=None, help='SMTP password (optional)')
    parser.add_option('-z', '--sleepTime', action='store', dest='sleep', default=60, help='sleep time(optional)')
   

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit( 1 )
    (options, args) = parser.parse_args()

    if options.host == None:
        parser.print_help()
        sys.exit( 1 )

    if options.smtp == None:
        parser.print_help()
        sys.exit( 1 )

    if options.mail_to == None:
        parser.print_help()
        sys.exit( 1 )
    global  SLEEP_TIME,email_from,email_to,ssl,smtp_server
    SLEEP_TIME = int(options.sleep)
    email_from = options.mail_from
    email_to   = options.mail_to
    smtp_server=options.smtp
    ssl=options.ssl
   
   
    try:
        upflag = True
        while(True):
            if options.debug: print "pinging host: " + str(options.host)
            pingresult = runProcess(["ping", options.host])
            http_ping_result = False
            try:
                conn = httplib.HTTPConnection(options.host)
                conn.request('HEAD', '/')
                url = 'http://{0}/{1}'.format(options.host,"")
                if options.debug: print '    Trying: {0}'.format(url)
                response = conn.getresponse()
                if options.debug: print '    Got: ', response.status, response.reason
                conn.close()
                if response.status == 200:
                    if options.debug: print ("Got Response 200 " +" everything is ok")
                    http_ping_result = True   
            except:
                e = sys.exc_info()[0]
                print ' Problem in connection  ' + str(e)   
                http_ping_result = False
           
            if pingresult == False or http_ping_result==False:
                what=""
                if pingresult == False: what =what + "ping "           
                if http_ping_result == False: what =what + " http"           
                if options.debug: print "ping failed" + str(pingresult)
                if upflag == True:
                    if options.debug: print "send down email"
                    sendAlert(1,options.host,options.debug,what)
                   
                upflag = False
            else:
                if options.debug: print "ping was successful..."
                if upflag == False:
                    if options.debug: print "send up email"
                    sendAlert(0,options.host,options.debug,what)
                upflag = True
           
            if options.debug: print "sleeping for "+str(SLEEP_TIME) +"s"
            time.sleep(SLEEP_TIME)
    except (KeyboardInterrupt, SystemExit):
        #raise
        print "Exiting"
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)
        exit ( 1 )
    exit( 1 )

if __name__ == '__main__':
    main()
---------------------------------------------------------------------------------------------------------------------
usage example: 

http_ping.py -d -p my.Server.com -s my.mail.server.com -t my.mail@my.mail.com -z 30

Sunday, July 26, 2015

How to fix windows 7 weather gadget

If you were using weather gadget on windows 7, then probably (to your disappointment) you discovered one day that after some security updates - it stopped working. What a loss! :(

Luckily, it turns out that fixing the problem is not so hard after all.
All you need to do is to change modification date of a config.xml file used by the gadget.

So open your notepad as administrator (right click->run as admin) and navigate to the following path:

C:\Users\[UserName]\AppData\Local\Microsoft\Windows Live\Services\Cache 

and open  config.xml file located there.

*make sure that you replace [UserName] with the user name you are using on your machine.

Now to change the modification date you just tamper a little with your pc's clock and set it say to the year 2019, after that you 'modify' the config.xml (just type space character somewhere and then delete it) and save the changes.
That's it - your file modification date is 2019 way ahead in the future ... and the widget is working again!!

Don't forget to set your clock to correct time again.

Monday, February 2, 2015

 How to Stop Chrome Running in the Background

Well it has been a while since my last post. This time I just want to tell you how to get rid off that Chrome process which is always running in the background eating up your PC's resources. Actually it is quite simple. 

1. Open your chrome browser 

2. Select Settings 

3. Click on the link titled ‘Show advanced settings

4. Under the section headed ‘System‘ untick the box next to “Continue running background apps  when Google Chrome is closed”

 

Saturday, November 16, 2013

Glassfish hangs on leak reclaim


OK, let me tell you a painful story about a developer an application and an application server called Glassfish 3.1.2.2 ;-) Beware, this story is still in progress so I may still be updating this post till the issue is resolved.
(Forgive me my poetic mood - this post will be less technical than the previous ones ..though you will find some technical details, solutions etc in this text .. somewhere ;-)

So what the problem was/is? At the beginning it appeared to be a total mystery. After running cheerfully on the server for days or even weeks...application hangs ...and nothing could be done to bring it back to life, except for restarting the whole server (I mean the machine itself) - and we are talking about production environment here!  
Something had be done ..but what ? Fortunately, there is this monitoring tool  that came to my attention  - VisualVM and it has glassfish plugin. Installation of this product was definitely first step in the right direction.
The tool revealed that during the freeze or  'deadlock' all http thread-pool threads were waiting to lock Object which was held by "connector-timer-proxy".  Connector-timer-proxy itself was trying to reclaim a connection that was marked as 'leaked' but for some reason couldn't reclaim it. Taking a look at database connections revealed 4 inactive connections....and one active (the one that should have been reclaimed).
Killing the database connection - brought  Glassfish back to life ... everything unfreezed!
My thoughts on this one are that the connection was actually doing something (admittedly it must have been a very long operation) and thus the connection couldn't be reclaimed. Or I am wrong here? I don't know yet.
One thing I did, I set statement timeout on Glassfish. So I suppose if for some reason I have a statement running for too long ... it will be canceled first and then  if need the connection could be reclaimed without problem... Let's hope it is the case, and not the fact that I am dealing with some kind of GF's bug...(Time will show).
Anyway, if you have any ideas on this matter - don't be shy - let me know...

Sunday, July 14, 2013

Android Emulator too slow

Wanted for a while now to try out android programming without actually owning android device ... tried once with emulator which comes with android sdk and eclipse plugins  and was deeply disappointed ... too damn slow.

Fortunately there are solutions out there that are much  faster - e.g.  android-x86 that can be installed on virtual box or the VMware. Although bare in mind that some versions do not have out-of-the-box support for Internet or Sound (it takes some intervention to make these features work).

I personally use VMware (seems faster than vBox) and luckily I found an android-x86 v4.0 with Ethernet and sound enabled. If you are interested you can download the image here  http://www.buildroid.org/Download/android-x86-vm-20120307.iso.gz.

If you need instructions on how to install anroid-x86 on virtual machines just search the web as I did.

Happy android programming ! ;-)


10/01/2014 just an update.
Some useful tips if you are using Android on VMware.

1 .To find out the IP address of your virtual android device just enter terminal emulator and type:
     "netcfg"

2. To connect eclipse to Android on VM:
    a. enter command prompt on your PC: type cmd in start menu
    b. go to the directory  where android platform tools are installed
    (e.g. cd "C:\Program Files\Android\android-sdk\platform-tools")
    c. Then type adb connect <IP Address of the Android on VM>