<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">

<channel>
	<title>The Server Labs Blog</title>
	
	<link>http://www.theserverlabs.com/blog</link>
	<description>The technical blog of The Server Labs</description>
	<pubDate>Thu, 02 Sep 2010 08:57:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheServerLabsBlog" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="theserverlabsblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Persistence Strategies for Amazon EC2</title>
		<link>http://www.theserverlabs.com/blog/2010/07/08/ec2-persistence-strategies/</link>
		<comments>http://www.theserverlabs.com/blog/2010/07/08/ec2-persistence-strategies/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:02:20 +0000</pubDate>
		<dc:creator>Gerardo Viedma</dc:creator>
		
		<category><![CDATA[Default]]></category>

		<category><![CDATA[Amazon]]></category>

		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[Cloud Computing]]></category>

		<category><![CDATA[EC2]]></category>

		<category><![CDATA[persistence]]></category>

		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=1086</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/07/08/ec2-persistence-strategies/";</script>At The Server Labs, we often run into a need that comes naturally with the on-demand nature of Cloud Computing. Namely, we’d like to keep our team’s AWS bill in check by ensuring that we can safely turn off our Amazon EC2 instances when not in use. In fact, we’d like to take this practice [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/07/08/ec2-persistence-strategies/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>At The Server Labs, we often run into a need that comes naturally with the on-demand nature of Cloud Computing. Namely, we’d like to keep our team’s AWS bill in check by ensuring that we can safely turn off our Amazon EC2 instances when not in use. In fact, we’d like to take this practice one step further and automate the times when an instance should be operational (e.g. only during business hours). Stopping an EC2 instance is easy enough, but how do we ensure that our data and configuration persist across server restarts? Fortunately, there are a number of possible approaches to solve the persistence problem, but each one brings its own pitfalls and tradeoffs. In this article, we analyze some of the major persistence strategies and discuss their strengths and weaknesses.</p>
