Author: mszefler
Date: Tue Jan 2 21:19:40 2007
New Revision: 492044
URL: http://svn.apache.org/viewvc?view=rev&rev=492044
Log:
Runtime sanity checks.
Added:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidContextException.java
Modified:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidProcessException.java
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PICK.java
Modified:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java?view=diff&rev=492044&r1=492043&r2=492044
==============================================================================
---
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
(original)
+++
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/engine/BpelProcess.java
Tue Jan 2 21:19:40 2007
@@ -398,7 +398,7 @@
mex.setFailure(FailureType.UNKNOWN_OPERATION,
mex.getOperationName(), null);
return;
}
-
+
mex.getDAO().setPartnerLinkModelId(_plinkDef.getId());
mex.setPortOp(_plinkDef.myRolePortType, operation);
mex.setPattern(operation.getOutput() == null ?
MessageExchangePattern.REQUEST_ONLY
Added:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidContextException.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidContextException.java?view=auto&rev=492044
==============================================================================
---
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidContextException.java
(added)
+++
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidContextException.java
Tue Jan 2 21:19:40 2007
@@ -0,0 +1,31 @@
+package org.apache.ode.bpel.runtime;
+
+/**
+ * Exception used by the runtime to indicate a problem with the execution
context. This
+ * is for dealing with conditions where the runtime expects certain things of
the context
+ * and the context does not oblige. These are what one might call "internal
errors", for
+ * example if a message is received and it does not have the required parts,
this execption
+ * is thrown, since the runtime expects received messages to be of the correct
form.
+ *
+ * @author Maciej Szefler - m s z e f l e r @ g m a i l . c o m
+ *
+ */
+public class InvalidContextException extends RuntimeException {
+
+ public InvalidContextException() {
+ super();
+ }
+
+ public InvalidContextException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidContextException(String message) {
+ super(message);
+ }
+
+ public InvalidContextException(Throwable cause) {
+ super(cause);
+ }
+
+}
Modified:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidProcessException.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidProcessException.java?view=diff&rev=492044&r1=492043&r2=492044
==============================================================================
---
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidProcessException.java
(original)
+++
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/InvalidProcessException.java
Tue Jan 2 21:19:40 2007
@@ -21,52 +21,54 @@
/**
* A run-time exception indicating that the process is invalid. This should not
* normally occur: that is, a process should be found to be invalid before it
is
- * executed. Therefore, this can be viewed as a rather rare and serious
condition.
+ * executed. Therefore, this can be viewed as a rather rare and serious
+ * condition.
*/
public class InvalidProcessException extends RuntimeException {
private static final long serialVersionUID = 9184731070635430159L;
-
- public final static int DEFAULT_CAUSE_CODE = 0;
- public final static int RETIRED_CAUSE_CODE = 1;
-
- private final int causeCode;
-
- public InvalidProcessException(String msg, Throwable cause) {
- super(msg,cause);
- this.causeCode = DEFAULT_CAUSE_CODE;
- }
-
- public InvalidProcessException(String msg) {
- super(msg);
- this.causeCode = DEFAULT_CAUSE_CODE;
- }
-
- public InvalidProcessException(Exception cause) {
- super(cause);
- this.causeCode = DEFAULT_CAUSE_CODE;
- }
-
- /**
- * @param causeCode
- */
- public InvalidProcessException(final int causeCode) {
- super();
- this.causeCode = causeCode;
- }
-
- /**
- * @param message
- * @param causeCode
- */
- public InvalidProcessException(String message, final int causeCode) {
- super(message);
- this.causeCode = causeCode;
- }
-
- /**
- * @return the cause code
- */
- public int getCauseCode() {
- return causeCode;
- }
+
+ public final static int DEFAULT_CAUSE_CODE = 0;
+
+ public final static int RETIRED_CAUSE_CODE = 1;
+
+ private final int causeCode;
+
+ public InvalidProcessException(String msg, Throwable cause) {
+ super(msg, cause);
+ this.causeCode = DEFAULT_CAUSE_CODE;
+ }
+
+ public InvalidProcessException(String msg) {
+ super(msg);
+ this.causeCode = DEFAULT_CAUSE_CODE;
+ }
+
+ public InvalidProcessException(Exception cause) {
+ super(cause);
+ this.causeCode = DEFAULT_CAUSE_CODE;
+ }
+
+ /**
+ * @param causeCode
+ */
+ public InvalidProcessException(final int causeCode) {
+ super();
+ this.causeCode = causeCode;
+ }
+
+ /**
+ * @param message
+ * @param causeCode
+ */
+ public InvalidProcessException(String message, final int causeCode) {
+ super(message);
+ this.causeCode = causeCode;
+ }
+
+ /**
+ * @return the cause code
+ */
+ public int getCauseCode() {
+ return causeCode;
+ }
}
Modified:
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PICK.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PICK.java?view=diff&rev=492044&r1=492043&r2=492044
==============================================================================
---
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PICK.java
(original)
+++
incubator/ode/trunk/bpel-runtime/src/main/java/org/apache/ode/bpel/runtime/PICK.java
Tue Jan 2 21:19:40 2007
@@ -23,8 +23,12 @@
import org.apache.ode.bpel.common.CorrelationKey;
import org.apache.ode.bpel.common.FaultException;
import org.apache.ode.bpel.explang.EvaluationException;
+import org.apache.ode.bpel.o.OElementVarType;
+import org.apache.ode.bpel.o.OMessageVarType;
import org.apache.ode.bpel.o.OPickReceive;
import org.apache.ode.bpel.o.OScope;
+import org.apache.ode.bpel.o.OXsdTypeVarType;
+import org.apache.ode.bpel.o.OMessageVarType.Part;
import org.apache.ode.bpel.runtime.channels.FaultData;
import org.apache.ode.bpel.runtime.channels.PickResponseChannel;
import org.apache.ode.bpel.runtime.channels.PickResponseChannelListener;
@@ -34,9 +38,13 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import com.sun.org.apache.xalan.internal.xsltc.DOM;
+
import java.util.Calendar;
+import java.util.Collection;
import java.util.Date;
+import javax.xml.namespace.QName;
/**
* Template for the BPEL <code>pick</code> activity.
@@ -54,10 +62,9 @@
public PICK(ActivityInfo self, ScopeFrame scopeFrame, LinkFrame linkFrame)
{
super(self, scopeFrame, linkFrame);
- _opick= (OPickReceive) self.o;
+ _opick = (OPickReceive) self.o;
}
-
/**
* @see org.apache.ode.jacob.JacobRunnable#run()
*/
@@ -70,18 +77,23 @@
selectors = new Selector[_opick.onMessages.size()];
int idx = 0;
for (OPickReceive.OnMessage onMessage : _opick.onMessages) {
- CorrelationKey key = null; // this will be the case for the
createInstance activity
+ CorrelationKey key = null; // this will be the case for the
+ // createInstance activity
PartnerLinkInstance pLinkInstance =
_scopeFrame.resolve(onMessage.partnerLink);
if (onMessage.matchCorrelation == null &&
!_opick.createInstanceFlag) {
- // Adding a route for opaque correlation. In this case,
correlation is on "out-of-band" session-id
+ // Adding a route for opaque correlation. In this case,
+ // correlation is on "out-of-band" session-id
String sessionId =
getBpelRuntimeContext().fetchMySessionId(pLinkInstance);
- key = new CorrelationKey(-1, new String[]{sessionId});
+ key = new CorrelationKey(-1, new String[] { sessionId });
} else if (onMessage.matchCorrelation != null) {
- if
(!getBpelRuntimeContext().isCorrelationInitialized(_scopeFrame.resolve(onMessage.matchCorrelation)))
{
- // the following should really test if this is a
"join" type correlation...
+ if (!getBpelRuntimeContext().isCorrelationInitialized(
+ _scopeFrame.resolve(onMessage.matchCorrelation))) {
+ // the following should really test if this is a "join"
+ // type correlation...
if (!_opick.createInstanceFlag)
- throw new
FaultException(_opick.getOwner().constants.qnCorrelationViolation, "Correlation
not initialized.");
+ throw new
FaultException(_opick.getOwner().constants.qnCorrelationViolation,
+ "Correlation not initialized.");
} else {
key =
getBpelRuntimeContext().readCorrelation(_scopeFrame.resolve(onMessage.matchCorrelation));
@@ -90,24 +102,25 @@
}
}
- selectors[idx] = new Selector(idx, pLinkInstance,
onMessage.operation.getName(), onMessage.operation.getOutput() == null,
onMessage.messageExchangeId, key);
+ selectors[idx] = new Selector(idx, pLinkInstance,
onMessage.operation.getName(), onMessage.operation
+ .getOutput() == null, onMessage.messageExchangeId,
key);
idx++;
}
timeout = null;
for (OPickReceive.OnAlarm onAlarm : _opick.onAlarms) {
- Date dt = onAlarm.forExpr != null
- ?
offsetFromNow(getBpelRuntimeContext().getExpLangRuntime().evaluateAsDuration(onAlarm.forExpr,
getEvaluationContext()))
- :
getBpelRuntimeContext().getExpLangRuntime().evaluateAsDate(onAlarm.untilExpr,
getEvaluationContext()).getTime();
+ Date dt = onAlarm.forExpr != null ?
offsetFromNow(getBpelRuntimeContext().getExpLangRuntime()
+ .evaluateAsDuration(onAlarm.forExpr,
getEvaluationContext())) : getBpelRuntimeContext()
+ .getExpLangRuntime().evaluateAsDate(onAlarm.untilExpr,
getEvaluationContext()).getTime();
if (timeout == null || timeout.compareTo(dt) > 0) {
timeout = dt;
_alarm = onAlarm;
}
}
getBpelRuntimeContext().select(pickResponseChannel, timeout,
_opick.createInstanceFlag, selectors);
- } catch(FaultException e){
+ } catch (FaultException e) {
__log.error(e);
- FaultData fault = createFault(e.getQName(), _opick,e.getMessage());
+ FaultData fault = createFault(e.getQName(), _opick,
e.getMessage());
dpe(_opick.outgoingLinks);
_self.parent.completed(fault, CompensationHandler.emptySet());
return;
@@ -129,7 +142,9 @@
/**
* Calculate a duration offset from right now.
- * @param duration the offset
+ *
+ * @param duration
+ * the offset
* @return the resulting date.
*/
private static Date offsetFromNow(Duration duration) {
@@ -138,6 +153,66 @@
return cal.getTime();
}
+ @SuppressWarnings("unchecked")
+ private void initVariable(String mexId, OPickReceive.OnMessage onMessage) {
+ // This is allowed, if there is no parts in the message for example.
+ if (onMessage.variable == null)
+ return;
+
+ Element msgEl = getBpelRuntimeContext().getMyRequest(mexId);
+ Collection<String> partNames = (Collection<String>)
onMessage.operation.getInput().getMessage().getParts()
+ .keySet();
+
+ // Let's do some sanity checks here so that we don't get weird errors
in assignment later.
+ // The engine should have checked to make sure that the messages that
are delivered conform
+ // to the correct format; but you know what they say, don't trust
anyone.
+ if (!(onMessage.variable.type instanceof OMessageVarType)) {
+ String errmsg = "Non-message variable for receive: should have
been picked up by static analysis.";
+ __log.fatal(errmsg);
+ throw new InvalidProcessException(errmsg);
+ }
+
+ OMessageVarType vartype = (OMessageVarType) onMessage.variable.type;
+
+ // Check that each part contains what we expect.
+ for (String pName : partNames) {
+ QName partName = new QName(null, pName);
+ Element msgPart = DOMUtils.findChildByName(msgEl, partName);
+ Part part = vartype.parts.get(pName);
+ if (part == null) {
+ String errmsg = "Inconsistent WSDL, part " + pName + " not
found in message type " + vartype.messageType;
+ __log.fatal(errmsg);
+ throw new InvalidProcessException(errmsg);
+ }
+ if (msgPart == null) {
+ String errmsg = "Message missing part: " + msgPart;
+ __log.fatal(errmsg);
+ throw new InvalidContextException(errmsg);
+ }
+
+ if (part.type instanceof OElementVarType) {
+ OElementVarType ptype = (OElementVarType) part.type;
+ Element e = DOMUtils.getFirstChildElement(msgPart);
+ if (e == null) {
+ String errmsg = "Message (element) part " + pName + " did
not contain child element.";
+ __log.fatal(errmsg);
+ throw new InvalidContextException(errmsg);
+ }
+
+ QName qn = new QName(e.getNamespaceURI(), e.getLocalName());
+ if(!qn.equals(ptype.elementType)) {
+ String errmsg = "Message (element) part " + pName + " did
not contain correct child element: expected "
+ + ptype.elementType + " but got " + qn;
+ __log.fatal(errmsg);
+ throw new InvalidContextException(errmsg);
+ }
+ }
+
+ }
+
+
getBpelRuntimeContext().initializeVariable(_scopeFrame.resolve(onMessage.variable),
msgEl);
+
+ }
private class WAITING extends BpelJacobRunnable {
private static final long serialVersionUID = 1L;
@@ -169,22 +244,18 @@
}
FaultData fault;
- Element msgEl =
getBpelRuntimeContext().getMyRequest(mexId);
- try {
-
getBpelRuntimeContext().initializeVariable(_scopeFrame.resolve(onMessage.variable),msgEl);
- } catch (Exception ex) {
- __log.error(ex);
- throw new RuntimeException(ex);
- }
+ initVariable(mexId, onMessage);
try {
for (OScope.CorrelationSet cset :
onMessage.initCorrelations) {
initializeCorrelation(_scopeFrame.resolve(cset),
_scopeFrame.resolve(onMessage.variable));
}
if (onMessage.partnerLink.hasPartnerRole()) {
- // Trying to initialize partner epr based on a
message-provided epr/session.
+ // Trying to initialize partner epr based on a
+ // message-provided epr/session.
- if
(!getBpelRuntimeContext().isPartnerRoleEndpointInitialized(_scopeFrame
- .resolve(onMessage.partnerLink)) ||
!onMessage.partnerLink.initializePartnerRole) {
+ if
(!getBpelRuntimeContext().isPartnerRoleEndpointInitialized(
+ _scopeFrame.resolve(onMessage.partnerLink))
+ ||
!onMessage.partnerLink.initializePartnerRole) {
Node fromEpr =
getBpelRuntimeContext().getSourceEPR(mexId);
if (fromEpr != null) {
@@ -198,8 +269,8 @@
String partnersSessionId =
getBpelRuntimeContext().getSourceSessionId(mexId);
if (partnersSessionId != null)
-
getBpelRuntimeContext().initializePartnersSessionId(_scopeFrame.resolve(onMessage.partnerLink),
- partnersSessionId);
+
getBpelRuntimeContext().initializePartnersSessionId(
+
_scopeFrame.resolve(onMessage.partnerLink), partnersSessionId);
}
} catch (FaultException e) {
@@ -211,22 +282,25 @@
}
// load 'onMessage' activity
- // Because we are done with all the DPE, we can simply
re-use our control
+ // Because we are done with all the DPE, we can simply
+ // re-use our control
// channels for the child.
ActivityInfo child = new ActivityInfo(genMonotonic(),
onMessage.activity, _self.self, _self.parent);
- instance(createChild(child,_scopeFrame,_linkFrame));
+ instance(createChild(child, _scopeFrame, _linkFrame));
}
public void onTimeout() {
- // Dead path all the onMessage activiites (the other
alarms have already been DPE'ed)
+ // Dead path all the onMessage activiites (the other alarms
+ // have already been DPE'ed)
for (OPickReceive.OnMessage onMessage : _opick.onMessages)
{
dpe(onMessage.activity);
}
- // Because we are done with all the DPE, we can simply
re-use our control
+ // Because we are done with all the DPE, we can simply
+ // re-use our control
// channels for the child.
ActivityInfo child = new ActivityInfo(genMonotonic(),
_alarm.activity, _self.self, _self.parent);
- instance(createChild(child,_scopeFrame,_linkFrame));
+ instance(createChild(child, _scopeFrame, _linkFrame));
}
public void onCancel() {