Sunday, September 14, 2014

Book Review: Apache Camel Developer's Cookbook


I got a chance to review the "Apache CamelDeveloper's Cookbook" by Cranton and Korab. Overall I think this is a great book. System integration problems and solutions come in many forms, so getting started by reading on some proven solution recipes is definitely a good way to improve your skill. This book provides more than 100 examples on how to solve integration problems with Camel framework; from simple standalone Java application to testing, transaction, monitoring and even a chapter on web services. Each example comes with brief explanations and further reading references. My favorites are the side notes sprinkled throughout each recipe. Clearly these great tips can only have came from well experienced Camel developers who has spent time on the field.

As many cookbook style, the book can only go to certain length with each example on explanation and teaching, but readers may dig much deeper by using the sample code provided by this book. In fact I think it's really cool that it's available through GitHub as well. Check it out at http://github.com/CamelCookbook/camel-cookbook-examples. (although I think there is a typo in the book for this URL on the copy I have! ^_^) The sample code are complete, clean and easy to follow for each recipe example. The source code is in Maven based project, so you will get all the dependencies needed by just running the "install" phase. Open by any major IDE and you will start reading and compiling immediately. Because it's using Maven, you can also download the Camel dependencies with Source, and you can jump right into the framework code itself to analyze what's behind this cool project.

Because it's a cookbook, it does not go into too deep about Camel internal. But through the examples, many of the core concepts of Camel has been touched; and it serves as a great example and can be used as handy reference book. Because it covers the Camel concept briefly, it expected you to know little bit of the integration knowledge and background though. Things like Enterprise Integration Patterns and transport technologies used such as File, FTP, SEDA, JMS etc. The book also comes with many Spring based XML configuration examples, and it expects you to know some basic knowledge of bean configuration. But the xml configuration of Camel routes itself are very self explanatory, so readers should able to follow along easily.

If you work with Camel project, or have to start an integration project, I would recommend you to check out this book.

Friday, September 5, 2014

Django with Python 3 and MySQL database


I read many folks are having problems using MySQL db driver with Python 3, especially when setting up a Django app. The default Django 1.6.5 is only supporting the MySQLdb driver and that only works with Python 2.

I have been using mysql-connector-python with Python 3 and it has built-in django support as well. I had ran into trouble like this http://bugs.mysql.com/bug.php?id=73232, but it is fixed now with the latest mysql-connector-python 1.2.3 release. The mysql-connector-python also works with Python 2.7 as well, and it's a pure python library without native code, which makes the install much easier.

When installing mysql-connector-python, ensure you allow external hosted files like this

pip install --allow-all-external mysql-connector-python

If you are behind a firewall, use the proxy option

pip install --proxy my_proxy_server --allow-all-external mysql-connector-python

With these, now you can set your Django settings.py file with MySQL engine

DATABASES = {
    'default': {
        'ENGINE': 'mysql.connector.django',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
    }
}


PS: My initial testing with Django 1.7 also works pretty well with mysql-connector-python. How sweet!

Thursday, August 21, 2014

Deploying applications or libraries to WebLogic Server using command line

Here is how you can automate deployment for WebLogic server using command line.

First source the env settings from the server:
$ source $ML_HOME/server/bin/setWLSEnv.sh

Deploy Library:
$ java weblogic.Deployer -nostage -deploy -library \
-adminurl localhost:7001 \
-username weblogic -password my_secret \
-targets myserver \
my_shared_lib.war


Deploy Application:
$ java weblogic.Deployer -nostage -deploy \
-adminurl localhost:7001 \
-username weblogic -password my_secret \
-targets myserver \
-name myapp.war myapp.war


For development, you likely want to use the "-nostage" meaning to deploy the app or library directly from the file system. This means any changes to that file location and a reload from WLS will take effect immediately.

For undeploy the command line options are same for library or app but with matching name.
$ java weblogic.Deployer -undeploy \
-adminurl localhost:7001 \
-username weblogic -password my_secret \
-targets myserver \
-name myapp_or_lib.war

Wednesday, August 20, 2014

WebLogic shared library deployment

When deploying a large WAR file application, it would be more easier to manage if we can separate the dependency jars away from the rest of the Web content; or at least those third party jars that do not update often. In this case, we usually call the jars content a "Shared Library" and the Web content the "Skinny WAR".

With WebLogic Server, you can easily deploy such two artifacts. Just seperate and package your WAR application into two. The share library would be simply another WAR with only the WEB-INF/lib content in it, while the Skinny war will be the rest of your application without the jar depependencies. On the shared lib WAR file, ensure you have an META-INF/MANIFEST.MF that specify the name and version like the following:

Implementation-Title: my_shared_lib
Implementation-Version: 1.0

Specification-Title: my_shared_lib
Specification-Version: 1.0

Extension-Name: my_shared_lib-1.0

Now your Skinny WAR would need to add an WEB-INF/weblogic.xml extension file to reference the library like this:

<weblogic-web-app>
    <library-ref>
        <library-name>my_shared_lib</library-name>
        <specification-version>1.0</specification-version>
        <implementation-version>1.0</implementation-version>
        <exact-match>true</exact-match>
    </library-ref>
</weblogic-web-app>



With these two packaged, now turn to your WLS admin console, you will find "Deployments" menu link on left, and on right, you click "Install" button. The next screen will prompt you to choose which type of deployment to install: "Library" (Shared Lib War) or "Application" (Skinny War). Re-run this twice, each with your two seperated WAR files you just built.



The WLS will combine the two when running your WAR application. This comes handy if you are to deploy multiple instances of your Skinny war application, but now you only need one shared lib.

NOTE: Ensure you select at least one, and the same Target servers where you deploy the Library and Application. Else your application will not be deployed and run.