System which I'm developing as a part of my PhD thesis must validate WS-BPEL before enhancing and deploying it on a remote WS-BPEL engine.
I decided to use Apache ODE
bpelc command line tool.bpelc takes as an argument the WS-BPEL process main file to be validated, for example:bin/bpelc.bat c:/Studies/PhD/nuntius/instance2/var/tmp/nuntius29dd0bfc4f0/XhGPW.bpelToday I will show you how I'm invoking it from Java and what problems I encountered.
JDK 5.0 ProcessBuilder, bpelc, and return codes
To invoke external application directly from Java I used JDK 5.0
ProcessBuilder mechanism.I wrote simple
BPELCRunner class, but I had some problems with return codes.In Java documentation you can read: "By convention,
0 indicates normal termination".By convention... which means you cannot rely on it in 100%.
When I invoked:
int result = p.waitFor();The result was always
0, even for WS-BPEL processes containing errors.Error-aware BPELCRunner
Thankfully Apache ODE developers write all error messages to error stream, this way I could detect if there was an error in WS-BPEL process.
To access error stream I could use
Process class.So, here is my error-aware complete working
BPELCRunner class:public class BPELCRunner {
private static final Logger logger = Logger.getLogger(BPELCRunner.class);
private ProcessBuilder pb;
private String message;
public BPELCRunner(String command, String bpel) {
pb = new ProcessBuilder(command, bpel);
}
public boolean compile() {
Process p = null;
try {
p = pb.start();
int result = p.waitFor();
// ignore result as it is always 0
// check the error stream instead
if (p.getErrorStream().available() > 0) {
byte[] output = new byte[2048];
int length = p.getErrorStream().read(output);
message = new String(output, 0, length);
return false;
}
} catch (Exception e) {
logger.error("Caught exception during running ODE bpelc", e);
throw new NuntiusRuntimeException("Could not validate ODE Archive");
}
return true;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}Running BPELCRunnerHere is a code to run
BPELCRunner:String bpel = "C:/Studies/Programs/geronimo-tomcat6-javaee5-2.1.3/var/temp/nuntius29dd0bfc4f0/XhGPW.bpel";
String command = "C:/Studies/Programs/apache-ode-war-1.1.1/bin/bpelc.bat";
BPELCRunner runner = new BPELCRunner(command, bpel);
boolean result = runner.compile();
if (!result) {
System.out.println("error message ==> " + runner.getMessage());
}For example, when I added <qwqw /> element to my XhGPW.bpel process, the compile() returned false and the getMessage() returned:error message ==> WARN - 2009-06-25 11:50:20,483 - <org.apache.ode.bpel.compiler.bom.BpelObjectFactory> Unrecognized element in BPEL dom: qwqwCheers,
Łukasz

0 comments:
Post a Comment