Publish Drools artifacts from a production environment

Enterprise people often want a production repository that is physically separated from development repository. One approach to address this requirement is to automatically pull published artifacts from development repository then copy them to a http server. As Guvnor already has the capability of publishing artifacts through its REST interface, what we really need is a simple copy script that copies published artifacts from Guvnor dev repository to a HTTP server based on certain metadata for example lifecycle state. Following example shows how to do this with a Java client.

2. Poll package version feed periodically. When a new version of package is available, the client can ask Guvnor to send it back an Atom Entry which contains detailed package metadata for this version. Based on package metadata (for example, lifecycle state or categories), the client pulls package binary from Guvnor then save they to a configured location on the HTTP server.

Here is an example code:

public class AtomClient extends TimerTask {

private Date lastUpdateDate;

private String feedURL;

public AtomClient(String feedURL) {

this.feedURL = feedURL;

}

public void run() {

try {

System.out.println("-----Polling feed----");

List entries = createFeed().getEntries();

for (Entry entry : entries) {

if (isEntryUpdated(entry)) {

String title = entry.getTitle();

System.out.println("-------Found a new entry -

");

System.out.println("Title: " + title);

System.out.println("Updated: " + entry.getUpdated());

String contentSrcPath = entry.getLinks().get(0).getHref().toString();

InputStream is = getPackageBinary(contentSrcPath);

String NS = "";

QName METADATA = new QName(NS, "metadata");

QName STATE = new QName(NS, "stage");

ExtensibleElement metadataExtension = entry.getExtension(METADATA);

String state = metadataExtension.getSimpleExtension(STATE);

System.out.println("state: " + state);

//We can copy package binary to different locations based on state info.