Tuesday, September 13, 2011

Windows firewall blocks access to Apache Tomcat service from remote computer

Today, my colleague installed Tomcat as windows service on a Windows 7 box, strangely he could access via http://127.0.0.1:8080 and http://ipofserver:8080, but he could not access http://ipofserver:8080 from a remote computer. After some digging, it turns out to be the Windows 7 firewall blocked the remote access traffic. The solution of the problem is simple: just manually start the tomcat7.exe, Windows 7 will show the firewall warning dialog, just allow access.;-)

Tuesday, August 30, 2011

JNI Refreshment

Today one of my colleague asked me some questions on JNI implementation. The knowledge seems fading away from me. To avoid it happens again, I recorded the basic steps:
  1. Delare your native methods in a normal Java class, for example, HelloJNI.java.
  2. javac the java file(HelloJNI.java).
  3. javah -jni HelloJNI to generate the .h file(s).
  4. Write your native code, using the .h file generated in step 3; copy the function prototye from the .h file into your .c file.
  5. compile by using Visual Studio 2005 command shell(cl command).
  6. Modify your java class to load the library; recompile it; ready to run it!!!
Reference:
  1. http://java.sun.com/docs/books/jni/html/jniTOC.html
  2. http://patriot.net/~tvalesky/jninative.html
  3. http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html#comp
  4. command to compile your c file: c:\test\jnitest>cl /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include" /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include\win32" -LD HelloJNI.c -Felibnative.dll
  5. JNI in package

Thursday, July 07, 2011

Decoding IBM DB2 error message

Ever get an IBM DB2 error message like "SQL0407N Assignment of a NULL value to a NOT NULL column TBSPACEID=n1, TABLEID=n2, COLNO=n3 is not allowed. What actually does "TBSPACEID=n1, TABLEID=n2, COLNO=n3" mean? Don't ask me, you should ask IBM DB2, but how?

SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME

Wednesday, January 05, 2011

Install Oracle Developer Suite 10g on Windows 7 (64bit)

Recently, I got a task to install Oracle Developer Suite on Windows 7(64bit), but there seems lots of hassles to achieve this goal. There is a thread on Oracle forum on that topic. Here I log what I did to get it installed on my Windows 7(64bit) with 8G RAM.
  • extract the setup files (version 101202) downloaded from otn.
  • right click the install\setup.exe property, set compatibility to Windows XP SP2
  • edit the virtual memory size to custom size from 1024m to 8000m, restart it
  • run the install\setup.exe
Hope this helps.

Saturday, December 04, 2010

Oracle 11g alert log location

Oracle alert log contains much useful information about your Oracle database, but do you know where is it located and how could you find it out?
  1. Connect to the database with SQL*Plus or another query tool, such as SQL Developer.

  2. Query the V$DIAG_INFO view as shown in "Viewing ADR Locations with the V$DIAG_INFO View".

  3. To view the text-only alert log, without the XML tags, complete these steps:

    1. In the V$DIAG_INFO query results, note the path that corresponds to the Diag Trace entry, and change directory to that path.

    2. Open file alert_SID.log with a text editor.

  4. To view the XML-formatted alert log, complete these steps:

    1. In the V$DIAG_INFO query results, note the path that corresponds to the Diag Alert entry, and change directory to that path.

    2. Open the file log.xml with a text editor.

Monday, September 06, 2010

How to use Android Market on Android Emulator 2.2

After some digging, finally I got android market working on Android emulator 2.2 running on Windows Vista. Here is the steps,:
  • Start SDK Setup.exe and create an AVD - android-2.2
  • Copy system.img coming with the SDK platform to the newly created AVD.
cd c:\Users\dliu\.android\avd\android-2.2.avd
copy c:\labs\android-sdk-windows\platforms\android-8\images\system.img .
  • Start the emulator by using command line:
c:\labs\android-sdk-windows\tools>emulator -avd android-2.2 -partition-size 96
  • Pull build.prop from the emulator for editing:
c:\labs\android-sdk-windows\tools>adb.exe pull /system/build.prop .
  • Comment out ro.config.nocheckin=yes line from the build.prop file just pulled out from the emulator.
  • Push back the updated build.prop file to the emuloator
C:\labs\android-sdk-windows\tools>adb.exe remount
C:\labs\android-sdk-windows\tools>adb.exe push build.prop /system/build.prop
C:\labs\android-sdk-windows\tools>adb.exe push c:\labs\r21-update-nexusone-modacocustomcustomrom-withadditions-chinese-signed\system\app\GoogleServicesFramework.apk /system/app
C:\labs\android-sdk-windows\tools>adb.exe push c:\labs\r21-update-nexusone-modacocustomcustomrom-withadditions-chinese-signed\system\app\Vending.apk /
system/app
C:\labs\android-sdk-windows\tools>adb shell rm /system/app/SdkSetup.apk
  • Stop the emulator and delete the files: userdata-qemu.img, userdata.img, cache.img
  • start the emulator by using command line again, you should get the Android Market in your emulator.

