The AMSeT Project Blog

Saturday Sep 26, 2009

Pathy News

Or... Status Symbols for the Java Developer.

This might save someone 10 minutes or so.

Here's the problem. You have nested arrays that you want to loop over to display in a jasper and bind these to form elements using Spring.

Specifically, the SWORD bean hierarchy in AMSeT contains a branch consisting of

serviceDocumentContext.serviceDocument.service.workflowList.collections.

The workflowList and collections objects are lists and each have a number of simple datatype fields that need to be bound to a form input element using Spring.

Using JSTL the basic construct is nested <c:forEach/> elements. Normally you would write something like

<c:forEach items="${serviceDocumentContext.serviceDocument.service.workflowList}" var="workflow">

and then loop using $workflow as the representative indexed item.

Now, each workflow has a title. The title of the first workflow would be accessed using the following variable:

${serviceDocumentContext.serviceDocument.service.workflowList[0].title}

Each collection has a title, which for the first worklow and first collection would be found at

${serviceDocumentContext.serviceDocument.service.workflowList[0].collections[0].title}

Both workflow and collections have several fields and you want to output them all. Some index variable is needed to label the iterations. This is where the varStatus attribute of the <c:forEach/> comes into play.

Forget about var for a while - this justs confuses the issue when it comes to Spring which doesn't recognise the usage.

The varStatus attribute represents a LoopTagStatus object, one of whose fields is index which is a
zero-start counter for the iteration.

So the forEach becomes:

<c:forEach items="${../../...workflowList}" varStatus="wloop" ></c:forEach>

For the inner collections loop we have:

<c:forEach items="${../../...collections}" varStatus="cloop"></forEach>

The general title field of collections then becomes:

${serviceDocumentContext.serviceDocument.service.workflowList[wloop.index].collections[cloop.index].title}

Note no dollars on the index.

In order to bind a form element to Spring the following construct is required:

<spring:bind path="serviceDocumentContext.serviceDocument.service.workspaceList[${wloop.index}].collections[${cloop.index}].title">

<input type="hidden" name="<c:out value='${status.expression}'/>" value="<c:out value='${status.value}'/>" />

</spring:bind>

Note the dollar variable notation for the index in the Spring path.

The ${status.expression} and ${status.value} variables apply to the object pointed to in the Spring path. The expression is the precise path expression of the object bound to the form element and the value is its value, a string or integer.

Cock-a-doodle-do.

Tuesday Jul 14, 2009

wsmonitor

When developing Web services and workflows, a tool to monitor outgoing and incoming messages is pretty much essential.

There are a few candidates here: SOAPMonitor, soapUI, TCPMon, tcpmon. I have used wsmonitor (Web Services Monitor) most of the time and find it is easy to use and works well.

It uses port-forwarding and intercepts all HTTP traffic in and out of a port specified in a config.xml file. Outgoing messages are then re-routed to the ultimate Web service endpoint.

An example config.xml file is given below:

<monitor xmlns="http://java.sun.com/xml/ns/jax-ws/ri/config/monitor"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="config.xsd">
<connection
name="5050 --> my.webservicehost.ac.uk:8080"
description="5050->8080"
listenPort="5050"
targetHost="my.webservicehost.ac.uk"
targetPort="8080"/>
</monitor>

In order for this to work the host in the service endpoint URL in the WSDL file must be changed to http://localhost:5050/myservice from http://my.webservicehost.ac.uk:8080/myservice.

Unzipping the distribution file provides an executable in the bin directory. Placing the config.xml file in the bin and executing

>wsmonitor config.xml

from the command line, wsmonitor would then look the following:

wsmonitor

Connections to multiple servers can be created simultaneously, each with a different listen port.

Calendar

Search

Navigation