Thursday, May 29, 2008

Making friends with WebLogic using WLST

We have been playing around with WebLogic for a few weeks now; but I have only recently watched a course on the Jython based web logic scripting langauge, WLST, that you can use to automate common operations. It turns out that the setup for the tool take a few steps, so lets quickly define an alias that starts the tool with the right environment.

alias wlst '/bin/sh -c "source $WL_HOME/server/bin/setWLSEnv.sh; java -Dpython.cachedir=/tmp/wlst weblogic.WLST \!*"'

You can run WSLT in interactive or scripting mode, we are going to focus on script mode for the moment though. You will tend to use the interactive mode to debug your scripts. All the examples here can be simply placed in a .py file and passed as a parameter to wlst.

The first thing I wanted to do is the automate setting the HTTP/Tunneling preference which is required to enable deployment from within JDeveloper. Since we get new builds quite often I wanted a quick workaround. You can do this with the server running, and the commands are slightly different, but I went with off-line modification of configuration files.

readDomain('/ade/gdavison_wls/wls10/beahome/user_projects/domains/base_domain')
cd ('Server/AdminServer')
set ('TunnelingEnabled', true)
updateDomain()
closeDomain()

Now the server is properly configured you will probably want to start it. There is a script to do this but I figured would be interesting to do this using a WLST:

startServer('AdminServer', 'base_domain', 't3://localhost:7001', 'weblogic', 'weblogic', '/ade/gdavison_wls/wls10/beahome/user_projects/domains/base_domain', 'true')

And of course you might want to shut it down later. Since the AdminServer is the default local connection as I am not worried about clusters for the moment we can connection with the default connection information and force a server shutdown.

connect("weblogic","weblogic")
shutdown(force="true")

Of course this has just scratched the surface of what you can do with this tool. The jython underpinning makes it really easy to do powerful things. For example this blog entry shows how to automate setting up a cluster. You can also impressively record operation when using web console and later use them in scripts to configure another server.

Wednesday, May 28, 2008

Still waiting on Mac support from Sentilla

So I got a Perk pack at JavaOne this year and I am told the wait for a OS X/Linux developement tool is nearly over. Got an email from Spence at Sentilla saying we should have something in 1-2 weeks.

Looking forward to working with this system, still a big cloud over how much each mote will cost for production purposes. I was told I could perhaps buy perk kits after JavaOne; but don't want to commit until I have had some time to play. To be honest after talking to more than a few Sentilla sales people I am not sure they knew quite how they were going to deliver this stuff.

That being said the Java API they provide looks really promising. Nice use of Generics and the JScience API allow you to get typed "temperature" values back for example. The cloud networking protocols are also really easy to work with.

I hope they get there tools delivered and their pricing policy more defined soon. Otherwise they are going to remain curious toys.

Tuesday, May 20, 2008

Some pictures of Manoj and I on stage at JavaOne

In case you are wondering we are trying to tidy the podium whilst answering questions. We are not, as it appears in the photos, laying down some phat tracks as part of a DJ set.

Manoj points out the falicy in the questioners argument.

In real life I have more hair than this, honest.

Thanks to Nilesh, Manoj's boss, for providing these pictures.

Thursday, May 15, 2008

Java One 2008, day four, part two

Right back in blighty so before I forget everything just a few notes on the final day of presentations. Generally the friday isn't as well attended as the rest of the week with quite a few people leaving early; but there was still a lot of good stuff and a whole bunch of repeats of very popular presentations.

The first presentation of the day was TS-5796 JavaFX Patterns which took me a little while to get up to speed on, having never looked at JavaFX properly before, but I was impressed just how easy it to build ui application. The ability to bind variables is the key with the run time environment dealing with pushing updates without having to ever think about dealing with a Thread. In fact the take home message here is that JavaFX is single threaded and if you are using native java threads you are probably going about the problem in the wrong way for most common operations.

One problem with the current builds of JavaFX is there is no automatic binding from Collections to JavaFX sequence and indeed to bean properties on POJOs to JavaFX properties. This mean you have to create a wrapper to access "properties" on POJO which is a real pain. This is something jython has right but I can't speak for the other programming langauges.

Quick break, bumped into my old manager at Oracle standing in front of the big TV screen said hi and then back into some serious sessions.

Next up was TS - 6547 which covered the Hudson build integration system. Never met it before but was pleasantly surprised about how well it deals with common actions. Although I do wonder how well the, admittedly swish, web ui will scale up to deal with more complicated systems. That being said the system is extensible so it should be possible to add some graphs to make build / test dependencies cleared. This is specially important when building and testing multiple modules.

I like the ability to run a <100k web start app on your machine and add it to the build pool. A nice thing to do when you go home at night or away on holiday. Might save buying even more dedicated machines.

This presentation wins the prize for the most inappropriate metaphor used at Java One this year. The "Omaha Beach" pattern used to describe throwing many build systems at a problem.

After a bit of lunch, out of the infected convention center just to make sense, I took a bit out of the closing session of the Grizzly presentation. This builds on top of NIO to provide a very scalable server backbone. Used in many place such as the cometd server mentioned previously and of course at the core of glassfish. Very powerful stuff but not generally something that you will use directly. Interesting note that 1.8 will support the new full asynchronous NIO.2 API I talked about earlier. They reckon they get 10% better performance in that configuration. Of course you would have to risk you production sever on a JDK 7 label!

Last nugget of information of the day comes from TS - 6145 which looked at some pratical examples of using D-Trace with java. I did find the syntax required to talk monitor java using "d" to be a bit over complicated. Mostly this is due to the need to pass in lengths for all the string properties. How C.

There was a java API both for defining probe points, and hence making the "d" less complication, and doing d-trace monitoring from java. (These live in the "com.sun.tracing.*" package) Of course these only exist on Solaris and OS X so you need to consider you options when running on different platforms.

The presenters were very good reminding me of Simon Day when he was on a roll. The key point to take away is that D-Trace should be used as a way of getting answers to questions rather than a more general profiling tool. For example if I know that a method is called too many times and I can quickly ask D-Trace for stats on how often it is called in each place. Can be really powerful stuff. Sadly my day-to-day development environment, Linux, wont have support for D-Trace for some time as the Linux maintainers appear to want to create a new technology rather than reuse this one.

At that point my brain was really quite full so it was time to quit the conference and spend a little bit of time not learning anything. Ah the Metreon and "Iron Man" there I went.

Errata for our java one presentation TS-5318

Well it turns out that not matter how many times you read it the transition to powerpoint tends to make code that doesn't run or compile

Slide: Callback Implementation for JAX-WS

Notice extra brackets to make the code compile, and the change of variable name in the loop.

// Deal with response

@Resource WebServiceContext wsContext;

public void getPriceResponse(String _return)
{
 SOAPHeader sh = ((SOAPMessageContext)wsContext   
  .getMessageContext()).getMessage().getSOAPHeader();
    
 String relatesToMessageId = null;
 for (Iterator it =
  sh.getChildElements(AddressingVersion.W3C.relatesToTag);
  it.hasNext(); ) {
      SOAPHeaderElement obj =(SOAPHeaderElement)it.next();
      relatesToMessageId = obj.getTextContent();  break;
}

We found out later that if you are using RI then this code wont work because the message context is never of type SOAPMessageContext. So you might need to use code that looks something like the following block. Anoyingly this code wont work with non-RI based implements. (See also)

// Deal with response

@Resource WebServiceContext wsContext;

public void getPriceResponse(String _return)
{
 HeaderList hl = context.getMessageContext().get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
 Header h = hl.get(AddressingVersion.W3C.relatesToTag);
 String relatesToMessageId = h.getStringContent();
}

You could of course be using a Handler which will have a consistent SOAPMessageContext; but I find it makes the code just much harder to follow.

Every slide

Interestingly each and every slide has a url starting "java.dun.com", I have no idea how that typo got in there!

Wednesday, May 14, 2008

Running wsgen easily from within JDeveloper

It occured to me that in my previous post if you are deploying to a jax-ws platform that is pre 2.1.4, and need to run wsgen, you might like an easier way of doing it that doesn't require you to shell out to ant. (For example JAX-WS deployed to BEA WLS 10.2 and 10.3 tech preview or deployed to earlier builds of glassfish)

The easiest way to do this is to go to Tools->External Tools and create a new tool entry. On the first page of the wizard enter the path to wsgen(.sh|.bat)? on your platform, this is in the "bin" directory under JDK 6. Run directory isn't important; but in the arguments box put the following code:

-d ${project.outputdirectory} -s ${project.first.sourcepath} -keep -cp ${project.outputdirectory} ${target.class}

On the next page I will leave it up to you to put the right entries in for display as this is down to personal preference. On the integration page you probably want:

  • Only add to "Navigator Context Menu"
  • Before tool starts "Save All"
  • After tool exits "Reload Open Files"
  • Log output to message console

On the avaliability page make sure you only enable this for "Java Source" file types. It is probably not a good idea to allow this on other types. And thats it, you can now right click on a java web service and generate the extra boiler plate classes when you start fom the java class and work your way up. (Also known as bottom up)

You might have to refresh the navigator to see new files when they are generated, I am going to raise a bug for this and try to see if we can get JDeveloper to do this for you.

Update 9th June 2009

I noticed a slight bug in the above command line as it is missing the project classpath, this can cause the task to fail if you are using EJB for example. (Make sure you swap the ; for a : if you are on unix/mac.

-d ${project.outputdirectory} -s ${project.first.sourcepath} -keep -cp ${project.outputdirectory};${project.classpath ${target.class}

JAX-WS RI 2.1.4 released

JAX-WS RI progresses at a pace. Has a the "simplified" bottom-up deployment model that you have been able to enjoy in OC4J for a while.

They also have a nice example of using the sun-jaxws.xml file to speficy dual bindings for the same class file:

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name='soap'
        implementation='dual_binding.server.AddNumbersImpl'
        port='{http://server.dual_binding/}soap'
        url-pattern='/soap'/>
    <endpoint
        name='rest'
        implementation='dual_binding.server.AddNumbersImpl'
        port='{http://server.dual_binding/}rest'
        binding="http://jax-ws.dev.java.net/rest"
        url-pattern='/rest'/>
</endpoints>

It is nice to have the standard evolve so quickly.