Sunday, April 25, 2010

SAP IDES 4.7

The best place to start learning SAP is to try out the SAP IDES, International Demonstration and Education System. Here are some of the default settings for IDES 4.7 after installation:
  • Client ID: 800
  • Login user/pwd: sap*/06071992
  • Login user/pwd: ddic/19920706

Saturday, April 10, 2010

How to remote debug Tomcat server code?

Either you are a developer of Tomcat or you would like to see how the Tomcat works in a live mode, you may want to set a few break points in the Tomcat codes and to see the code in the live run. How could you set up remote debug for tomcat? Thanks for the JPDA(Java Platform Debug Architecutre) we can easily achieve this goal.
  • Start tomcat server with remote debug enabled with JVM parameters: -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y and make sure you setting suspend=y to let the tomcat server suspend and wait for debugger to attach to it.
  • Start your debugger, I am using Intellij Remote Debug, and here is the settings: Host: localhost Port: 8000
That is all. Happy debugging.

Sunday, April 04, 2010

Install lxml on Cygwin

To install lxml on Cygwin you need jump through a few hoops, to save who wants to get it done smoothly, I write down the necessary steps:
  • Make sure install the following package for cygwin by using Cygwin setup libxml2, libxml2-devel, libxslt, libxslt-devel, python-libxml2, python-libxslt
  • If you got lots of errors about debug format:
    • try to add -gdwarf-2 to CFLAGS
      • export CFLAGS="-gdwarf-2"

Using pip, virtualenv, and virtualenvwrapper in Cygwin

I have been using pip, virtualenv, and virtualenvwrapper in Cygwin for long time, it is pretty handy to isolate my development environment for each python projects I am working on. But I still need to think about what need to be done to setup all the pip, virtualenv, and virtualenvwrapper on Cygwin. To save my time and help anybody would like to setup the stuff on Cygwin, I recorded the process as following:
  • Use Cygwin setup to install Python for Cygwin.
  • Install easy_install in your Cygwin: download and run ez_setup.py in Cygwin.
  • Install pip by using easy_install: eazy_install pip.
  • pip install virtualenv
  • pip install virtualenvwrapper
  • add the following lines into your ~/.bashrc
    • export WORKON_HOME=/cygdrive/c/labs/virtualenvs
      source /usr/bin/virtualenvwrapper_bashrc
That is all, now you can create a new virtualenv in your Cygwin: mkvirtualenv my-first-env. You can use pip to install the specific packages you need for your virtualenv. To activate your virtualenv: workon my-first-env. To deactivate your virtualenv: deactivate. To remove the virtualenv: rmvirtualenv my-first-env.

Monday, March 29, 2010

Using HQL Console for JPA facet in Intellij

You got a complicated HQL or JPAQL in your code that has some problems, you need to verify what exactly the query is doing, how should you go ahead to test run it in your database? One option is that you can read the HQL or JPAQL and manually translate it to SQL statement and run the sql statement in your Database, however, this method is error prone and tedious. Another option is use the HQL Console came with Intellij, I found this method is easy and more accurate comparing to the previous options. Here is how I did it:
  • Create a DataSource in Intellij, let's name it datasource_1
  • Go to the Project->View:J2EE structure->right click the module your pojos are located in, edit the JPA facet properties to set datasource_1 maps to the desired Persistent Unit, and set the default JPA provider to: Hibernate.
  • Project->View:J2EE structure->right click the Persistent Unit, you should be able to start HQL Console.
  • You can paste your HQL or JPAQL in the HQL Console and try it out, or you can generate SQL for it and run the SQL in your DB.
Update: In Intellj 9, there is a little bit change where you can find the Persistent Unit to start HQL Console, you should click the Persistence tab on the left corner of Intellij 9.

Wednesday, December 09, 2009

Unable to access jarfile on Cygwin

Today I ran into a strange problem on Cygwin: I give the full path to the jar file for the java command, but strangely, the java runtime shows me the error message: Unable to access jarfile /cygdrive/c/pathtojar/.yuicompressor.jar. What is going on? did I have a typo? No. Then Why? After scratch my head enough, I figure out that the java in Cygwin does not like Unix format path to specify the jar file. You can use cygpath to do the trick to convert the Unix format path to mixed(-m) or windows format(-w) path, the java command will happily take it and use the jar file. Here are the two commands that works for me:
  • java -jar `cygpath -m /cygdrive/c/pathtojar/.yuicompressor.jar`
  • java -jar `cygpath -w /cygdrive/c/pathtojar/.yuicompressor.jar`

pip install python packages makes it easy

pip is easy_install replacement, and it is easy to use. Here are some features I recently used:
  1. To install something from Python Package Index, for example, Django 1.1, you just issue: pip install django, it will download it and install it.
  2. To see what Python Packages were installed by pip, you can use command: pip freeze, of course, you can redirect the output to a file and pass around.
  3. To uninstall a Python Package, for example, Django 1.1 installed in step 1, the command is: pip uninstall django.
  4. To install some Python Package you may run into error: No distributions at all found for xxxxx, you can supply the package file url to the pip install command, for example, if you want to install Django 0.96.5, here is the command: pip install http://www.djangoproject.com/download/0.96.5/tarball/, this one is pretty cool, if you can find the package gz file, then you can install it by using pip.

Friday, June 05, 2009

Install MySQL-python on Cygwin

After pulling my hairs and scavenging the Google, finally I succeeded installed the MySQL-python on Cygwin.
  • Build MySQL on Cygwin
  • Download MySQL source package from here. I was using mysql-5.0.76.tar.gz
  • configure && make && make install
  • Install MySQL-python on Cygwin
  • Download MySQL-python . I was using 1.2.2. Unzip it.
  • ./setup.py install, if you run into any problem, please have look on the readme file of the MySQL-python package. You may need to update threadSafe=False in the site.cfg file.

Wednesday, June 03, 2009

PIL error: IOError: decoder jpeg not available

After installing PIL on Cygwin, I ran into the following error while I am trying to load data from a JPEG file.
IOError: decoder jpeg not available
To solve this problem I did the following steps:
Remove the installed PIL from Cygwin:
rm -rf /usr/lib/python2.5/site-packages/PIL
rm /usr/lib/python2.5/site-packages/PIL.pth

Install libjpeg by using Cygwin setup.exe

Rerun PIL setup.py install.

unable to remap C:\cygwin\bin\tk84.dll

While installing PIL(Python Imaging Libary) on Cygwin, I ran into the following error:
5 [main] python 4388 C:\cygwin\bin\python.exe: *** fatal error - unable to remap C:\cygwin\bin\tk84.dll to same address as parent(0x410000) != 0
x700000
22 [main] python 4636 fork: child 4388 - died waiting for dll loading, errno 11
error: Resource temporarily unavailable

Fortunately, with the help of Google, it is easy to find an existing solution from Datahammer's blog:
c:\cygwin\bin\ash
cd /bin
./rebase -b 0x100000000 tk84.dll

Rerun the PIL setup.py install in Cygwin shell.

Update: If you run into remap error on Cygwin, you could try rebaseall
c:\cygwin\bin\ash
cd /bin
./rebaseall

Thursday, April 16, 2009

Unix commands help on diagnosing Weblogic problems

While working on diagnosing the Weblogic problems, I found the unix commands help me a lot, here they are:
  • Apache error_log files BackEnd errors: grep -r -h --include=error_log Backend . | awk '{print $2 " " $3}'| sort | uniq -c

  • Oracle connections: while true; do netstat -an|grep 1521; netstat -an|grep 1521|wc -l; echo "+++++++++++++++++++"; sleep 4; done;

Thursday, April 09, 2009

Google App Engine for Java Rocks!!!

I signed up GAE yesterday, and the account was activated today. It is time to play with it:
* Create Application ID
* Download and install Eclipse plugin
* Create new Web application
* Deploy application to GAE

Done!!!
It is just so easy.
More will come on this topic.

Friday, March 13, 2009

How to remote debug JMeter?

Want to remote Debug JMeter? Here I show you how I did it?
  1. Download JMeter binary package and source package, unzip them into the same directory.
  2. Rename the eclipse.classpath file to .classpath and open the project with IDEA.
  3. Open a shell, set JVM_ARGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
  4. Start JMeter in the previous shell.
  5. Setup remote debug in IDEA and start debug.

Setup JMeter JMS Publisher Sampler

Even though there are documentations on how to setup and use JMeter JMS publisher sampler, it seems all of them are either inaccurate or out of date. After pulling my hair for almost two hours, I finally made it work. To avoid headache for anybody who want to set up JMeter JMS publisher sampler, I recorded the procedure as following.

We choose ActiveMQ as our JMS provider.
  1. Copy activemq-core-5.2.0.jar, jms-1.1.jar, and geronimo-j2ee-management_1.0_spec-1.0.jar into JMeter's lib directory.
  2. Create a jndi.properties file and jar it into a jar file, put the jar file into JMeter's lib directory.
  3. Confiture the JMS publisher sampler with the following settings in the JMeter GUI.
  • Check use jndi.properties
  • Connection Factory: ConnectionFactory
  • Topic: MyTopic
  • Number of messages to aggregate: 1
Here is the content of the jndi.properties file:
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=tcp://hostname:61616
topic.MyTopic=topic

There are a few catches during the setting up process:
* The ActiveMQInitialContextFactory package name must have the apache.
* ConnectionFactory can not contain any trailing space.
* The Topic JNDI name must be prefixed with topic in the jndi file.
* You must put in the Number Of messages to aggregate, otherwise there will be no messages published.

Full Guide for using Bitnami Prometheus Operator Helm Chart with Additional Scrape Configuration

"The Prometheus Operator for Kubernetes provides easy monitoring definitions for Kubernetes services and deployment and management of...