use of org.exist.debuggee.Debuggee in project exist by eXist-db.
the class ContextGet method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
try {
Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
if (session == null)
return StringValue.EMPTY_STRING;
Command command = new org.exist.debuggee.dbgp.packets.ContextGet(session, "");
command.exec();
return Utils.nodeFromString(getContext(), new String(command.responseBytes()));
} catch (Throwable e) {
throw new XPathException(this, Module.DEBUG001, e);
}
}
use of org.exist.debuggee.Debuggee in project exist by eXist-db.
the class Stop method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
try {
Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
if (session == null)
return BooleanValue.FALSE;
Command command = new org.exist.debuggee.dbgp.packets.Stop(session, "");
command.exec();
return BooleanValue.TRUE;
} catch (Throwable e) {
throw new XPathException(this, Module.DEBUG001, e);
}
}
use of org.exist.debuggee.Debuggee in project exist by eXist-db.
the class Run method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
try {
Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
if (session == null)
return BooleanValue.FALSE;
Command command = new org.exist.debuggee.dbgp.packets.Run(session, "");
command.exec();
return BooleanValue.TRUE;
} catch (Throwable e) {
throw new XPathException(this, Module.DEBUG001, e);
}
}
use of org.exist.debuggee.Debuggee in project exist by eXist-db.
the class StepOut method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
try {
Debuggee dbgr = BrokerPool.getInstance().getDebuggee();
IoSession session = (IoSession) dbgr.getSession(args[0].getStringValue());
if (session == null)
return BooleanValue.FALSE;
Command command = new org.exist.debuggee.dbgp.packets.StepOut(session, "");
command.exec();
return BooleanValue.TRUE;
} catch (Throwable e) {
throw new XPathException(this, Module.DEBUG001, e);
}
}
use of org.exist.debuggee.Debuggee in project exist by eXist-db.
the class XQuery method execute.
public Sequence execute(final DBBroker broker, final CompiledXQuery expression, Sequence contextSequence, final Properties outputProperties, final boolean resetContext) throws XPathException, PermissionDeniedException {
// check execute permissions
if (expression.getContext().getSource() instanceof DBSource) {
((DBSource) expression.getContext().getSource()).validate(Permission.EXECUTE);
}
final long start = System.currentTimeMillis();
final XQueryContext context = expression.getContext();
expression.reset();
if (resetContext) {
// context.setBroker(broker);
context.getWatchDog().reset();
}
if (context.requireDebugMode()) {
final Debuggee debuggee = broker.getBrokerPool().getDebuggee();
if (debuggee != null) {
debuggee.joint(expression);
}
}
// do any preparation before execution
context.prepareForExecution();
final Subject callingUser = broker.getCurrentSubject();
// if setUid or setGid, become Effective User
EffectiveSubject effectiveSubject = null;
final Source src = expression.getContext().getSource();
if (src instanceof DBSource) {
final DBSource dbSrc = (DBSource) src;
final Permission perm = dbSrc.getPermissions();
if (perm.isSetUid()) {
if (perm.isSetGid()) {
// setUid and SetGid
effectiveSubject = new EffectiveSubject(perm.getOwner(), perm.getGroup());
} else {
// just setUid
effectiveSubject = new EffectiveSubject(perm.getOwner());
}
} else if (perm.isSetGid()) {
// just setGid, so we use the current user as the effective user
effectiveSubject = new EffectiveSubject(callingUser, perm.getGroup());
}
}
try {
if (effectiveSubject != null) {
// switch to effective user (e.g. setuid/setgid)
broker.pushSubject(effectiveSubject);
}
context.getProfiler().traceQueryStart();
broker.getBrokerPool().getProcessMonitor().queryStarted(context.getWatchDog());
try {
// support for XQuery 3.0 - declare context item :=
if (contextSequence == null) {
if (context.getContextItemDeclartion() != null) {
contextSequence = context.getContextItemDeclartion().eval(null, null);
}
}
final Sequence result = expression.eval(contextSequence);
if (LOG.isDebugEnabled()) {
final NumberFormat nf = NumberFormat.getNumberInstance();
LOG.debug("Execution took {} ms", nf.format(System.currentTimeMillis() - start));
}
if (outputProperties != null) {
// must be done before context.reset!
context.checkOptions(outputProperties);
}
return result;
} finally {
context.getProfiler().traceQueryEnd(context);
// track query stats before context is reset
broker.getBrokerPool().getProcessMonitor().queryCompleted(context.getWatchDog());
expression.reset();
if (resetContext) {
context.reset();
}
}
} finally {
if (effectiveSubject != null) {
broker.popSubject();
}
}
}
Aggregations