I'm calling a java class from BPEL via bpelx:exec. It would simplify things a lot if the class was able to throw a specific Fault (known to BPEL from one of its partner links). Let's call it AdapterFault. AdapterFault is generated by wsimport and subclasses Exception.
Here's the code within Embedded Java block:
Object wfr = getVariableData("inputVariable","request");
Object req = getVariableData("V_CreateServiceRequest","createTNRequestPart");
somepackage.EndpointIterator it =
new somepackage.EndpointIterator();
it.setWFRequest(wfr);
it.setPlatformName("MMSC");
it.setOperationName("createTN");
it.setRequest(req);
Object reply = it.invoke();
setVariableData("V_CreateServiceResp开发者_StackOverflow社区onse","createTNResponsePart",reply);
When I declare the java method as throwing the AdapterFault, the BPEL refuses to deploy complaining that Exception is uncaught. It seems that Java callout step only declares BPELFault.
I'm only able to throw RuntimeException, which goes to CatchAll block instead of catch(AdapterFault).
Is there a simple way to throw a checked Fault from a java call-out?
If it is a WSIF binding there are instructions here under the "Exception Handling" heading, but that article is pretty old.
For bpelx:exec (I think) you need to catch the exception within the block and update a variable as such
try {
... do things} catch(Exception ex) {
addAuditTrailEntry("Exception message: " + ex.getMessage());
setVariableData("V_CreateServiceException",...
}
}
Only BPELFault can be thrown:
http://forums.oracle.com/forums/thread.jspa?threadID=547192
But it could include the nested part, which is the "real" exception, which can be extracted in Catch block and re-thrown, if required.
I have implemented it today.
Gotchas:
- Catch block should catch one of the system exceptions, e.g. remoteFault.
- RuntimeFault.wsdl shall be imported (wsdl:import) into one of the partner WSDLs, otherwise a nasty error saying that BPELFault is not found will be thrown
BPELFault is rather limited in that it can only have code, message and detail elements, all plain text. Passing a complex nested fault type to BPEL is possible via bpelFault.setPart("myname",obj), but I don't know how to extract it from the BPELFault, as BPEL sees no "dynamic" parts. Code and message is enough for my purposes though.
精彩评论