<h2>A Review of EC2</h2>
<p>Since Amazon introduced their EBS-backed AMIs in late 2009 [<a href="http://aws.typepad.com/aws/2009/12/new-amazon-ec2-feature-boot-from-elastic-block-store.html" target="_blank">1</a>], there has been a great deal of confusion around how this AMI type impacts the EC2 lifecycle operations, particularly in the area of persistence. In this section, we’ll review the often-misunderstood differences between S3 and EBS-backed EC2 instances, which will be crucial as we prepare for our discussion of persistence strategies.</p>
<h2>Not All EC2 Instances are Created Equal</h2>
<p>An Amazon EC2 instance can be launched from one of two types of AMIs: the traditional S3-backed AMI and the new EBS-backed AMI [<a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html" target="_blank">2</a>]. These two AMIs exhibit a number of differences, for example in their lifecycle [<a href="http://www.shlomoswidler.com/2009/07/ec2-instance-life-cycle.html" target="_blank">3</a>] and data persistence characteristics [<a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?Concepts_BootFromEBS.html" target="_blank">4</a>]:</p>
<table border="1" cellspacing="0" cellpadding="10">
<tbody>
<tr>
<td width="159" valign="top"><strong>Characteristic</strong></td>
<td width="259" valign="top"><strong>Amazon EBS</strong></td>
<td width="281" valign="top"><strong>Instance (S3) Store</strong></td>
</tr>
<tr>
<td width="159" valign="top"><span lang="EN-US">Lifecycle</span></td>
<td width="259" valign="top"><span lang="EN-US">Supports stopping and restarting of instance by saving state to EBS.</span></td>
<td width="281" valign="top"><span lang="EN-US">Instance cannot be stopped; it is either running or terminated.</span></td>
</tr>
<tr>
<td width="159" valign="top"><span lang="EN-US">Data persistence</span></td>
<td width="259" valign="top"><span>Data persists in EBS on instance failure or restart. Data can also be configured to persist when instance is terminated, although it does not do so by default.</span></td>
<td width="281" valign="top"><span lang="EN-US">Instance storage does not persist on instance shutdown or failure. It is possible to attach non-root devices using EBS for data persistence as needed.</span></td>
</tr>
</tbody>
</table>
<p>As explained in the table above, EBS-backed EC2 instances introduce a new stopped state, unavailable for S3-backed instances.  It is important to note that while an instance is in a stopped state, it will not incur any EC2 running costs. You will, however, continue to be billed for the EBS storage associated with your instance. The other benefit over S3-backed instances is that a stopped instance can be started again while maintaining its internal state. The following diagrams summarize the lifecycles of both S3 and EBS-backed EC2 instances:</p>
<p><img class="aligncenter size-full wp-image-1091" title="s3-lifecycle" src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/07/s3-lifecycle.png" alt="s3-lifecycle" width="410" height="320" /></p>
<p style="text-align: center; font-weight: bold">Lifecycle of an S3-backed EC2 Instance.</p>
<p><img class="aligncenter size-full wp-image-1092" title="ebs-lifecycle" src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/07/ebs-lifecycle.png" alt="ebs-lifecycle" width="551" height="439" /></p>
<p style="text-align: center; font-weight: bold">Lifecycle of an EBS-backed EC2 Instance.</p>
<p>Note that while the instance ID of a restarted EBS-backed instance will remain the same, it will be dynamically assigned a new set of public and private IP and DNS addresses. If you would like assign a static IP address to your instance, you can still do so by using Amazon’s Elastic IP service [<a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1346" target="_blank">5</a>].</p>
<h2>Persistence Strategies</h2>
<p>With an understanding of the differences between S3 and EBS-backed instances, we are well equipped to discuss persistence strategies for each type of instance.</p>
<h3>Persistence Strategy 1: EBS-backed Instances</h3>
<p>First, we’ll start with the obvious choice: EBS-backed instances. When this type of instance is launched, Amazon automatically creates an Amazon EBS volume from the associated AMI snapshot, which then becomes the root device. Any changes to the local storage are then persisted in this EBS volume, and will survive instance failures and restarts. Note that by default, terminating an EBS-backed instance will also delete the EBS volume associated with it (and all its data), unless explicitly configured not to do so [<a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/Using_ChangeRootDeviceVolumeToPersist.html" target="_blank">6</a>].</p>
<h3>Persistence Strategy 2: S3-backed Instances</h3>
<p>In spite of their ease of use, EBS-backed instances present a couple of drawbacks. First, not all software and architectures are supported out-of-the-box as EBS-backed AMIs, so the version of your favorite OS might not be available. Perhaps more importantly, the EBS volume is mounted as the root device, meaning that you will also be billed for storage of all static data such as operating systems files, etc., external to your application or configuration.</p>
<p>To circumvent these disadvantages, it is possible to use an S3-backed EC2 instance that gives you direct control over what files to persist. However, this flexibility comes at a price. Since S3-backed instances use local storage as their root device, you’ll have to manually attach and mount an EBS volume for persisting your data. Any data you write directly to your EBS mount will be automatically persisted. Other times, configuration files exist at standard locations outside of your EBS mount where you will still want to persist your changes. In such situations, you would typically create a symlink on the root device to point to your EBS mount.</p>
<p>For example, assuming you have mounted your EBS volume under <em>/ebs</em>, you would run the following shell commands to persist your apache2 configuration:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash bash" style="font-family:monospace;">
<span style="color: #336600;"># first backup original configuration
mv /etc/apache2/apache2.conf{,.orig}
# use your persisted configuration from EBS by creating a symlink
ln –s /ebs/etc/apache2/apache2.conf /etc/apache2/apache2.conf</span></pre>
</div>
</div>
<p>Once your S3-backed instance is terminated, any local instance storage (including symlinks) will be lost, but your original data and configuration will persist in your EBS volume. If you would then like to recover the state persisted in EBS upon launching a new instance, you will have to go through the process of recreating any symlinks and/or copying any pertinent configuration and data from your EBS mount to your local instance storage.</p>
<p>Synchronizing between the data persisted in EBS and that in the local instance storage can become complex and difficult to automate when launching new instances. In order to help with these tasks, there are a number of third-party management platforms that provide different levels of automation. These are covered in more detail in the next section.</p>
<h3>Persistence Strategy 3: Third-party Management Platforms</h3>
<p>In the early days of AWS, there were few and limited third-party platforms available for managing and monitoring your AWS infrastucture. Moreover, in order to manage and monitor your instances for you, these types of platforms necessarily need access to your EC2 instance keys and AWS credentials. Although a reasonable compromise for some, this requirement could pose an unacceptable security risk for others, who must guarantee the security and confidentiality of their data and internal AWS infrastructure.</p>
<p>Given these limitations, The Server Labs developed its own Cloud Management Framework in Ruby for managing EC2 instances, EBS volumes and internal SSH keys in a secure manner. Our framework automates routine tasks such as attaching and mounting EBS volumes when launching instances, as well providing hooks for the installation and configuration of software and services at startup based on the data persisted in EBS. It even goes one step further by mounting our EBS volumes using an encrypted file system to guarantee the confidentiality of our internal company data.</p>
<p>Today, companies need not necessarily develop their homegrown frameworks, and can increasingly rely on third-party platforms. An example of a powerful commercial platform for cloud management is Rightscale. For several of our projects, we rely on Rightscale to automatically attach EBS volumes when launching new EC2 instances. We also make extensive use of scripting to install and configure software onto our instances automatically at boot time using Rightscale’s Righscript technology [<a href="http://support.rightscale.com/12-Guides/01-RightScale_Dashboard_User_Guide/03-Design/02-RightScripts" target="_blank">7</a>]. These features make it easy to persist your application data and configuration in EBS, while automating the setup and configuration of new EC2 instances associated with one or more EBS volumes.</p>
<h2>Automating Your Instance Uptimes</h2>
<p>Now that we have discussed the major persistence strategies for Amazon EC2, we are in a good position to tackle our original use case. How can we schedule an instance in Amazon so that it is only operational during business hours? After all, we’d really like to avoid getting billed for instance uptime during times when it is not really needed.</p>
<p>To solve this problem, we’ll have to address two independent considerations. First, we’ll have to ensure that all of our instance state (including data and configuration) is stored persistently. Second, we’ll have to automate the starting and stopping of our instance, as well as restoring its state from persistent storage at boot time.</p>
<h3>Automation Strategy 1: EBS-backed Instances</h3>
<p>By using an EBS-backed instance, we ensure that all of its state is automatically persisted even if the instance is restarted (provided it is not terminated). Since the EBS volume is mounted as the root device, no further action is required to restore any data or configuration. Last, we’ll have to automate starting and stopping of the instance based on our operational times. For scheduling our instance uptimes, we can take advantage of the Linux cron service. For example, in order to schedule an instance to be operational during business hours (9am to 5pm, Monday-Friday), we could create the following two cron jobs:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash bash" style="font-family:monospace;">
<span style="color: #336600;">0 9 * * 1-5 /opt/aws/bin/ec2-start.sh i-10a64379
0 17 * * 1-/opt/aws/bin/ec2-stop.sh i-10a64379</span></pre>
</div>
</div>
<p>The first cron job will schedule the EBS-backed instance identified by instance ID <em>i-10a64379</em> to be started daily from Monday to Friday at 9am. Similarly, the second job schedules the same instance to be stopped at 5pm Monday through Friday. The cron service invokes the helper scripts <em>ec2-start.sh</em> and <em>ec2-stop.sh</em> to facilitate the configuration of the AWS command-line tools according to your particular environment. You could run this cron job from another instance in the cloud, or you could have a machine in your office launch it.</p>
<p>The following snippet provides sample contents for ec2-start.sh, which does the setup necessary to invoke the AWS <em>ec2-start-instances</em> command. Note that this script assumes that your EBS-backed instance was previously launched manually and you know its instance ID.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash bash" style="font-family:monospace;">
<span style="color: #336600;">#!/bin/bash
# Name: ec2-start.sh
# Description: this script starts the EBS-backed instance with the specified Instance ID
# by invoking the AWS ec2-start-instances command
# Arguments: the Instance ID for the EBS-backed instance that will be started.

export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.20
export EC2_HOME=/opt/aws/ec2-api-tools-1.3
export EC2_PRIVATE_KEY=/opt/aws/keys/private-key.pem
export EC2_CERT=/opt/aws/keys/cert.pem
# uncomment the following line to use Europe as the default Zone
#export EC2_URL=https://ec2.eu-west-1.amazonaws.com
PATH=$PATH:${EC2_HOME}/bin
INSTANCE_ID=$1

echo "Starting EBS-backed instance with ID ${INSTANCE_ID}"</span><span style="color: #336600; font-weight: bold">
ec2-start-instances ${INSTANCE_ID}</span></pre>
</div>
</div>
<p>Similarly, ec2-stop.sh would stop your EBS-backed instance by invoking <em>ec2-stop-instances</em> followed by your instance ID. Note that the instance ID of EBS-backed instances will remain the same across restarts.</p>
<h3>Automation Strategy 2: S3-backed Instances</h3>
<p>Amazon instances backed by S3 present the additional complexity that the local storage is not persistent and will be lost upon terminating the instance. In order to persist application data and configuration changes independently of the lifecycle of our instance, we’ll have to rely on EBS. Additionally, we’ll have to carefully restore any persisted state upon launching a new EC2 instance.</p>
<p>The Server Labs Cloud Manager allows us to automate these tasks. Among other features, it automatically attaches and mounts a specified EBS volume when launching a new EC2 instance. It also provides hooks to invoke one or more startup scripts directly from EBS. These scripts are specific to the application, and can be used to restore instance state from EBS, including any appropriate application data and configuration.</p>
<p>If you must use S3-backed instances for your solution, you&#8217;ll either have to develop your own framework along the lines of The Server Labs Cloud Manager, or rely on third-party management platforms like Rightscale. Otherwise, EBS-backed instances provide the path of least resistance to persisting your instance data and configuration.</p>
<h3>Automation Strategy 3: Rightscale</h3>
<p>Rightscale provides a commercial platform with support for boot time scripts (via Righscripts) and automatic attachment of EBS volumes. In addition, Rightscale allows applications to define arrays of servers that grow and shrink based on a number of parameters. By using the server array schedule feature, you can define how an alert-based array resizes over the course of a week [<a href="http://support.rightscale.com/12-Guides/01-RightScale_Dashboard_User_Guide/01-Manage/02-Arrays/Create_an_Alert-based_Server_Array/Server_Array_Schedule" target="_blank">8</a>], and thus ensure a single running instance of your server during business hours. In addition, leveraging boot time scripts and the EBS volume management feature enables you to automate setup and configuration of new instances in the array, while persisting changes to your application data and configuration. Using these features, it is possible to build an automated solution for a server that operates during business hours, and that can be shutdown safely when not in use.</p>
<h2>Conclusion</h2>
<p>This article describes the major approaches to persisting state in Amazon EC2. Persisting state is crucial to building robust and highly-available architectures with the capacity to scale. Not only does it promote operational efficiency by only consuming resources when a need exists; it also protects your application state so that it if your instant fails or is accidentally terminated you can automatically launch a new one and continue where you left off. In fact, these same ideas can also enable your application to scale seamlessly by automatically provisioning new EC2 instances in response to a growth in demand.</p>
<h2>References</h2>
<p>[1] <a href="http://aws.typepad.com/aws/2009/12/new-amazon-ec2-feature-boot-from-elastic-block-store.html" target="_blank">New Amazon EC2 Feature: Boot from Elastic Block Store</a>. Original announcement from Amazon explaining the new EC2 boot from EBS feature. </p>
<p>[2] <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/ComponentsAMIs.html" target="_blank">Amazon Elastic Compute Cloud User Guide: AMI Basics</a>. Covers basic AMI concepts for S3 and EBS AMI types.</p>
<p>[3] <a href="http://www.shlomoswidler.com/2009/07/ec2-instance-life-cycle.html" target="_blank">The EC2 Instance Life Cycle:</a> excellent blog post describing major lifecycle differences between S3 and EBS-backed EC2 instances.</p>
<p>[4] <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?Concepts_BootFromEBS.html" target="_blank">Amazon Elastic Compute Cloud User Guide: AMIs Backed by Amazon EBS</a>. Learn about EBS-backed AMIs and how they work.</p>
<p>[5] <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1346" target="_blank">AWS Feature Guide: Amazon EC2 Elastic IP Addresses</a>. An introduction to Elastic IP Addresses for Amazon EC2.</p>
<p>[6] <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/Using_ChangeRootDeviceVolumeToPersist.html" target="_blank">Amazon Elastic Compute Cloud User Guide: Changing the Root Volume to Persist.</a> Learn how to configure your EBS-backed EC2 instance so that the associated EBS volume is not deleted upon termination.</p>
<p>[7] <a href="http://support.rightscale.com/12-Guides/01-RightScale_Dashboard_User_Guide/03-Design/02-RightScripts" target="_blank">RightScale User Guide: RightScripts</a>. Learn how to write your own RightScripts.</p>
<p>[8] <a href="http://support.rightscale.com/12-Guides/01-RightScale_Dashboard_User_Guide/01-Manage/02-Arrays/Create_an_Alert-based_Server_Array/Server_Array_Schedule" target="_blank">RightScale User Guide: Server Array Schedule</a>. Learn how to create an alert-based array to resize over the course of the week.</p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/rDKpc6F_IA0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/07/08/ec2-persistence-strategies/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic LDAP-based authentication and authorization in Servicemix 3</title>
		<link>http://www.theserverlabs.com/blog/2010/06/25/dynamic-ldap-based-authentication-and-authorization-in-servicemix-3/</link>
		<comments>http://www.theserverlabs.com/blog/2010/06/25/dynamic-ldap-based-authentication-and-authorization-in-servicemix-3/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:07:54 +0000</pubDate>
		<dc:creator>Jacobo Matute</dc:creator>
		
		<category><![CDATA[SOA]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Add new tag]]></category>

		<category><![CDATA[Servicemix]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=1006</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/06/25/dynamic-ldap-based-authentication-and-authorization-in-servicemix-3/";</script>Recently, we have been working quite extensively with Apache Servicemix, a JBI-compliant ESB.
One of areas we have been looking into is securing services in general and how to perform ldap-based authentication and authorization for those services in particular.
A good starting point to understand Servicemix (SMX) security features can be found here. I will give a [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/06/25/dynamic-ldap-based-authentication-and-authorization-in-servicemix-3/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Recently, we have been working quite extensively with <a href="http://servicemix.apache.org/home.html">Apache Servicemix</a>, a <a href="http://jcp.org/aboutJava/communityprocess/final/jsr208/index.html">JBI-compliant</a> ESB.<br />
One of areas we have been looking into is securing services in general and how to perform ldap-based authentication and authorization for those services in particular.</p>
<p>A good starting point to understand Servicemix (SMX) security features can be found <strong><a href="http://servicemix.apache.org/security.html">here</a></strong>. I will give a brief overview of the security features of JBI and SMX .</p>
<p>JBI does not very concisely define authentication and authorization mechanisms, but it does define the following:</p>
<ul>
<li>JBI relies on <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html">JAAS</a> definitions for security features (i.e. security <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html#Subject">Subject</a>).</li>
<li>The Binding Components (e.g. servicemix-cxfbc) are expected to transform protocol-specific (e.g. WS-Security) credentials into a normalized format, a security Subject, and inject them into the normalized message.</li>
<li>The ESB will then apply the authentication and authorization mechanism based on Subject information.</li>
</ul>
<p>In particular for SMX we have:</p>
<ul>
<li>For authentication it relies on JAAS, being able to use custom Login modules to integrate different technologies (e.g. LDAP) and implement specific authentication logic. The SMX configuration for JAAS is located under <strong>$SERVICEMIX_HOME/conf/login.properties</strong>.</li>
<ul>
<li>SMX comes by default with a file based authentication mechanism, which is not suitable for use in many environments since it <strong>requires an SMX restart</strong> after any change.</li>
</ul>
<li>For authorization, SMX does not use JAAS, due to the different nature of the items to be authorized (i.e. service endpoints instead of Java code). It defines an specific ACL <strong><a href="http://servicemix.apache.org/dist/servicemix-3.2.1/site/parent/core/servicemix-core/apidocs/org/apache/servicemix/jbi/security/acl/AuthorizationMap.html">AuthorizationMap</a></strong>, used by the NormalizedRouter (SecureBroker) to allow or deny the invocation. The configuration file for this is located in <strong>$SERVICEMIX_HOME/conf/security.xml</strong> </li>
<ul>
<li>Also in this case, SMX comes by default with a file based ACL definition, included in the security.xml file. Any change in the ACLs <strong>requires an SMX restart</strong>.</li>
</ul>
</ul>
<p>So the idea behind this post is to provide a dynamic authentication/authorization mechanism in SMX that does not require an ESB restart after changes whilst also making use of LDAP.</p>
<p>In this post I will go through a complete example that requires the following:</p>
<ol>
<li><a href="http://servicemix.apache.org/servicemix-332.html">Apache ServiceMix 3.3.2</a>.</li>
<li><a href="http://www.opends.org/promoted-builds/2.2.0/">OpenDS 2.2</a> as a test LDAP Server. However you can use any other LDAP server you prefer.</li>
<li>Maven 2.0.9 or higher to build the projects.</li>
</ol>
<p>The complete source code of this post can be found <a href="http://www.theserverlabs.com/blog/wp-content/uploads/2010/06/smx-ldapsample-src.zip">here</a>. It contains:</p>
<ol>
<li>A LDAP ldif file with the sample directory structure used.</li>
<li>As a test service, a secured version of the SMX&#8217;s cxf-wsdl-first, now called <strong>cxf-wsdl-first-secure</strong>.</li>
<li>A <strong>smx-ldap</strong> maven project with the classes we need to deploy in SMX in order to enable LDAP.</li>
<li>A <strong>smxConfig</strong> directory with the required SMX configuration.</li>
</ol>
<p>With that in mind, let&#8217;s go through the details:</p>
<h1>Install Servicemix and OpenDS</h1>
<p>You can skip the OpenDS section if you have your own LDAP server, just make sure the relevant LDAP configuration parameters are used in the coming sections.</p>
<ol>
<li>Download and install Servicemix. No additional modifications are required at this stage.</li>
<li>Download and install OpenDS. If you want to use the sample LDAP ldif file, setup the directory server with the following configuration:</li>
<ul>
<li>Select as &#8220;Directory Base DN&#8221;: <strong>dc=theserverlabs,dc=com</strong>. </li>
<li>Select import data from LDIF and choose the file included in the source package.</li>
<li>Complete installation.
        </ul>
</ol>
<p>The users and passwords defined in the sample ldif are:</p>
<ul>
<li>reader:reader</li>
<li>smx:smx</li>
<li>testuser:testuser</li>
</ul>
<h1>Create a test service that requires authentication</h1>
<p>To show the authentication and authorization of a service deployed in SMX I took the &#8220;cxf-wsdl-first&#8221; example that is included in the SMX distribution and enabled WS-Security authentication headers. The result project is included in the source files as &#8220;cxf-wsdl-first-secure&#8221;.</p>
<p>For that I just added the following interceptors configuration into the xbean.xml file of the CXFBC service unit &#8220;wsdl-first-cxfbc-secure-su&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cxfbc:consumer</span> <span style="color: #000066;">wsdl</span>=<span style="color: #ff0000;">&quot;classpath:person.wsdl&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">targetService</span>=<span style="color: #ff0000;">&quot;person:PersonService&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">targetInterface</span>=<span style="color: #ff0000;">&quot;person:Person&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cxfbc:inInterceptors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.cxf.interceptor.LoggingInInterceptor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
             <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ref</span> <span style="color: #000066;">bean</span>=<span style="color: #ff0000;">&quot;UserName_RequestIn&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cxfbc:inInterceptors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cxfbc:consumer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor&quot;</span>  <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;UserName_RequestIn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;map<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;action&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;UsernameToken&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">			No real implementation of PasswordCallbackClass is required, thus the</span>
<span style="color: #808080; font-style: italic;">	    	        dummy class. However it must be defined. This is due to the fact</span>
<span style="color: #808080; font-style: italic;">			that the SMX will take care of the authentication, not WSS4J.</span>
<span style="color: #808080; font-style: italic;">		--&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;passwordCallbackClass&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.tsl.jbi.smx.security.DummyCallbackHandler&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;passwordType&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;PasswordText&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/map<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/constructor-arg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In this case as you see the required passwordCallbackClass just defines a DummyCallbackHandler (also included in the cxfbc su) that does nothing at all, delegating the whole authentication/authorization to SMX.<br />
This is the simplest case and obviously you could have a class that performs additional checks or needs to deal with keystore passwords in case encryption is used. I will not get into the details here about WSS4J as this can be a subject worth a whole entry by itself.</p>
<p>Also, for a very good background reading of WS-Security and SMX check this <a href="http://tmielke.blogspot.com/2009/05/understanding-authentication-and.html">blog post</a> by Torsten Mielke.</p>
<p>To install the example project into SMX, just build the maven project and copy the service assembly to the hotdeploy directory of SMX:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> Source<span style="color: #000000; font-weight: bold;">/</span>cxf-wsdl-first-secure<span style="color: #000000; font-weight: bold;">/</span>
mvn clean <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span>  wsdl-first-cxf-secure-sa<span style="color: #000000; font-weight: bold;">/</span>target<span style="color: #000000; font-weight: bold;">/</span>wsdl-first-cxf-secure-sa-3.3.2.zip <span style="color: #007800;">$SERVICEMIX_HOME</span><span style="color: #000000; font-weight: bold;">/</span>hotdeploy</pre></div></div>

<p>An example soap request with the WS-Security headers would be:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:Envelope</span> <span style="color: #000066;">xmlns:soapenv</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;</span> <span style="color: #000066;">xmlns:typ</span>=<span style="color: #ff0000;">&quot;http://servicemix.apache.org/samples/wsdl-first/types&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsse:Security</span> <span style="color: #000066;">xmlns:wsse</span>=<span style="color: #ff0000;">&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsse:UsernameToken</span> <span style="color: #000066;">wsu:Id</span>=<span style="color: #ff0000;">&quot;UsernameToken-9&quot;</span> <span style="color: #000066;">xmlns:wsu</span>=<span style="color: #ff0000;">&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsse:Username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>testuser<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsse:Username<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsse:Password</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>testuser<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsse:Password<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsse:UsernameToken<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsse:Security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:Header<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soapenv:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;typ:GetPerson<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;typ:personId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>world<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/typ:personId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/typ:GetPerson<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:Body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/soapenv:Envelope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h1>Setup the required LDAP classes for JAAS and SMX AuthorizationMap</h1>
<p>The required JAAS LDAP Login Module and the SMX AuthorizationMap contains many LDAP connectivity logic that are common and can be found in several open-source implementations.<br />
I took as a reference the ActiveMQ classes and modify them to fit the SMX needs.  </p>
<p>You can find the two classes in the smx-ldap maven project:</p>
<ul>
<li><strong>LdapLoginModule</strong>: This class implements the JAAS <a href="http://java.sun.com/javase/6/docs/api/javax/security/auth/spi/LoginModule.html">LoginModule</a> interface and it is responsible to perform the authentication (login method) based on the passed credentials. It is also responsible to extract the user&#8217;s roles once it is authenticated and inject them into the Subject as additional principals. The provided class is basically the same implementation used for ActiveMQ, no changes are required.</li>
<li><strong>LdapAuthorizationMap</strong>: This class implements the <a href="http://servicemix.apache.org/dist/servicemix-3.2.1/site/parent/core/servicemix-core/apidocs/org/apache/servicemix/jbi/security/acl/AuthorizationMap.html">AuthorizationMap</a> interface offered by SMX. The interface has just one method:

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">Set<span style="color: #339933;">&lt;</span>Principals<span style="color: #339933;">&gt;</span> getAcls<span style="color: #009900;">&#40;</span>endpoint, operation<span style="color: #009900;">&#41;</span></pre></div></div>

<p>The class simply provides a set of Principals allowed to invoke the passed endpoint and operation. Also in this case, I took as a baseline the LdapAuthorizationMap include in ActiveMQ. We need to adapt it as ActiveMQ maps work on queues and topics, not endpoints. </li>
</ul>
<p>Having reached this point I needed to define the level of granularity and also the format of the entries in LDAP defining the ACLs. I provide one implementation possibility here and it is definitely not perfect. Depending on your needs you can take this as a baseline an implement a more complex logic, add caching of endpoints ACLs, etc&#8230;</p>
<p>So this is the format I defined:</p>
<ul>
<li>Endpoint ACLs are located under &#8220;ou=endpoints,ou=smx&#8221; in the LDAP tree.
<li>The entries defining the ACLs will be &#8220;GroupOfUniqueNames&#8221;, having an entry per allowed group.</li>
<li>The &#8220;cn&#8221; of the ACLs has the form:

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">cn<span style="color: #339933;">=&lt;</span>Namespace<span style="color: #339933;">&gt;:&lt;</span>ServiceName<span style="color: #339933;">&gt;:&lt;</span>Operation<span style="color: #339933;">&gt;</span></pre></div></div>

<p>In the defined schema you can also use wildcards on Service and Operation. Examples of ACLs definition for the cxf-wsdl-first-secure project would be:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">cn<span style="color: #339933;">=</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//servicemix.apache.org/samples/wsdl-first:*:*   </span>
       Grant permissions to all services on that ns.    
&nbsp;
<span style="color: #006633;">cn</span><span style="color: #339933;">=</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//servicemix.apache.org/samples/wsdl-first:PersonService:*   </span>
       Grant permissions to all operations of PersonService.    
&nbsp;
<span style="color: #006633;">cn</span><span style="color: #339933;">=</span>http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//servicemix.apache.org/samples/wsdl-first:*:GetPerson   </span>
       Grant permissions to GetPerson operations of all services in that ns.</pre></div></div>

<p>Another example in case you use dynamic SMX ftp endpoints would be:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">cn<span style="color: #339933;">=</span>urn<span style="color: #339933;">:</span>servicemix<span style="color: #339933;">:</span>ftp<span style="color: #339933;">:*</span> 
       Grant permissions to all dynamic endpoints of the servicemix<span style="color: #339933;">-</span>ftp BC.</pre></div></div>

</li>
</ul>
<p>This logic is implemented in the LdapAuthorizationMap class.</p>
<p>Both ActiveMQ classes are highly configurable using properties as we will see how to setup their usage in SMX.</p>
<p>To install the classes, build the maven project and copy the jar file to the lib directory of SMX:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> Source<span style="color: #000000; font-weight: bold;">/</span>smx-ldap<span style="color: #000000; font-weight: bold;">/</span>
mvn clean <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span>  <span style="color: #c20cb9; font-weight: bold;">cp</span> target<span style="color: #000000; font-weight: bold;">/</span>smx-ldap-<span style="color: #000000;">1.0</span>-SNAPSHOT.jar <span style="color: #007800;">$SERVICEMIX_HOME</span><span style="color: #000000; font-weight: bold;">/</span>lib
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>Restart ServiceMix<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<h1>Configure SMX</h1>
<p>To make use of the LDAP authentication and authorization two SMX files need to be modified:</p>
<ul>
<li><strong>$SERVICEMIX_HOME/conf/login.properties</strong>: This is the JAAS authentication configuration and must define the LdapLoginModule. The parameters are for locally configured OpenDS LDAP, modify them with your configuration if required:

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">servicemix-domain <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    com.tsl.jbi.smx.security.login.LDAPLoginModule REQUIRED
        <span style="color: #007800;">debug</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
        <span style="color: #007800;">initialContextFactory</span>=com.sun.jndi.ldap.LdapCtxFactory
        <span style="color: #007800;">connectionURL</span>=<span style="color: #ff0000;">&quot;ldap://localhost:389&quot;</span>
        <span style="color: #007800;">connectionUsername</span>=<span style="color: #ff0000;">&quot;cn=reader,ou=people,dc=theserverlabs,dc=com&quot;</span>
        <span style="color: #007800;">connectionPassword</span>=reader
        <span style="color: #007800;">connectionProtocol</span>=s
        <span style="color: #007800;">authentication</span>=simple
        <span style="color: #007800;">userBase</span>=<span style="color: #ff0000;">&quot;ou=people,dc=theserverlabs,dc=com&quot;</span>
        <span style="color: #007800;">userRoleName</span>=dummyUserRoleName
        <span style="color: #007800;">userSearchMatching</span>=<span style="color: #ff0000;">&quot;(uid={0})&quot;</span>
        <span style="color: #007800;">userSearchSubtree</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
        <span style="color: #007800;">roleBase</span>=<span style="color: #ff0000;">&quot;ou=groups,dc=theserverlabs,dc=com&quot;</span>
        <span style="color: #007800;">roleName</span>=cn
        <span style="color: #007800;">roleSearchMatching</span>=<span style="color: #ff0000;">&quot;(member={0})&quot;</span>
        <span style="color: #007800;">roleSearchSubtree</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
        ;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>;</pre></div></div>

<p>You can see that there are two parameters, <strong>userSearchMatching</strong> and <strong>roleSearchMatching</strong> that allow us to define the user/roles search filter that fit our environment.
</li>
<li><strong>$SERVICEMIX_HOME/conf/security.xml</strong>. This file contains general SMX security configuration and here we will define the bean for the LdapAuthorizationMap:

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">  <span style="color: #808080; font-style: italic;">&lt;!-- Custom, LDAP based authorisation map --&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!-- MessageFormat used as LDAP filter to search for Roles of an Specific Endpoint --&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!-- {0} will be replaced by Endpoint Namespace, {1} by Endpoint Name and --&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!-- {2} by Endpoint operation --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;roleFilterMessageFormat&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;java.text.MessageFormat&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;constructor-arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;(|(|(|(cn={0}:{1}:{2})(cn={0}:{1}:\*))(cn={0}:\*:{2}))(cn={0}:\*:\*))&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;LdapAuthorizationMap&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.tsl.jbi.smx.security.LDAPAuthorizationMap&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;initialContextFactory&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;com.sun.jndi.ldap.LdapCtxFactory&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionURL&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ldap://localhost:389&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionUsername&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;cn=reader,ou=people,dc=theserverlabs,dc=com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionPassword&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;reader&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;connectionProtocol&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;s&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;endpointSearchBase&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ou=endpoints,ou=smx,dc=theserverlabs,dc=com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;endpointRoleFilterFormat&quot;</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;roleFilterMessageFormat&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;roleAttribute&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;uniqueMember&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Also in this case, we have an <strong>endpointRoleFilterFormat</strong> that defines the ACL&#8217;s search filter. This can be modified to match whatever other LDAP directory setup you want to define for ACLs.
</li>
<li><strong>$SERVICEMIX_HOME/conf/servicemix.xml</strong>. We need to modify the authorizationMap used by the secured broker and point to the new ldap-based map.

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sm:broker<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sm:securedBroker</span> <span style="color: #000066;">authorizationMap</span>=<span style="color: #ff0000;">&quot;#LdapAuthorizationMap&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
       .....
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sm:broker<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</ul>
<p><strong><br />
Restart ServiceMix to apply the changes and you are ready to go!</strong></p>
<h1>Test the service and play around</h1>
<p>You can test the configuration with SoapUI (example project included in sources) or make use of the client.html (thanks SMX guys for this!!!) included in the cxf-wsdl-first-secure project. </p>
<p>The simplest one is the client.html, just load it in your web browser and fire away.</p>
<div id="attachment_1023" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2010/06/client.jpg"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/06/client-300x151.jpg" alt="Test Web Service Client" title="Test Web Service Client" width="300" height="151" class="size-medium wp-image-1023" /></a><p class="wp-caption-text">Test Web Service Client</p></div>
<p>The test should run successfully and return the Person information. </p>
<p>Now, it&#8217;s time to start playing around with the LDAP and see dynamic authentication/authorization:</p>
<ul>
<li>For instance, you can change the ACL group in the endpoint LDAP to SMX-GROUP2 and see how you get a &#8220;Endpoint is not authorized for this user&#8221; exception. </li>
<li>Create a more fine grained endpoint ACL that only assigns SMX-GROUP1 to:

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #007800;">cn</span>=<span style="color: #ff0000;">&quot;http://servicemix.apache.org/samples/wsdl-first:PersonService:GetPerson&quot;</span></pre></div></div>

</li>
<li>Change the password used for authentication of testuser in the SOAP request to get an LDAP login error.</li>
</ul>
<h1>Conclusions</h1>
<p>Dynamic authentication/authorization configuration in an ESB with mechanisms like LDAP is mandatory in any real deployment scenario. </p>
<p>You have seen that adding LDAP-based authentication/authorization to SMX is not difficult but to have a robust model some implementation work is required. The implementation shown in this post can be taken as a good starting point but there are areas of improvement both in terms of performance (e.g. cache, etc&#8230;) and in the authorization model itself (e.g. precedence of ACLs, etc&#8230;).</p>
<p>Also, the SMX authentication/authorization mechanisms described are for version 3.x. They should be applicable also for SMX 4 with its new architecture based on OSGi, as the same type of NMR is sitting on top of the OSGi runtime. </p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/3NqT5wj1Sd4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/06/25/dynamic-ldap-based-authentication-and-authorization-in-servicemix-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>HTML5 Websocket vs Flex Messaging</title>
		<link>http://www.theserverlabs.com/blog/2010/06/09/html5-websocket-vs-flex-messaging/</link>
		<comments>http://www.theserverlabs.com/blog/2010/06/09/html5-websocket-vs-flex-messaging/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 10:51:11 +0000</pubDate>
		<dc:creator>Kevin McCormack</dc:creator>
		
		<category><![CDATA[Default]]></category>

		<category><![CDATA[activemq]]></category>

		<category><![CDATA[adobe]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[html5]]></category>

		<category><![CDATA[JMS]]></category>

		<category><![CDATA[stomp]]></category>

		<category><![CDATA[websocket]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=995</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/06/09/html5-websocket-vs-flex-messaging/";</script>Nearly 18 months ago, I wrote an article on this blog which showed how to develop a simple flex web application using ActiveMQ as a JMS server. It has proved a popular article so there must be a fair amount of interest in this topic. 
With all the hype surrounding HTML5 at the moment, I [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/06/09/html5-websocket-vs-flex-messaging/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Nearly 18 months ago, I wrote <a href="http://www.theserverlabs.com/blog/2009/01/22/flex-with-jms-using-blazeds-jetty-and-activemq/">an article on this blog</a> which showed how to develop a simple flex web application using ActiveMQ as a JMS server. It has proved a popular article so there must be a fair amount of interest in this topic. </p>
<p>With all the hype surrounding HTML5 at the moment, I figured I&#8217;d try to update the application for the HTML5 world, at the same time seeing how easy it would be to replace Adobe Flex. I&#8217;m sure you&#8217;re all familiar with the fact that Steve Jobs won&#8217;t let Flash (and therefore Flex) onto either the iPhone or iPad, so it&#8217;s worth investigating if the alternatives (in this case HTML5 websocket) are really up to scratch. </p>
<p>The example shown in the article uses HTML 5 websocket, Apache ActiveMQ, the Stomp messaging protocol and (indirectly) Jetty 7. It currently only runs in Google Chrome 5 since this is the only browser with support for websocket available as of May 2010. </p>
<h2>What is Websocket?</h2>
<p>In short, it&#8217;s a way of opening up a firewall-friendly bi-directional communications channel with a server. The channel stays open for a long period of time, allowing the server and client web browser to interchange messages without having to do polling which consumes bandwidth and a lot of server resources. </p>
<p><a href="http://www.kaazing.org/confluence/display/KAAZING/What+is+an+HTML+5+WebSocket">This article</a> describes websocket in much more depth. </p>
<p>Websocket forms part of the (still unapproved) HTML5 specification which all browsers will eventually have to implement. </p>
<h2>Updating the Trader app</h2>
<p>In order to get the best out of this section, it is probably best to have read the <a href="http://www.theserverlabs.com/blog/2009/01/22/flex-with-jms-using-blazeds-jetty-and-activemq/">original Flex-JMS article</a>. </p>
<p><a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/trader-app-websocket1.zip'>Here is the code for the updated trader app</a>. Instead of having a server webapp component with BlazeDS acting as a message proxy and the flex clients, we have a bunch of HTML/CSS/JS files (in the /html folder) and some code to put messages in the JMS queues published by Apache ActiveMQ (in the /server folder).</p>
<h3>Setting up Apache ActiveMQ</h3>
<p>Apache ActiveMQ now comes with support for Websocket (implemented behind the scenes with Jetty 7). We will use ActiveMQ both as our messaging server and web server in this example, though that is not perhaps the best production configuration. </p>
<p><a href="http://www.nighttale.net/activemq/activemq-54-stomp-over-web-sockets.html">This article</a> explains how to configure ActiveMQ and Websocket. I will repeat the key instructions here for the sake of simplicity: </p>
<ol>
<li>Download the latest snapshot of Apache ActiveMQ 5.4 from <a href="https://repository.apache.org/content/repositories/snapshots/org/apache/activemq/apache-activemq/5.4-SNAPSHOT/">here</a> and unzip it somewhere on your filesystem that we will call $ACTIVEMQ_HOME</li>
<li>Edit  $ACTIVEMQ_HOME/conf/activemq.xml and change the transportConnectors section so that it looks like the example below:

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transportConnectors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transportConnector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;openwire&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;tcp://0.0.0.0:61616&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transportConnector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;websocket&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;ws://0.0.0.0:61614&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transportConnector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stomp&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;stomp://0.0.0.0:61612?transport.closeAsync=false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;transportConnector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;stomp+nio&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;stomp+nio://0.0.0.0:61613?transport.closeAsync=false&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/transportConnectors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<li>Start ActiveMQ by running bin/activemq from the $ACTIVEMQ_HOME directory. Go to <a href="http://localhost:8161/admin/">http://localhost:8161/admin/</a> and log in with the username/password admin/admin to check that everything is working ok. </li>
</ol>
<h3>Configure an install the aplication</h3>
<p>Download <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/trader-app-websocket1.zip'>the trader app code</a> and copy the /html folder to $ACTIVEMQ_HOME/webapps/demo, renaming it to /trader-app-websocket (i.e. the full path should be $ACTIVEMQ_HOME/webapps/demo/trader-app-websocket). </p>
<p>Edit stock-quote.js and note the following section:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">    var url = 'ws://localhost:61614/stomp';
    var login = 'guest';
    var passcode = 'guest';
    destination = '/topic/stockQuoteTopic';</pre></div></div>

<p>The url attribute referes to the URL of the ActiveMQ server. Due to a bug in Chrome running on Ubuntu 9.10, I had to put the IP address of my machine here but if you&#8217;re running on another linux flavour, OSX or windows, I would imagine that leaving it as localhost should be OK. The username and password are guest/guest which is standard for ActiveMQ.</p>
<p>Download the latest version of Google Chrome (I have 5.0.375.55 which was released a few days ago) and open the URL http://localhost:8161/demo/trader-app-websocket/. You should see a UI that is similar to the Flex app developed in the original article: </p>
<p><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/chrome-initial.png"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/chrome-initial.png" alt="chrome-initial" title="chrome-initial" width="551" height="607" class="aligncenter size-full wp-image-998" /></a></p>
<p>Open up a terminal window and go to the location to which you extracted the /server part of the code download. Run the following (assumes Maven installed);</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn clean compile <span style="color: #7a0874; font-weight: bold;">exec</span>:java -Dexec.mainClass=<span style="color: #ff0000;">&quot;com.theserverlabs.flex.trader.JSONFeed&quot;</span></pre></div></div>

<p>You should see a whole bunch of stock quote information like that shown below scrolling in the terminal:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #ff0000;">&quot;symbol&quot;</span>: <span style="color: #ff0000;">&quot;XOM&quot;</span>,
<span style="color: #ff0000;">&quot;name&quot;</span>: <span style="color: #ff0000;">&quot;Exxon Mobile Corp&quot;</span>,
<span style="color: #ff0000;">&quot;low&quot;</span>: <span style="color: #000000;">61.317410451219146</span>,
<span style="color: #ff0000;">&quot;high&quot;</span>: <span style="color: #000000;">61.56</span>,
<span style="color: #ff0000;">&quot;open&quot;</span>: <span style="color: #000000;">61.56</span>,
<span style="color: #ff0000;">&quot;last&quot;</span>: <span style="color: #000000;">61.317410451219146</span>,
<span style="color: #ff0000;">&quot;change&quot;</span>: <span style="color: #000000;">61.317410451219146</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>This Java program is the same as that used in the original post. It generates random stock price information for a variety of stocks and publishes it in the stockQuote topic in ActiveMQ. In this case, it generates JMS text messages which contain data formatted in the JSON format. </p>
<p>If you go back to the Chrome browser window, you should see the stock quotes update. If they don&#8217;t update, click on refresh: </p>
<p><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/chrome-stocks.png"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/05/chrome-stocks.png" alt="chrome-stocks" title="chrome-stocks" width="551" height="607" class="aligncenter size-full wp-image-999" /></a></p>
<p>This is pretty much exactly the same as how the original Flex application worked. The UI colours etc. are slightly different and I&#8217;ve not implemented the functionality for subscribing/unsubscribing from a stock price - but that was just on time grounds, not because it is difficult. </p>
<h2>How does it work?</h2>
<p>When the browser opens the page, it executes the following code in stock-quote.js, which subscribes to the stock quote service:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function(){
&nbsp;
    var client, destination;
&nbsp;
    ... 
&nbsp;
    var url = 'ws://localhost:61614/stomp';
    var login = 'guest';
    var passcode = 'guest';
    destination = '/topic/stockQuoteTopic';
&nbsp;
    client = Stomp.client(url);
    client.connect(login, passcode, onconnect);
&nbsp;
});</pre></div></div>

<p>Here we use <a href="http://jmesnil.net/stomp-websocket/doc/">the library provided by Jeff Mesnil </a> which enables us to access ActiveMQ using the <a href="http://stomp.codehaus.org">Stomp protocol</a> instead of JMS. We use it here because it is simple and cross-platform. There is no way of directly subscribing from JavaScript to a JMS server via JMS because there is no client available. </p>
<p>In the same block of code, you can see the code that we execute when we receive a message:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">&nbsp;
    var onconnect = function(frame) {
&nbsp;
      client.subscribe(destination, function(message) {
        var quote = JSON.parse(message.body);
        $('.' + quote.symbol).replaceWith(&quot;&lt;tr class=\&quot;&quot; + quote.symbol + &quot;\&quot;&gt;&quot; + 
            &quot;&lt;td&gt;&quot; + quote.symbol + &quot;&lt;/td&gt;&quot; +  
            &quot;&lt;td&gt;&quot; + quote.open.toFixed(2) + &quot;&lt;/td&gt;&quot; + 
            &quot;&lt;td&gt;&quot; + quote.last.toFixed(2) + &quot;&lt;/td&gt;&quot; + 
            &quot;&lt;td&gt;&quot; + quote.change.toFixed(2) + &quot;&lt;/td&gt;&quot; + 
            &quot;&lt;td&gt;&quot; + quote.high.toFixed(2) + &quot;&lt;/td&gt;&quot; + 
            &quot;&lt;td&gt;&quot; + quote.low.toFixed(2) + &quot;&lt;/td&gt;&quot; +  
            &quot;&lt;/tr&gt;&quot;);
      });
    };</pre></div></div>

<p>When we receive a message, we parse it using the JSON parser that is part of the JQuery library and then we find the HTML element with class attribute equal to the symbol (e.g. if the symbol is IBM, we look for the HTML element with class=&#8221;IBM&#8221;) and replace it&#8217;s contents with the HTML table row code generated in the method. Simple really. </p>
<p>The rest of the code is just HTML and CSS and is not really that interesting for this article. </p>
<h2>Conclusions</h2>
<p>It is pretty easy to develop an application that uses Websocket - you only have to look at how little real code there is in this example. I&#8217;d say it is as easy as developing the original Flex app so from a development point of view, there&#8217;s little to chose between these technologies.</p>
<p>Unfortunately the only browser that currently supports Websocket is Google Chrome (and the implementation is a bit buggy). Other browsers (especially Firefox and Safari) should have this functionality soon though. One of the arguments used in support of Flash/Flex has always been the large installed base. Given that the iPhone and iPad are not part of this installed base, it is questionable as to whether this can still be used as a justification for using Flash/Flex. Sure there aren&#8217;t that many browsers that support Websocket but in 6 months time they probably all will and you won&#8217;t need any proprietary plugin to access the apps build using them. I&#8217;d definitely recommend that people developing internal corporate apps who can force their end users to use a browser with Websocket support take a look at this technology. People developing publically accessible webapps are probably going to have to wait till it is more widely implemented in browsers and provide graceful fallback in the case in which it isn&#8217;t. </p>
<p>I should point out that I have an iPhone and use Ubuntu 9.10 64-bit at work and I hate not being able to see content on my iPhone because it has been implemented in Flash and my entire firefox browser often crashes completely due to the 64-bit linux Flash plugin. </p>
<p>I&#8217;ve gone from being a fan of Flash/Flex to not being so sure about it. It&#8217;s hard to escape the feeling that HTML5 will offer much of the functionality currently offered by Flash/Flex in a short period of time. I think the future of these technologies is going to depend on Adobe innovating and offering stuff that is not possible in HTML5, otherwise there is little reason to use it. </p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/ycWtK67xrTA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/06/09/html5-websocket-vs-flex-messaging/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Human readable JVM GC timestamps</title>
		<link>http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/</link>
		<comments>http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/#comments</comments>
		<pubDate>Wed, 26 May 2010 16:28:26 +0000</pubDate>
		<dc:creator>Francisco González</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Performance & Tuning]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[file]]></category>

		<category><![CDATA[GC]]></category>

		<category><![CDATA[log]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=855</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/";</script>When we are diagnosing problems in a Java (EE or otherwise) application, is often a good idea to check how garbage collection is performing. One of the basic and most unobtrusive actions is to enable garbage collection logging.
As you may know, if we add the following arguments to the java start command&#8230;
-Xloggc:&#60;file_name&#62; –XX:+PrintGCDetails -XX:+PrintGCDateStamps
&#8230; the [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>When we are diagnosing problems in a Java (EE or otherwise) application, is often a good idea to check how garbage collection is performing. One of the basic and most unobtrusive actions is to enable garbage collection logging.</p>
<p>As you may know, if we add the following arguments to the java start command&#8230;</p>
<p><code>-Xloggc:&lt;file_name&gt; –XX:+PrintGCDetails -XX:+PrintGCDateStamps</code></p>
<p>&#8230; the JVM will start writing garbage collection messages to the file we set with the parameter -Xlogcc. The messages should be something like:</p>
<p><code><br />
<strong>2010-04-22T18:12:27.796+0200</strong>: 22.317: [GC 59030K-&gt;52906K(97244K), 0.0019061 secs]<br />
<strong>2010-04-22T18:12:27.828+0200</strong>: 22.348: [GC 59114K-&gt;52749K(97244K), 0.0021595 secs]<br />
<strong>2010-04-22T18:12:27.859+0200</strong>: 22.380: [GC 58957K-&gt;53335K(97244K), 0.0022615 secs]<br />
<strong>2010-04-22T18:12:27.890+0200</strong>: 22.409: [GC 59543K-&gt;53385K(97244K), 0.0024157 secs]<br />
</code></p>
<p>The bold part is simply the date and time when reported garbage collection event starts.</p>
<p>Unfortunately -XX:+PrintGCDateStamps is available only for Java 6 Update 4 and later JVMs. So, if we are unlucky and our application is running on older JVMs we are forced to use&#8230;</p>
<p><code>-Xloggc:&lt;file&gt; –XX:+PrintGCDetails</code></p>
<p>&#8230; and the messages will be like:</p>
<p><code><br />
<strong>22.317</strong>: [GC 59030K-&gt;52906K(97244K), 0.0019061 secs]<br />
<strong>22.348</strong>: [GC 59114K-&gt;52749K(97244K), 0.0021595 secs]<br />
<strong>22.380</strong>: [GC 58957K-&gt;53335K(97244K), 0.0022615 secs]<br />
<strong>22.409</strong>: [GC 59543K-&gt;53385K(97244K), 0.0024157 secs]<br />
</code></p>
<p>Now, the bold numbers (also present in previous format) are the seconds elapsed from JVM start time. </p>
<p>Mmm&#8230; way harder to correlate GC events with information from other log files in this case :/</p>
<p>Wouldn&#8217;t it be easier to process the gc log file and calculate date and time from seconds elapsed? It seems so, but seconds elapsed from&#8230; when? Or, putting it in other words, where do we extract the JVM startup date and time from?</p>
<p>In order to be as unobtrusive as possible, we should try to calculate the start date and time from the same GC log file. That brings us to the file attributes. We have different options:</p>
<table>
<thead>
<tr>
<td>
<strong>Unix</strong>
</td>
<td>
<strong>Windows</strong>
</td>
</thead>
<tbody>
<tr>
<td>
Access time
</td>
<td>
Access time
</td>
</tr>
<tr>
<td>
Change time
</td>
<td>
Creation time
</td>
</tr>
<tr>
<td>
Modify time
</td>
<td>
Modify time
</td>
</tr>
</tbody>
</table>
<p>We discard access time (for obvious reasons) and change time and creation time as they are not available in both platforms, so we are left with modification time, which represents the time when the file was last modified. </p>
<p>In Windows, modification time is maintained when the file is copied elsewhere, but <strong>in Unix we should use the -p flag to preserve timestamp attributes if we want to copy the GC log file prior to our processing</strong>.</p>
<p>The last modification time of the GC log file should match the last timestamp recorded for a GC event in the log file. Well&#8230; for the purists, it should match exactly the last elapsed time plus the execution time (both in bold) as each log line is written piece by piece as it executes.</p>
<p><code><br />
<strong>22.409</strong>: [GC 59543K-&gt;53385K(97244K), <strong>0.0024157</strong> secs]<br />
</code></p>
<p>In our approach, we discard the execution time as we don&#8217;t need accurate precision to have a rough idea of what time each garbage collection event occurred. Nevertheless, keep in mind that GC execution time could sometimes be as long as several seconds in large heaps.</p>
<p>When we experienced this situation in a client recently, we needed to quickly develop a simple and portable script, so we used Python for the task. You already knew we don&#8217;t do just Java, didn&#8217;t you? <img src='http://www.theserverlabs.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>, <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">datetime</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># true if string is a positive float</span>
<span style="color: #ff7700;font-weight:bold;">def</span> validSeconds<span style="color: black;">&#40;</span>str_sec<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> 0 <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>str_sec<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ValueError</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># show usage                </span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">2</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Usage: %s &lt;gc.log&gt;&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>
&nbsp;
file_str = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
lastmod_date = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">fromtimestamp</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">getmtime</span><span style="color: black;">&#40;</span>file_str<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #008000;">file</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>file_str, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
lines = <span style="color: #008000;">file</span>.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #008000;">file</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># get last elapsed time</span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">reversed</span><span style="color: black;">&#40;</span>lines<span style="color: black;">&#41;</span>:
    parts = line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">':'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> validSeconds<span style="color: black;">&#40;</span>parts<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># calculate start time</span>
start_date = lastmod_date - <span style="color: #dc143c;">datetime</span>.<span style="color: black;">timedelta</span><span style="color: black;">&#40;</span>seconds=<span style="color: #008000;">float</span><span style="color: black;">&#40;</span>parts<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># print file prepending human readable time where appropiate  </span>
<span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> lines:
    parts = line.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">':'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> validSeconds<span style="color: black;">&#40;</span>parts<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">print</span> line.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">continue</span>
    line_date = start_date + <span style="color: #dc143c;">datetime</span>.<span style="color: black;">timedelta</span><span style="color: black;">&#40;</span>seconds=<span style="color: #008000;">float</span><span style="color: black;">&#40;</span>parts<span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;%s: %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>line_date.<span style="color: black;">isoformat</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, line.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The script output can be redirected to another file, where we&#8217;ll have<br />
<code><br />
<strong>2010-04-22T18:12:27.796375</strong>: 22.317: [GC 59030K-&gt;52906K(97244K), 0.0019061 secs]<br />
<strong>2010-04-22T18:12:27.828375</strong>: 22.348: [GC 59114K-&gt;52749K(97244K), 0.0021595 secs]<br />
<strong>2010-04-22T18:12:27.859375</strong>: 22.380: [GC 58957K-&gt;53335K(97244K), 0.0022615 secs]<br />
<strong>2010-04-22T18:12:27.890375</strong>: 22.409: [GC 59543K-&gt;53385K(97244K), 0.0024157 secs]<br />
</code></p>
<p>You may note the date format is not 100% the same as the one with -XX:+PrintGCDateStamps argument, but it should be enough to get an idea of when each GC event happened (Timezone management in Python is way out of the scope of this blog entry).</p>
<p>This has been my first blog entry for The Server Labs and I hope some of you find it useful. Of course, all comments, suggestions and feedback are very welcome.</p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/FoeWK42iLs8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/05/26/human-readable-jvm-gc-timestamps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Server Labs BizBlog</title>
		<link>http://www.theserverlabs.com/blog/2010/05/14/the-server-labs-bizblog/</link>
		<comments>http://www.theserverlabs.com/blog/2010/05/14/the-server-labs-bizblog/#comments</comments>
		<pubDate>Fri, 14 May 2010 14:15:03 +0000</pubDate>
		<dc:creator>Kevin McCormack</dc:creator>
		
		<category><![CDATA[events]]></category>

		<category><![CDATA[bizblog]]></category>

		<category><![CDATA[blog]]></category>

		<category><![CDATA[business]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=930</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/14/the-server-labs-bizblog/";</script>This week The Server Labs launched a second blog - BizBlog - which, as my colleague Greg says, aims to &#8220;address IT Architecture and Cloud topics taking a less technical but more business relevant angle&#8221; than that found in this more technical blog. 
I encourage any regular readers of this blog to take a look [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/14/the-server-labs-bizblog/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>This week The Server Labs launched a second blog - <a href="http://www.theserverlabs.com/bizblog">BizBlog</a> - which, as my colleague Greg says, aims to &#8220;address IT Architecture and Cloud topics taking a less technical but more business relevant angle&#8221; than that found in this more technical blog. </p>
<p>I encourage any regular readers of this blog to take a look at <a href="http://www.theserverlabs.com/bizblog/2010/05/10/welcome-to-the-server-labs-biz-blog/">Greg&#8217;s initial post</a> and the posts that he will be publishing in the next few weeks for a slightly different take on IT. </p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/7SrLBa4mPCc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/05/14/the-server-labs-bizblog/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Intellectual Property (IPR) Management and Monitoring Tools</title>
		<link>http://www.theserverlabs.com/blog/2010/05/06/intelectual-property-ipr-management-and-monitoring-tools/</link>
		<comments>http://www.theserverlabs.com/blog/2010/05/06/intelectual-property-ipr-management-and-monitoring-tools/#comments</comments>
		<pubDate>Thu, 06 May 2010 08:54:37 +0000</pubDate>
		<dc:creator>Jacobo Matute</dc:creator>
		
		<category><![CDATA[Continuous Integration]]></category>

		<category><![CDATA[Methodologies]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[quality]]></category>

		<category><![CDATA[Automation]]></category>

		<category><![CDATA[IPR]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=849</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/06/intelectual-property-ipr-management-and-monitoring-tools/";</script>It seems that every day projects have more and more dependencies on libraries (internal or external) and, of course, many of these depend on other libraries, resulting in a large dependency tree for any given project. How do you know if any of those libraries contain some code which is licensed in a way that [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/05/06/intelectual-property-ipr-management-and-monitoring-tools/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>It seems that every day projects have more and more dependencies on libraries (internal or external) and, of course, many of these depend on other libraries, resulting in a large dependency tree for any given project. How do you know if any of those libraries contain some code which is licensed in a way that is incompatible with your company&#8217;s policies e.g. no GPL? </p>
<p>BT (the former British Telecom) apparently didn&#8217;t and <a href="http://www.theregister.co.uk/2007/01/22/bt_breaking_gpl/">ended up having to publish all the code used in one of the routers it distributes due to a GPL violation</a>. </p>
<p>To give you an idea of the scale of this problem, doing a quick search of my local Maven repository reveals that it has 1760 JAR files in it. Admittedly not all of these belong to one single project but maybe they are spread out over 20 different projects. It is pretty infeasible to try to manage such a task manually. </p>
<p>Tools like Maven are a great help for managing dependency trees in your project but doesn&#8217;t help much with checking the licenses that each dependency uses. The pom.xml file permits the use of a &lt;license&gt; element but it is optional, many libraries either don&#8217;t use Maven or don&#8217;t specify the license and you have to check compliance manually in any case. </p>
<p>This is where IPR monitoring tools come in. Such tools allow the definition of licensing policies at an organizational level and provide mechanisms to monitor compliance with these policies in software projects, raising alerts on detected violations.</p>
<p>We recently had to take a look at such tools for one of our clients. After studying the market, we discovered that are currently no open-source solutions covering this problem domain, but several commercial tools address the problem of continuous IPR monitoring. </p>
<p>For reference purposes, here is a list of the providers that we discovered: </p>
<table>
<thead>
<th>IPR Management Tool</th>
<th>Site</th>
</thead>
<tbody>
<tr>
<td>Palamida Compliance Edition</td>
<td><a href="http://www.palamida.com">http://www.palamida.com</a></td>
</tr>
<tr>
<td>Black Duck Protex</td>
<td><a href="http://www.blackducksoftware.com/protex">http://www.blackducksoftware.com/protex</a></td>
</tr>
<tr>
<td>Protecode</td>
<td><a href="http://www.protecode.com">http://www.protecode.com</a></td>
</tr>
<tr>
<td>HiSoftware AccVerify</td>
<td><a href="http://www.hisoftware.com">http://www.hisoftware.com</a></td>
</tr>
<tr>
<td>OpenLogic Library or Enterprise Edition</td>
<td><a href="http://www.openlogic.com">http://www.openlogic.com</a></td>
</tr>
</tbody>
</table>
<p>All of these commercial products offer common features:</p>
<ul>
<li>Automated binary and source code analysis with multi-language support (Java, C/C++, C#,<br />
         Visual Basic, Perl, Python, PHP). The analysis is performed against an external proprietary<br />
         database that contains the code of most open-source products.</li>
<li>Provide workflows in order to control the IPR of the software projects through the whole<br />
lifecycle, based on defined licensing policies.</li>
<li>Approval/disapproval licensing mechanisms as well as billing of materials for<br />
software releases summarizing components, licenses, approval status and license/policy<br />
violations.</li>
<li>Different levels of code fragment recognition to detect reuse of code.</li>
<li>User interfaces offering policy management, reporting and dashboard features.</li>
<li>Support for integration of code scan in <strong>Continuous Integration</strong> platforms via command line<br />
interface execution.</li>
</ul>
<p>We think that these products are going to become increasingly important as the total number of libraries used in projects shows no sign of decreasing and there will always be a need to protect intellectual property.</p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/avDzQV4vZ-g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/05/06/intelectual-property-ipr-management-and-monitoring-tools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamically changing log level with Weblogic, log4j, JMX and WLST</title>
		<link>http://www.theserverlabs.com/blog/2010/04/22/dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/</link>
		<comments>http://www.theserverlabs.com/blog/2010/04/22/dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 08:05:57 +0000</pubDate>
		<dc:creator>Kevin McCormack</dc:creator>
		
		<category><![CDATA[Default]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Java EE]]></category>

		<category><![CDATA[JEE]]></category>

		<category><![CDATA[jmx]]></category>

		<category><![CDATA[log4j]]></category>

		<category><![CDATA[logging]]></category>

		<category><![CDATA[Oracle]]></category>

		<category><![CDATA[WebLogic]]></category>

		<category><![CDATA[WLST]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=833</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/04/22/dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/";</script>Logging is an uninteresting but nevertheless fundamental part of application development. It is useful not just when you are coding an application but in diagnosing problems of any nature once an application passes into production. 
Unfortunately, it is not that clear how to do logging well when developing JEE applications that are to be deployed [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/04/22/dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Logging is an uninteresting but nevertheless fundamental part of application development. It is useful not just when you are coding an application but in diagnosing problems of any nature once an application passes into production. </p>
<p>Unfortunately, it is not that clear how to do logging well when developing JEE applications that are to be deployed on a Weblogic server. With this article, I hope to clear up some of the confusion or, at the very least, explain a method that works for me!</p>
<p>The article is based on the use of Apache log4j since that is the most commonly used logging library. The article explains: </p>
<ul>
<li>how to configure log4j properly in a JEE app to be run on Weblogic</li>
<li>how to dynamically configure the log level using JMX and Weblogic Scripting Tool</li>
</ul>
<p>The article assumes some familiarity with Apache Maven, Eclipse and Weblogic. </p>
<p>The <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/code.zip'>code</a> is available here, although you may just prefer to download the <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/logging-ear-10-snapshot.ear'>EAR file</a> which saves you having to compile any code with Maven. The code.zip file contains the code for the JEE application, the code for the JMX library developed by The Server Labs and used in this article and the scripts for WLST. </p>
<h2>Configuring log4j in Weblogic</h2>
<p>Weblogic 10 comes with a modified version of log4j by default so you can use log4j in your application without having to deploy the log4j library in your application. Unfortunately, my experience (in WLS 10.0) is that if you do this, you will not be able to configure log4j for your application because the classloader in which log4j is loaded is one that is separate to that of your application. Any log4j.properties that you include will be ignored. </p>
<p>Instead, what you have to do is the following: </p>
<p>1) Include the log4j JAR in your application. If your app is an EAR (like mine), then the log4j JAR should go in the .ear file (in the root directory or in /APP-INF/lib). In my project, I have used a Maven multi-project setup with 3 projects - 1 for the EAR, 1 for the EJBs and 1 webapp. In this case, I have to add the log4j JAR to the EAR project&#8217;s pom.xml:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>log4j<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>log4j<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.2.12<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>2) Tell Weblogic to use your version of the log4j library and not it&#8217;s own. To do this, you specify the following in the weblogic-application.xml file which is in the EAR (/META-INF/weblogic-application.xml):</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wls:prefer-application-packages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wls:package-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.log4j.*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wls:package-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wls:prefer-application-packages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This basically says that when the app asks for a class in the package org.apache.log4j or it&#8217;s sub-packages, that it should look for it on the app&#8217;s classloader and not in the Weblogic server classloader. </p>
<p>3) Configure log4j using log4j.properties</p>
<p>Log4j requires that you configure it in order to receive log messages. I include the following contents in the /APP-INF/classes/log4j.properties file which is in the EAR file: </p>
<pre>
log4j.rootLogger=INFO, stdout, file

log4j.debug=true

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %-5p %c %x - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.File=/bea/logs/aplicaciones/blog-logging/logging_${weblogic.Name}.log
log4j.appender.file.Append = false
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.MaxFileSize = 20000Kb
log4j.appender.file.MaxBackupIndex = 5
log4j.appender.file.layout.ConversionPattern=[%d] %-5p %c %x - %m%n

log4j.category.com.theserverlabs.blog.wls=DEBUG
</pre>
<p>This configures log4j to send output both to the console in which Weblogic was started and to a file (/bea/logs/aplicaciones/blog-logging/logging_${weblogic.Name}.log). You will probably want to change the file path to something that works on your machine. </p>
<h2>Testing that log4j is working OK</h2>
<p>In order to test these changes, download the <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/logging-ear-10-snapshot.ear'>EAR file</a> and deploy it to a Weblogic server. I tested on Weblogic 10.3 but it should work on any Weblogic 10.x server or later I believe. </p>
<p>Go to the URL <a href="http://localhost:7001/logging/test">http://localhost:7001/logging/test</a> and you should see a very basic HTML page that tells you to check the logs:</p>
<p><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/servlet.png"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/servlet.png" alt="servlet" title="servlet" width="621" height="304" class="aligncenter size-full wp-image-838" /></a></p>
<p>Take a look at the console in which weblogic is running (or the Server.out file if you have the output redirected) and you should see output like that shown below:</p>
<pre>
[2010-04-21 15:29:47,888] WARN  com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - warn
[2010-04-21 15:29:47,888] INFO  com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - info
[2010-04-21 15:29:47,888] DEBUG com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - debug
[2010-04-21 15:29:47,889] ERROR com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - error
[2010-04-21 15:29:47,889] FATAL com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - fatal
[2010-04-21 15:29:48,056] WARN  com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - warn
[2010-04-21 15:29:48,056] INFO  com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - info
[2010-04-21 15:29:48,056] DEBUG com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - debug
[2010-04-21 15:29:48,056] ERROR com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - error
[2010-04-21 15:29:48,056] FATAL com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - fatal
</pre>
<p>If you examine the application, you can see that accessing the URL causes a Servlet to get executed. The servlet writes it&#8217;s messages to the log (those recorded with the class &#8220;com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet&#8221;) and invokes an EJB3 session bean which also writes messages to the log (those tagged with &#8220;com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService&#8221;). </p>
<p>This shows that this log solution works equally for web as for EJB and that there is no interference with the weblogic logging system. </p>
<h2>Making it dynamic</h2>
<p>This is a great solution when you&#8217;re still developing the app because you can change the debug level just by modifying the log4j.properties file and redeploying the app. However, this is not something you can feasibly do in a production environment - not at the companies I&#8217;ve worked at anyway - due to the interruption in service this causes to the end users. </p>
<p>Why would you want to change the log level? Well, if you have to diagnose a problem in the application, it often makes sense to increase the log level of either the whole application or a subset of it such that you receive more information which helps you to diagnose the problem. Once you have diagnosed the problem, you return the logging to it&#8217;s original level so as not to affect the performance of the application unnecesarily.  </p>
<p>What we really want is to be able to change the log level dynamically (i.e. without redeploying the application), ideally using administrator tools (since that is what the people who manage production systems tend to use) - not developer tools. </p>
<p>First I&#8217;ll show you how to change the log level and then I&#8217;ll explain how it works. </p>
<h2>Using WLST and JMX to change the log level</h2>
<p>If you have deployed the example application, go to your domain home in a terminal window and execute the setDomainEnv script. The idea is to update your shell with the domain environment variables such as JAVA_HOME, CLASSPATH etc. On my linux box, I execute the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$DOMAIN_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin
$ <span style="color: #7a0874; font-weight: bold;">source</span> setDomainEnv.sh</pre></div></div>

<p>To check it has worked, run &#8220;echo $CLASSPATH&#8221; on unix or &#8220;echo %CLASSPATH%&#8221; on windows and you should see a long classpath. </p>
<p>Once you have set up the environment, execute the changeAppLogLevel.py script that is included in the /scripts directory of the  <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/code.zip'>code</a> ZIP:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">java <span style="color: #660033;">-classpath</span> <span style="color: #007800;">$CLASSPATH</span>  <span style="color: #007800;">$JAVA_OPTIONS</span>  weblogic.WLST changeAppLogLevel.py</pre></div></div>

<p>You should see the following output: </p>
<pre>
$ java -classpath $CLASSPATH  $JAVA_OPTIONS  weblogic.WLST changeAppLogLevel.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

==>Insufficient arguments
==>Syntax: changeAppLogLevel.py [APP NAME] [LOGGER] [LEVEL]
==> where: APP NAME=context root of the app e.g. xxx for /xxx
==>        LOGGER=log4j logger name
==>        LEVEL=TRACE/DEBUG/WARN/INFO/ERROR/FATAL
==>   e.g: changeAppLogLevel.py xxx com.theserverlabs.blog.logging DEBUG
</pre>
<p>As the instructions indicate, you have to call the script with the name of the app (which is the context root of the application web), the Log4j logger that you wish to modify (normally a Java package name) and the level that you want to set (TRACE/DEBUG/WARN/INFO/ERROR/FATAL). </p>
<p>In the example below, we set the log level to INFO for the package com.theserverlabs.blog.wls in the application &#8220;logging&#8221;, which is what the example application is called. The output is the following: </p>
<pre>
java -classpath $CLASSPATH  $JAVA_OPTIONS  weblogic.WLST changeAppLogLevel.py logging com.theserverlabs.blog.wls ERROR 

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'log4j'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to custom tree. This is a writable tree with No root.
For more help, use help(custom)

changing log level to ERROR for app logging on server t3://localhost:7001
  ... done. New log levels are:
{com.theserverlabs.blog.wls=ERROR}

Exiting WebLogic Scripting Tool.
</pre>
<p>As you can see from the line &#8220;New log levels are:{com.theserverlabs.blog.wls=ERROR}&#8221;, the log level was changed from the default in the log4j.properties file (DEBUG) to ERROR. </p>
<p>If you go to the logging test page again (<a href="http://localhost:7001/logging/test">http://localhost:7001/logging/test</a>), you should see that there are no longer entries for the DEBUG, INFOR or WARN levels: </p>
<pre>
[2010-04-21 17:47:09,728] ERROR com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - error
[2010-04-21 17:47:09,728] FATAL com.theserverlabs.blog.wls.logging.view.servlet.LoggingTestServlet  - fatal
[2010-04-21 17:47:09,728] ERROR com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - error
[2010-04-21 17:47:09,728] FATAL com.theserverlabs.blog.wls.logging.services.ejb.SessionLoggingTestService  - fatal
</pre>
<p>So, we can now dynamically change the log level of a logger in our application using an administrator tool (WLST). Pretty cool, huh? </p>
<p>Here I have specified a single logger &#8220;com.theserverlabs.blog.wls&#8221; which is a high-level logger in my application. You can only pass 1 logger as arguments to the script but there is nothing to stop you from running the same script different times with different loggers e.g. once to set com.theserverlabs.blog.wls.logging.services.ejb to DEBUG to get detailed logging of EJB session beans and another time to set org.hibernate to INFO to get more info on what hibernate is doing. </p>
<h2>How do I get this to work in my application?</h2>
<p>Simple. Include our <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/jmx-logging-10.jar'>JMX-logging JAR</a> in your WEB application and add the following lines to your web.xml file:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.theserverlabs.jmx.web.JmxServletContextListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>At startup time, a JMX Mbean will be registered with the Weblogic JMX subsystem. The Mbean will be registered under a name which includes your application name, meaning there will be one MBean per application deployed on the server. </p>
<p>Once deployed, you can use the WLST script discussed in the previous section to interact with the MBean for your application and thereby change the log level of your application. </p>
<h2>OK, how does all this really work?</h2>
<p>If you look at the source code for the jmx-logging JAR (included in the <a href='http://www.theserverlabs.com/blog/wp-content/uploads/2010/04/code.zip'> source code bundle</a>, you will find a class called com.theserverlabs.jmx.ApplicationLogManager. This class implements the interface ApplicationLogManagerMBean, whose methods are JMX MBean-compatible. It provides methods that allow a caller to set the log level for a given log4j logger:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setLogLevel<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> logger, <span style="color: #003399;">String</span> level<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Logger l <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>logger<span style="color: #009900;">&#41;</span>;
		l.<span style="color: #006633;">setLevel</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">toLevel</span><span style="color: #009900;">&#40;</span>level<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and to interrogate log4j for the currently-configured loggers and their levels, returning a map of Strings:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> getLogLevels<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HashMap<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
		Enumeration<span style="color: #339933;">&lt;</span>Logger<span style="color: #339933;">&gt;</span> e <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getRootLogger</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getLoggerRepository</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCurrentLoggers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">hasMoreElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			Logger l <span style="color: #339933;">=</span> e.<span style="color: #006633;">nextElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>l.<span style="color: #006633;">getLevel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				result.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>l.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, l.<span style="color: #006633;">getLevel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> result;
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This MBean can be registered with any JMX system, allowing it&#8217;s methods to be invoked via JMX calls. In this case, we really want to register it with the Weblogic JMX system when the application starts up. To accomplish this, we use the class com.theserverlabs.jmx.web.JmxServletContextListener, which is registered in the web.xml of the web application:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.theserverlabs.jmx.web.JmxServletContextListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>A modified version of the source code for JmxServletContextListener is shown below which error-handling and logging removed for clarity. It is pretty clear that when Weblogic starts our application and calls the contextInitialized() method, we register a new instance of ApplicationLogManager with the object name &#8220;com.theserverlabs.jmx:type=ApplicationLogManager,name=[NAME OF APPLICATION]LogManager&#8221;. This name is generated in the getObjectName() method. When Weblogic stops the web application, it calls the contextDestroyed() method which un-registers the instance of ApplicationLogManager from the JMX MBean server.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JmxServletContextListener <span style="color: #000000; font-weight: bold;">implements</span> ServletContextListener <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">InitialContext</span> ctx;
	<span style="color: #000000; font-weight: bold;">private</span> MBeanServer server;
&nbsp;
	<span style="color: #009900;">&#123;</span>
	    ctx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	    server <span style="color: #339933;">=</span> MBeanServer.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">cast</span><span style="color: #009900;">&#40;</span>ctx.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/env/jmx/runtime&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextInitialized<span style="color: #009900;">&#40;</span>ServletContextEvent sce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		server.<span style="color: #006633;">registerMBean</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ApplicationLogManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, getObjectName<span style="color: #009900;">&#40;</span>sce<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> contextDestroyed<span style="color: #009900;">&#40;</span>ServletContextEvent sce<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>server.<span style="color: #006633;">isRegistered</span><span style="color: #009900;">&#40;</span>getObjectName<span style="color: #009900;">&#40;</span>sce<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		    server.<span style="color: #006633;">unregisterMBean</span><span style="color: #009900;">&#40;</span>getObjectName<span style="color: #009900;">&#40;</span>sce<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ObjectName getObjectName<span style="color: #009900;">&#40;</span>ServletContextEvent sce<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> MalformedObjectNameException, <span style="color: #003399;">NullPointerException</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #003399;">String</span> appName <span style="color: #339933;">=</span> sce.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContextPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ObjectName<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.theserverlabs.jmx:type=ApplicationLogManager,name=&quot;</span> <span style="color: #339933;">+</span> appName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;LogManager&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>The WLST script</h2>
<p>That&#8217;s pretty much all there is to it in terms of application code. The only thing left to discuss is the Weblogic Scripting Tool (WLST) script that modifies the log level. Below is the source code (it is Python code):</p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> changeServerAppLogLevel<span style="color: black;">&#40;</span>app, logger, level, serverUrl<span style="color: black;">&#41;</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;">## connect to the server</span>
    connect<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;weblogic&quot;</span>, <span style="color: #483d8b;">&quot;weblogic&quot;</span>, url=serverUrl<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">## go to the custom MBean tree </span>
    custom<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">## go to the place where our app log level mbeans are stored. </span>
    <span style="color: #dc143c;">cd</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'com.theserverlabs.jmx/com.theserverlabs.jmx:type=ApplicationLogManager,name='</span> + app + <span style="color: #483d8b;">'LogManager'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">## horrible code necessary to invoke a Java method that changes the log level</span>
    args = jarray.<span style="color: #dc143c;">array</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>java.<span style="color: black;">lang</span>.<span style="color: black;">String</span><span style="color: black;">&#40;</span>logger<span style="color: black;">&#41;</span>, java.<span style="color: black;">lang</span>.<span style="color: black;">String</span><span style="color: black;">&#40;</span>level<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>,java.<span style="color: black;">lang</span>.<span style="color: black;">Object</span><span style="color: black;">&#41;</span>
    sig = jarray.<span style="color: #dc143c;">array</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'java.lang.String'</span>, <span style="color: #483d8b;">'java.lang.String'</span><span style="color: black;">&#93;</span>,java.<span style="color: black;">lang</span>.<span style="color: black;">String</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'changing log level to '</span> + level + <span style="color: #483d8b;">' for app '</span> + app + <span style="color: #483d8b;">' on server '</span> + serverUrl
    invoke<span style="color: black;">&#40;</span><span style="color: #483d8b;">'setLogLevel'</span>,args,sig<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'  ... done. New log levels are:'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>get<span style="color: black;">&#40;</span><span style="color: #483d8b;">'LogLevels'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># &quot;main method&quot; of the python script</span>
argslength = <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> argslength <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">3</span> :
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt;Insufficient arguments'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt;Syntax: changeAppLogLevel.py [APP NAME] [LOGGER] [LEVEL]'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt; where: APP NAME=context root of the app e.g. xxx for /xxx'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt;        LOGGER=log4j logger name'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt;        LEVEL=TRACE/DEBUG/WARN/INFO/ERROR/FATAL'</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'==&gt;   e.g: changeAppLogLevel.py xxx com.theserverlabs.blog.logging DEBUG'</span>
    exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">else</span>:
&nbsp;
    app = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
    logger = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>
    level = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># change the log level for the server. if there was more than one server</span>
    <span style="color: #808080; font-style: italic;"># in the cluster, you could add multiple calls here, each with a different </span>
    <span style="color: #808080; font-style: italic;"># server URL</span>
    changeServerAppLogLevel<span style="color: black;">&#40;</span>app, logger, level, <span style="color: #483d8b;">'t3://localhost:7001'</span><span style="color: black;">&#41;</span>
&nbsp;
    exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Hopefully the majority of this code will be clear, even if you don&#8217;t understand python. The method/function changeServerAppLogLevel() declared at the start modifies the log level for a defined logger in an application running on a specific Weblogic server. To do this it: </p>
<ul>
<li>Connects to the Weblogic server at the specified URL (note that this example uses the hardcoded username and password weblogic/weblogic</li>
<li>Moves to the custom JMX MBean tree which is where Weblogic puts all non-Weblogic MBeans</li>
<li>Moves to the place where our MBean is stored in the tree</li>
<li>Executes the setLogLevel() method of the MBean with the required arguments to change the log level. This translates to an invocation of the ApplicationLogManager.setLogLevel() method. </li>
<li>Lists the new log levels</li>
</ul>
<p>In the &#8220;main&#8221; method of the script (i.e. everything that is not in a method/function), there is some basic code to make sure the script is properly invoked and, if it is, a call to changeServerAppLogLevel() with the supplied arguments and the hard-coded URL of &#8216;t3://localhost:7001&#8242;. Obviously you should modify this value to reflect your Weblogic environment.</p>
<p>One interesting aspect of using a script to do this is that you can include a call to changeServerAppLogLevel() for each server in your cluster, if you have a multi-node setup. MBeans are published at server level so there is no concept of publishing a cluster-wide MBean (so far as I know anyway). </p>
<p>An interesting extension of this script would be to interrogate a Weblogic Admin server to find all the nodes in the cluster that were up and then execute the code to change the log level against each available node. </p>
<h2>Conclusion</h2>
<p>Hopefully this article has cleared up any confusion as to how to perform logging with log4j in a JEE app deployed on Weblogic. I think that the ability to modify dynamically the log level for a given log4j logger without having to redeploy the application is extremely useful and hopefully will be of use to people looking to do a similar thing either with Weblogic or any other JEE server that supports JMX. </p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/Y7E7lKQeYng" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/04/22/dynamically-changing-log-level-with-weblogic-log4j-jmx-and-wlst/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Server Labs at CeBIT 2010</title>
		<link>http://www.theserverlabs.com/blog/2010/02/25/the-server-labs-at-cebit-2010/</link>
		<comments>http://www.theserverlabs.com/blog/2010/02/25/the-server-labs-at-cebit-2010/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:43:37 +0000</pubDate>
		<dc:creator>Paul Parsons</dc:creator>
		
		<category><![CDATA[Cloud Computing]]></category>

		<category><![CDATA[EC2]]></category>

		<category><![CDATA[conferences]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=826</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/02/25/the-server-labs-at-cebit-2010/";</script>Come and see us at CeBIT 2010 where we will have a booth on Amazon&#8217;s Stand in the Main Exhibition Hall: Hall 2, Stand B26. We will be there on March the 4th and March the 5th.
We will be happy to chat to you about our added value in bringing IT Architecture solutions to the [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2010/02/25/the-server-labs-at-cebit-2010/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>Come and see us at <a href="http://www.cebit.com">CeBIT 2010</a> where we will have a booth on <a href="http://aws.amazon.com/solutions/solution-providers/program/cebit/">Amazon&#8217;s Stand</a> in the Main Exhibition Hall: Hall 2, Stand B26. We will be there on March the 4th and March the 5th.</p>
<p>We will be happy to chat to you about our added value in bringing IT Architecture solutions to the Cloud.</p>
<p>We will also be presenting the work on HPC we have been doing for the European Space Agency, at 13:30 on March the 4th, and at 11:00 on March the 5th, both in the Theatre at the back of the Amazon stand.</p>
<p><code><br />
Complex low-cost HPC Data Processing in the Cloud<br />
<em><br />
With the maturing of cloud computing, it is now feasible to run even the most complex HPC applications in the cloud. Data storage and high performance computing resources - fundamental for these applications – can be outsourced thus leveraging scalability, flexibility and high availability at a fraction of the cost of traditional in-house data processing. This presentation evaluates Amazon’s EC2/S3 suitability for such a scenario, by running a distributed astrometric process The Server Labs developed for the European Space Agency’s Gaia mission in Amazon EC2</em>.<br />
</code></p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/YWtcpz6fgUE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2010/02/25/the-server-labs-at-cebit-2010/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting started with JBI4Corba and Apache Servicemix</title>
		<link>http://www.theserverlabs.com/blog/2009/10/01/getting-started-with-jbi4corba-and-apache-servicemix/</link>
		<comments>http://www.theserverlabs.com/blog/2009/10/01/getting-started-with-jbi4corba-and-apache-servicemix/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 10:07:19 +0000</pubDate>
		<dc:creator>Kevin McCormack</dc:creator>
		
		<category><![CDATA[Default]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=804</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2009/10/01/getting-started-with-jbi4corba-and-apache-servicemix/";</script>I&#8217;ve recently been investigating the use of the JBI4Corba JBI Binding Component with the Apache ServiceMix Enterprise Service Bus. JBI4Corba permits a JBI compliant ESB to call corba code running outside of the bus (the consumer scenario) and to external code to call endpoints published on the bus via corba (the provider scenario). 
Why is [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2009/10/01/getting-started-with-jbi4corba-and-apache-servicemix/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p>I&#8217;ve recently been investigating the use of the <a href="http://jbi4corba.sourceforge.net/index.html">JBI4Corba</a> JBI Binding Component with the <a href="http://servicemix.apache.org/">Apache ServiceMix Enterprise Service Bus</a>. JBI4Corba permits a JBI compliant ESB to call corba code running outside of the bus (the consumer scenario) and to external code to call endpoints published on the bus via corba (the provider scenario). </p>
<p>Why is this useful? Well, there is quite a lot of corba code out there but new applications are not generally written to use corba technologies. JBI4Corba permits you to make services offered by legacy corba code available to new applications and enables existing corba code to call services published on the ESB. This means you don&#8217;t have to rewrite code that uses corba in order to integrate it into an SOA architecture. </p>
<p>This post will show you how to get started with JBI4Corba and Apache ServiceMix, using an example taken from the JBI4Corba integration tests. The idea is to show from &#8220;first principles&#8221; how to arrive at a simple JBI4Corba solution, which is something that I have failed to find myself on the web. </p>
<p>In this example, we have a simple &#8216;legacy&#8217; corba interface which just has one method that echos an input parameter String back to the caller. This interface is implemented in a Java corba Servant. We wish to make this corba interface available as a web service and call it using a standard HTTP client - which knows nothing about corba. The diagram below (taken from the JBI4Corba website) indicates how the various components will interact in this example: </p>
<p><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2009/09/jbi4corbaarchitecture.jpg"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2009/09/jbi4corbaarchitecture.jpg" alt="Architectural Components of the Example " title="Architectural Components of the Example " width="219" height="377" class="aligncenter size-full wp-image-815" /></a></p>
<p>To get started, download this code from <a href="http://www.theserverlabs.com/blog/wp-content/uploads/2009/09/blog-code.zip">here</a> and unzip it to a folder on your local machine. This example requires you to have Maven and Apache Servicemix installed on your machine. I have versions 2.09 and 3.3.1 of these two products, respectively. </p>
<h1>The Corba Code</h1>
<p>Once you have downloaded the code, run</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p> in the root directory in which you unzipped the code. The provider-simple-servant project contains the existing Corba code. In src/main/idl, you will find the Corba IDL file which expresses the Corba interfaces. In this case, it is a very simple interface:</p>
<pre>
module it{
	module imolinfo{
		module jbi4corba{
			module test{
				module testprovidersimple{
						interface Echo {
							string echo(in string msg);
						};
				};
			};
		};
	};
};
</pre>
<p>In this project, we use the Maven idlj plugin to generate the Java classes from this Corba IDL file. Below is the pom.xml configuration:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>idlj-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>generate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Echo.idl<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/includes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;emitStubs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/emitStubs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;emitSkeletons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/emitSkeletons<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;compatible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/compatible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>        
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>When you run the maven generate-sources goal or a later goal (such as compile or install), idlj generates the Corba Java classes and puts them in the /target/generated-sources/idl directory, which is on the classpath.</p>
<p>The /src/main/java/it/imolinfo/jbi4corba/test/servant/testprovidersimple/EchoSimpleImpl.java class is a Corba Servant that provides the behaviour for the Echo Corba interface. To run it, we must first be running the Sun Corba ORB daemon, which depends on your OS. Unix:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">  orbd <span style="color: #660033;">-ORBInitialPort</span> <span style="color: #000000;">1050</span> <span style="color: #660033;">-ORBInitialHost</span> localhost<span style="color: #000000; font-weight: bold;">&amp;</span></pre></div></div>

<p>Windows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">  start orbd <span style="color: #660033;">-ORBInitialPort</span> <span style="color: #000000;">1050</span> <span style="color: #660033;">-ORBInitialHost</span> localhost</pre></div></div>

<p>Once this is running ok, we run the Echo server by executing the following Maven command in the /provider-simple-servant directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn <span style="color: #7a0874; font-weight: bold;">exec</span>:java -Dexec.mainClass=<span style="color: #ff0000;">&quot;it.imolinfo.jbi4corba.test.servant.testprovidersimple.EchoSimpleImpl&quot;</span> -Dexec.args=<span style="color: #ff0000;">&quot;sunorb.properties&quot;</span></pre></div></div>

<p>In another command window, execute the following in the same /provider-simple-servant directory to run the EchoClient that tests that the server is working ok:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn <span style="color: #7a0874; font-weight: bold;">exec</span>:java -Dexec.mainClass=<span style="color: #ff0000;">&quot;it.imolinfo.jbi4corba.test.servant.testprovidersimple.EchoClient&quot;</span> -Dexec.args=<span style="color: #ff0000;">&quot;-ORBInitialPort 1050 -ORBInitialHost localhost&quot;</span></pre></div></div>

<p>When you run the client, you should see output like that below: </p>
<pre>
.....
[INFO] [exec:java]
Obtained a handle on server object: IOR:000000000000003b49444c3a69742f696d6f6c696e666f2f6a626934636f7262612f746573742f7465737470726f766964657273696d706c652f4563686f3a312e300000000000010000000000000082000102000000000a3132372e302e312e3100881a00000031afabcb0000000020cd9636e200000001000000000000000100000008526f6f74504f410000000008000000010000000014000000000000020000000100000020000000000001000100000002050100010001002000010109000000010001010000000026000000020002
  result: test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
....
</pre>
<p>If not, your Echo server is not correctly working and you need to fix this before continuing with the rest of the post. </p>
<p><em>IMPORTANT:</em> Leave the Echo server running - we will need it later on in the post. </p>
<h1>Introducing JBI4Corba</h1>
<p>Now that we know that the Corba code is working ok, we can create a JBI service unit that uses JBI4Corba to publish this Corba application on the ServiceMix ESB. The configuration to do this is in the provider-simple-jbi4corba-provider project. Unfortunately, there do not seem to be any Maven archetypes for JBI4Corba projects so we won&#8217;t look at how to create this project completely from scratch, but we will see the important steps. </p>
<p>You must generate a WSDL that describes your Corba interface so that it can be used with JBI4Corba. This can be done with the <a href="http://jbi4corba.sourceforge.net/idl2wsdltool.html">IDL to WSDL tool</a>. Download this tool from <a href="http://sourceforge.net/projects/jbi4corba/files/">here</a>, and modify the shell/batch script that is in the /bin directory (if necessary) to point to your JDK installation. Once you have it installed, run the following command in the /provider-simple-jbi4corba-provider/src/main/resources directory, substituting [path-to] for the path where you installed IDL2WSDLTool:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>path-to<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>IDL2WSDLTool Echo.idl jbi4corba.properties</pre></div></div>

<p>This generates the Echo.wsdl file which describes the Corba IDL in a WSDL format that JBI4Corba understands. The generation of this file is a bit of a pain in the neck to be honest. You have to generate a properties file which describes the IDL file, such as provider-simple-jbi4corba-provider/src/main/resources/jbi4corba.properties: </p>
<pre>
InterfaceCount=1
Interface0.FileName=Echo.wsdl
Interface0.IDLInterfaceName=Echo
Interface0.Address=Echo
Interface0.LocalizationType=NameService
Interface0.ORBPropertiesCount=3
Interface0.ORBPropertyName0=org.omg.CORBA.ORBInitialPort
Interface0.ORBPropertyValue0=1050
Interface0.ORBPropertyName1=org.omg.CORBA.ORBClass
Interface0.ORBPropertyValue1=com.sun.corba.ee.impl.orb.ORBImpl
Interface0.ORBPropertyName2=org.omg.CORBA.ORBInitialHost
Interface0.ORBPropertyValue2=localhost
</pre>
<p>This file states that there is 1 interface in the IDL file, that it is called &#8220;Echo&#8221; and that it should be published at address &#8220;Echo&#8221; in the NameService. The WSDL file generated is Echo.wsdl. </p>
<p>Note that the jbi-services.xml file in /provider-simple-jbi4corba-provider/src/main/resources makes reference to the target namespace (targetNamespace=&#8221;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&#8221;) declared at the top of the Echo.wsdl file, as well as other attrributes contained within that file.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services</span> <span style="color: #000066;">binding-component</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/jbi&quot;</span> </span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:ns0</span>=<span style="color: #ff0000;">&quot;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;provides</span> <span style="color: #000066;">interface-name</span>=<span style="color: #ff0000;">&quot;ns0:Echo&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">service-name</span>=<span style="color: #ff0000;">&quot;ns0:Echo&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">endpoint-name</span>=<span style="color: #ff0000;">&quot;EchoCorbaPort&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Once you have generated the WSDL file, run</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p> in the root of the provider-simple-jbi4corba-provider project to install the final version. </p>
<h1>Accessing the Corba code via HTTP Web services</h1>
<p>Now we will create a JBI Service Unit that publishes the Endpoint created in the JBI4Corba Service Unit via HTTP web services. To do this, we will use the Apache Servicemix maven archetypes which make it much easier to create JBI service unit projects since they auto-generate the relevant structure and file and create the JBI XML descriptor automatically at runtime. In the directory to which you downloaded the source code, run the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn archetype:create \
    -<span style="color: #007800;">DarchetypeGroupId</span>=org.apache.servicemix.tooling \
    -<span style="color: #007800;">DarchetypeArtifactId</span>=servicemix-http-consumer-service-unit \
    -<span style="color: #007800;">DgroupId</span>=it.imolinfo.jbi4corba.test-provider-simple \
    -<span style="color: #007800;">DartifactId</span>=provider-simple-http-consumer \
    -<span style="color: #007800;">DremoteRepositories</span>=http:<span style="color: #000000; font-weight: bold;">//</span>people.apache.org<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>m2-incubating-repository</pre></div></div>

<p>You should now have a new project called &#8220;provider-simple-http-consumer&#8221;. Edit the provider-simple-http-consumer/src/main/resources/xbean.xml file and replace the contents with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;beans</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:http</span>=<span style="color: #ff0000;">&quot;http://servicemix.apache.org/http/1.0&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:jbi4corba-test</span>=<span style="color: #ff0000;">&quot;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>      
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;http:endpoint</span></span>
<span style="color: #009900;">    <span style="color: #000066;">service</span>=<span style="color: #ff0000;">&quot;jbi4corba-test:Echo&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">endpoint</span>=<span style="color: #ff0000;">&quot;EchoCorbaPort&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">interfaceName</span>=<span style="color: #ff0000;">&quot;jbi4corba-test:Echo&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">role</span>=<span style="color: #ff0000;">&quot;consumer&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">locationURI</span>=<span style="color: #ff0000;">&quot;http://localhost:8192/Service/test-provider-simple/&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">defaultMep</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2004/08/wsdl/in-out&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">soap</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/beans<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This publishes a new HTTP web service at http://localhost:8192/Service/test-provider-simple/ which calls out to the jbi4corba-test:Echo Endpoint established by the provider-simple-jbi4corba-provider JBI service unit. </p>
<p>In the provider-simple-http-consumer/src/main/resources directory, create a new file called EchoSimple.wsdl and paste in the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:definitions</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimple&quot;</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">&quot;urn:jbi4corba/test-provider-simple&quot;</span> <span style="color: #000066;">xmlns:tns</span>=<span style="color: #ff0000;">&quot;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&quot;</span> <span style="color: #000066;">xmlns:imolacorba</span>=<span style="color: #ff0000;">&quot;uri://schemas.imola.it/jbi/wsdl-extensions/corba/&quot;</span> <span style="color: #000066;">xmlns:plnk</span>=<span style="color: #ff0000;">&quot;http://docs.oasis-open.org/wsbpel/2.0/plnktype&quot;</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #000066;">xmlns:soap</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot;</span> <span style="color: #000066;">xmlns:wsdl</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:types<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:schema</span> <span style="color: #000066;">attributeFormDefault</span>=<span style="color: #ff0000;">&quot;unqualified&quot;</span> <span style="color: #000066;">elementFormDefault</span>=<span style="color: #ff0000;">&quot;qualified&quot;</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">&quot;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://it.imolinfo.jbi4corba.test.testprovidersimple.Echo&quot;</span> <span style="color: #000066;">xmlns:xs</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:element</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;msg&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xs:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echoResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xs:element</span> <span style="color: #000066;">minOccurs</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;return&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xs:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xs:schema<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:types<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;parameters&quot;</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">&quot;tns:echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:part<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echoResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;parameters&quot;</span> <span style="color: #000066;">element</span>=<span style="color: #ff0000;">&quot;tns:echoResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:part<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimple&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;tns:echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:input<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:output</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echoResponse&quot;</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;tns:echoResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:output<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:portType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimpleCorbaBinding&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;tns:EchoSimple&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:binding</span> <span style="color: #000066;">transport</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/http&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;document&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:operation</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:input</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;literal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:input<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:output</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;echoResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;literal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:output<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimple&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsdl:port</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimpleCorbaPort&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;tns:EchoSimpleCorbaBinding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:address</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;http://localhost:8192/Service/test-provider-simple/&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plnk:partnerLinkType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimple&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plnk:role</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EchoSimplePortTypeRole&quot;</span> <span style="color: #000066;">portType</span>=<span style="color: #ff0000;">&quot;tns:EchoSimple&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plnk:partnerLinkType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsdl:definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Run</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p> in the root of the project to create and install the JBI Service unit. </p>
<h1>Creating the Service Assembly</h1>
<p>A JBI Service assembly is a way of packaging up JBI Service units. We will create the Service Assembly maven project using another Servicemix archetype. Run the following in the directory to which you downloaded the source code:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">mvn archetype:create \
    -<span style="color: #007800;">DarchetypeGroupId</span>=org.apache.servicemix.tooling \
    -<span style="color: #007800;">DarchetypeArtifactId</span>=servicemix-service-assembly \
    -<span style="color: #007800;">DgroupId</span>=it.imolinfo.jbi4corba.test-provider-simple \
    -<span style="color: #007800;">DartifactId</span>=provider-simple-service-assembly \
    -<span style="color: #007800;">DremoteRepositories</span>=http:<span style="color: #000000; font-weight: bold;">//</span>people.apache.org<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>m2-incubating-repository</pre></div></div>

<p>This should create a new maven sub-project called provider-simple-service-assembly which just contains a pom.xml file. Edit this file and remove the Junit dependency. Add the following instead:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${pom.groupId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provider-simple-jbi4corba-provider<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${pom.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${pom.groupId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provider-simple-http-consumer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${pom.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Run mvn install in the service assembly project directory and a new file should be created in the provider-simple-service-assembly/target directory called provider-simple-service-assembly-1.0-SNAPSHOT.jar. This is the file we will deploy to ServiceMix. </p>
<h1>Deploying to ServiceMix</h1>
<p>Download and install Apache ServiceMix 3.3.1 if you have not already done so. I will refer to the installation directory as $SERVICEMIX_HOME. Download <a href="http://sourceforge.net/projects/jbi4corba">Jbi4Corba</a> and copy it into $SERVICEMIX_HOME/hotdeploy directory. Ensure you have a Java JDK installed. Copy the $JDK_HOME/lib/tools.jar file to  $SERVICEMIX_HOME/lib/optional. </p>
<p>Start up ServiceMix by running the servicemix or servicemix.bat (depending on your OS) file in the $SERVICEMIX_HOME/bin folder. </p>
<p>Ensure that you still have the EchoServer running from earlier in this post. Now, copy the  provider-simple-service-assembly/target/provider-simple-service-assembly-1.0-SNAPSHOT.jar file to the $SERVICEMIX_HOME/hotdeploy directory. You should see a whole bunch of messages on the ServiceMix console but hopefully no (serious) errors. </p>
<p>To test if the service assembly deployed ok, go to <a href="http://localhost:8192/Service/test-provider-simple/main.wsdl">http://localhost:8192/Service/test-provider-simple/main.wsdl</a> and you should see the WSDL descriptor for the HTTP web service. Save this WSDL file somewhere on your local machine. </p>
<h1>Testing using SoapUI</h1>
<p><a href="http://www.soapui.org/">SoapUI</a> is a very effective tool for testing web services. If you have not already installed it, download and install the standard (free) edition and run it. </p>
<p>Select File > New soapUI project. Enter &#8220;test jbi4corba&#8221; as the project name and for the Initial WSDL/WADL field, browse for the WSDL file you saved from http://localhost:8192/Service/test-provider-simple/main.wsdl. Ensure the &#8220;create requests&#8221; option is ticked and click ok. Keep clicking OK till soapUI creates a TestSuite for you. Save the project. </p>
<p>Right-click on the &#8220;EchoCorbaPortBinding Test Suite&#8221; element. Choose &#8220;Launch Test Runner&#8221; and select &#8220;Launch&#8221; from the dialog. The test should complete successfully and you should see the message &#8220;message received: ?&#8221; in the debug output from the Corba Echo Server, proving that the message is making its way to the Corba code. </p>
<h1>Conclusion</h1>
<p>You can download the finished code from this article <a href="http://www.theserverlabs.com/blog/wp-content/uploads/2009/09/blog-code-final.zip">here</a>. </p>
<p>With the aid of the ServiceMix Maven archetypes and a bit of knowledge of JBI4Corba, you can make services offered by legacy Corba applications available to modern Service Oriented Architecture components via an ESB, with all of the advantages that gives. </p>
<p>Check out the rest of the JBI4Corba integration tests, available <a href="https://jbi4corba.svn.sourceforge.net/svnroot/jbi4corba/tags/jbi4corba-0_7_2/corba-bc/integration-test/">here</a> for more complex examples. </p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/_N6oqu23Utk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2009/10/01/getting-started-with-jbi4corba-and-apache-servicemix/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Eating our own Dog Food! - The Server Labs moves its Lab to the Cloud!</title>
		<link>http://www.theserverlabs.com/blog/2009/07/29/eating-our-own-dog-food-the-server-labs-moves-its-lab-to-the-cloud/</link>
		<comments>http://www.theserverlabs.com/blog/2009/07/29/eating-our-own-dog-food-the-server-labs-moves-its-lab-to-the-cloud/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 11:02:18 +0000</pubDate>
		<dc:creator>Jacobo Matute</dc:creator>
		
		<category><![CDATA[Cloud Computing]]></category>

		<category><![CDATA[Company Culture]]></category>

		<category><![CDATA[Default]]></category>

		<category><![CDATA[EC2]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[Virtualization]]></category>

		<category><![CDATA[Amazon]]></category>

		<category><![CDATA[cloud]]></category>

		<category><![CDATA[Lab]]></category>

		<guid isPermaLink="false">http://www.theserverlabs.com/blog/?p=711</guid>
		<description><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2009/07/29/eating-our-own-dog-food-the-server-labs-moves-its-lab-to-the-cloud/";</script>

After all these years dealing with servers, switches, routers and virtualisation technologies we think it´s time to move our lab into the next phase, the Cloud, specifically the Amazon EC2 Cloud.
We are actively working in the Cloud now for different projects, as you´ve seen in previous blog posts. We believe and feel this step is [...]]]></description>
			<content:encoded><![CDATA[<script type="text/javascript">dzone_url = "http://www.theserverlabs.com/blog/2009/07/29/eating-our-own-dog-food-the-server-labs-moves-its-lab-to-the-cloud/";</script><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><p><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2009/07/cloudlab_v2.jpg" alt="cloudlab" title="cloudlab" width="250" height="146" class="alignleft size-full wp-image-786" /></p>
<p>
After all these years dealing with servers, switches, routers and virtualisation technologies we think it´s time to move our lab into the next phase, <strong>the Cloud</strong>, specifically the <a href="http://aws.amazon.com/ec2/">Amazon EC2 Cloud</a>.</p>
<p>We are actively working in the Cloud now for different projects, as you´ve seen in previous blog posts. We believe and feel this step is not only a natural one but also takes us in the right direction towards a more effective management of resources and higher business agility. This fits with the needs of a company like ours and we believe it will also fit for many others of different sizes and requirements.<br />
Cloud computing is not only a niche for special projects with very specific needs. It can be used by normal companies to have a more cost effective It infrastructure, at least in certain areas.</p>
<p>In our lab we had a mixture of server configurations, comprising Sun and Dell servers running all kinds of OSs, using VMWare and Sun virtualisation technology. The purpose of our Lab is to provide an infrastructure for our staff, partners and customers to perform specific tests, prototypes, PoC´s, etc&#8230; Also, the Lab is our R &amp; D resource to create new architecture solutions.</p>
<p>Moving our Lab to the cloud will provide an infrastructure that will be more flexible, manageable, powerful, simple and definitely more elastic to setup, use and maintain, without removing any of the features we currently have. It will also allow us to concentrate more in this new paradigm, <strong>creating advanced cloud architectures</strong> and <strong>increasing the overall know-how</strong>, that can be injected back to customers and the community.</p>
<p>In order to commence this small project the first thing to do was to perform a small feasibility study to identify the different technologies to use inside the cloud to maintain confidentiality and secure access primarily, but also to properly manage and monitor that infrastructure. Additionally, one of the main drivers of this activity was to reduce our monthly hosting cost, so we needed to calculate, based on the current usage, the savings of moving to the cloud.</p>
<h1>Cost Study</h1>
<p>Looking at the cost for moving to the cloud we performed an inventory of the required CPU power, server instances, storage (for both Amazon S3 and EBS) and the estimated data IO. Additionally, we did an estimation of the volume of data between nodes and between Amazon and the external world.</p>
<p>We initially thought to automatically shutdown and bring up those servers that are only needed during working hours to save more money. In the end, we will be using Amazon reserved instances, that give a even lower per-hour price similar to the one that we would get using on-demand servers.</p>
<p>Based on this inventory and estimations, and with the help of the <a href="http://calculator.s3.amazonaws.com/calc5.html">Amazon Cost Calculator</a>, we reached a <strong>final monthly cost that was aprox. 1/3 of our hosting bill!</strong>.</p>
<p>This cost is purely considering the physical infrastructure. We need to add on top of this the savings we have on hardware renewal, pure system administration and system installation. Even if we use virtualization technologies, sometimes we´ve had to rearrange things as our physical infrastructure was limited. All these extra costs mean savings on the cloud.</p>
<h1>Feasibility Study</h1>
<p>Moving to the cloud gives a feeling to most IT managers that they lose control and most importantly, they lose control of the data. While the usage of hybrid clouds can permit the control of the data, in our case we wanted to move everything to the cloud. In this case, we are certainly not different and we are quite paranoid with our data and how would be stored in Amazon EC2. Also, we still require secure network communication between or nodes in the Amazon network and the ability to give secure external access to our staff and customers.</p>
<p>There are a set of open-source technologies that have helped us to materialize these requirements into a solution that we feel comfortable with:</p>
<ul>
<li>Filesystem encryption for securing data storage in Amazon EBS.</li>
<li>Private network and IP range for all nodes</li>
<li>Cloud-wide encrypted communication between nodes within a private IP network range via OpenVPN solution</li>
<li>IPSec VPN solution for external permanent access to the Cloud Lab, as for instance connection of private cloud/network to public EC2 Cloud</li>
<li>Use of RightScale to manage and automate the infrastructure</li>
</ul>
<div id="attachment_798" class="wp-caption alignleft" style="width: 710px"><a href="http://www.theserverlabs.com/blog/wp-content/uploads/2009/07/cloudlaboverview.jpg"><img src="http://www.theserverlabs.com/blog/wp-content/uploads/2009/07/cloudlaboverview-1024x372.jpg" alt="Overview of TSL Secure Cloud deployment" title="Overview of TSL Secure Cloud deployment" width="700" height="255" class="size-large wp-image-798" /></a><p class="wp-caption-text">Overview of TSL Secure Cloud deployment</p></div>
<h1>Implementation and Migration</h1>
<p>The implementation of our Cloud Lab solution has gone very smoothly and it is working perfectly.<br />
One of the beneficial side effects you get when migrating different systems into the cloud is that it forces you to be much more organised as the infrastructure is very focused on reutilisation and automatic recreation of the different servers.</p>
<p>We have all our Lab images standardized, taking prebuilt images available in Amazon and customising them to include the security hardening, standard services and conventions we have defined. We can in a matter of seconds deploy new images and include them into our Secure VPN-Based CloudLab network ready to be used.</p>
<p>Our new Cloud Lab is giving us a very stable, cost-effective, elastic and secure infrastructure, which can be rebuilt in minutes using EBS snapshots.</p>
<img src="http://feeds.feedburner.com/~r/TheServerLabsBlog/~4/pWFFUqKjyfY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.theserverlabs.com/blog/2009/07/29/eating-our-own-dog-food-the-server-labs-moves-its-lab-to-the-cloud/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
