« Using OpenLDAP with WebLogic Server | Main | Automate WLS Console Tasks with WLST »

Changing WebLogic Annotations on the Fly (more detail)

This was originally posted on my dev2dev blog August 30th, 2007.

One of my customers asked me about a common use case:  they would like to change the value of a Java annotation in their deployment artifacts at deployment time without changing the code.  This way they can avoid having separate EAR files for each environment.  Using the same EAR file is very desirable because you know what you tested in QA is the same code that you are putting into production.  I'd consider that a best practice.

In this case, assume we are using Beehive Service Control to invoke a web service.  The URL of that service changes depending one each environment (dev, qa, prod).  Since Beehive is heavily annotations based  and the URL endpoint of the web service is actually put into code, how can we change that URL for the various environments without building a separate EAR file for each environment?  The solution is a combination of deployment plans (JSR-88) and a Beehive annotation override.  It turns out that Chris Hogue has already blogged this and his steps apply to 9.x and 10.x versions of WLS.  His entry is very straight-forward, but I found that the WebLogic console interface was not as intuitive as Chris's post..  So I wrote up the steps I followed to get it working.  These steps will create a plan.xml and the Beehive annotation-overrides.xml files for you,.  Once you understand the mechanisms, you could script this and apply it to other WEB-INF or META-INF files and values that might change between environments and say goodbye to multiple EAR files.

Here's Chris description of the steps to follow after deploying your EAR to WLS:

Now say I've deployed it to the production server. After deploying it the first time I can go into the WLS console, locate the control, and change the value through a simple form. To find it in the console, navigate to Deployments > [your application] > Deployment Plan > Resource Dependencies. Then locate your control in the "Controls" tree to find the available settings. It should look something like this:

I suggest you read Chris's full entry, but I'm going to get a little more granular with the instructions.

  1. First of all you need to be in a Change Session for this to take effect.
  2. Then you have to click on the “(No value specified)” label, and it will magically turn into a text box.  That was non-intuitive hang-up number 1 for me.
  3. Enter the value, BUT DO NOT LEAVE THE TEXT BOX.  In order for your value to take effect you have to hit the <ENTER> key to submit to the server while the cursor is still in the text box.  If you put that mouse anywhere else, let's say by trying to click the “Save” button, your changes will be lost, and the screen will refresh saying that the save was successful, but the Override Value will still say "(No value specified)".  This was my non-intuitive hang-up number 2.
  4. After hitting the enter key and the page loads and shows the value you typed in, then click the “Save” button.  I must admit user error on this one, I forgot to save once.  Don't miss this step.
  5. Now can activate your changes and update the application for it to take effect.

For curiosity you can browse to the directory where your deployment plan is stored (you select the directory yourself).  Your plan.xml will refer to an annotations-overrides.xml file, which you will find in the web application directory as META-INF/annotations-overrides.xml.  Here's an example of mine.  Notice the override-value where I switch to port 7001 instead of 7011.  I hope this more detailed explanation of Chris's post helps avoid the hang-ups that I encountered.

<?xml version='1.0' encoding='UTF-8'?>
<annotation-overrides xmlns="http://www.bea.com/2004/03/wlw/external-config/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <annotated-class>
    <annotated-class-name>test.HelloWebServiceControl</annotated-class-name>
    <component-type>Control Extension (JCX)</component-type>
    <annotation>
      <annotation-class-name>com.bea.control.ServiceControl$Location</annotation-class-name>
      <array-member>
        <member-name>urls</member-name>
        <member-value>http://localhost:7011/WebServiceWEB/HelloWebService</member-value>
        <override-value>http://localhost:7001/WebServiceWEB/HelloWebService</override-value>
        <cleartext-override-value>http://localhost:7001/WebServiceWEB/HelloWebService</cleartext-override-value>
      </array-member>
    </annotation>
  </annotated-class>
</annotation-overrides>

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

james_bayer.jpg

I am a Senior Sales Consultant covering enterprise customers in and around the Chicago area focusing on middleware and internet technologies. My career began as a Java consultant and architect where I experienced the technology shift toward SOA. I enjoy helping customers solve business problems by applying Oracle technology solutions.

About This Entry

This page contains a single entry from the blog posted on August 30, 2007 7:51 PM.

The previous post in this blog was Using OpenLDAP with WebLogic Server.

The next post in this blog is Automate WLS Console Tasks with WLST.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle