use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class GenericHandler method doService.
/**
* doService() is called by Dispatcher to perform web service.
*
* @return
* @throws NavajoException
* @throws UserException
* @throws SystemException
* @throws AuthorizationException
*/
@Override
public final Navajo doService(Access a) throws UserException, SystemException, AuthorizationException {
if (a.isBreakWasSet()) {
if (a.getOutputDoc() == null) {
Navajo outDoc = NavajoFactory.getInstance().createNavajo();
a.setOutputDoc(outDoc);
}
return a.getOutputDoc();
}
Navajo outDoc = null;
StringBuilder compilerErrors = new StringBuilder();
outDoc = NavajoFactory.getInstance().createNavajo();
CompiledScriptInterface cso = null;
try {
cso = loadOnDemand(a, a.rpcName);
} catch (Throwable e) {
logger.error("Exception on getting compiledscript", e);
if (e instanceof FileNotFoundException) {
a.setExitCode(Access.EXIT_SCRIPT_NOT_FOUND);
}
throw new SystemException(-1, e.getMessage(), e);
}
try {
if (cso == null) {
if (Version.osgiActive()) {
logger.warn("Script not found from OSGi registry while OSGi is active");
}
logger.error("No compiled script found, proceeding further is useless.");
throw new RuntimeException("Can not resolve script: " + a.rpcName);
}
a.setOutputDoc(outDoc);
a.setCompiledScript(cso);
if (cso.getClassLoader() == null) {
logger.error("No classloader present!");
}
cso.run(a);
return a.getOutputDoc();
} catch (Throwable e) {
if (e instanceof com.dexels.navajo.mapping.BreakEvent) {
// Outdoc might have been changed by running script
outDoc = a.getOutputDoc();
// Create dummy header to set breakwasset attribute.
Header h = NavajoFactory.getInstance().createHeader(outDoc, "", "", "", -1);
outDoc.addHeader(h);
outDoc.getHeader().setHeaderAttribute("breakwasset", "true");
return outDoc;
} else if (e instanceof com.dexels.navajo.server.ConditionErrorException) {
return ((com.dexels.navajo.server.ConditionErrorException) e).getNavajo();
} else if (e instanceof UserException) {
throw (UserException) e;
}
throw new SystemException(-1, e.getMessage(), e);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class BinaryStoreAdapter method store.
@Override
public void store() throws MappableException, UserException {
if (value != null) {
BinaryStore os = BinaryStoreFactory.getInstance().getBinaryStore(resource, tenant);
if (os == null) {
logger.warn("Can not find swift resource: {} for tenant: {}", resource, tenant);
throw new UserException(-1, "Can not find binary store resource");
}
os.store(this.value);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class TwitterAdapter method getSignPost.
public Binary getSignPost() throws UserException {
if (mySignPost != null) {
Binary b = new Binary();
try {
ObjectOutputStream oos = new ObjectOutputStream(b.getOutputStream());
oos.writeObject(mySignPost);
oos.close();
} catch (Exception e) {
throw new UserException(-1, e.getMessage(), e);
}
return b;
} else {
throw new UserException(-1, "Signpost not set.");
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method createConnection.
protected final void createConnection() throws SQLException, UserException {
if (this.debug) {
Access.writeToConsole(myAccess, this.getClass() + ": in createConnection()\n");
}
if (transactionContext != -1) {
con = JdbcResourceComponent.getInstance().getJdbc(transactionContext);
if (con == null) {
throw new UserException(-1, "Invalid transaction context set: " + transactionContext);
}
// Make sure to set connection id.
this.connectionId = transactionContext;
}
if (con == null) {
if (this.debug) {
Access.writeToConsole(myAccess, "in createConnection() for datasource " + datasource);
}
DataSource jdbc = JdbcResourceComponent.getJdbc(datasource);
con = jdbc.getConnection();
setDbIdentifier(con);
if (this.username != null) {
String query = "ALTER SESSION SET CURRENT_SCHEMA = " + username;
if (this.dbIdentifier.equals(SQLMapConstants.POSTGRESDB)) {
query = "SET SEARCH_PATH TO " + username;
}
PreparedStatement ps = con.prepareStatement(query);
ps.executeUpdate();
ps.close();
logger.info("Username set to: {}", this.username);
}
if (con == null) {
AuditLog.log("SQLMap", "Could (still) not connect to database: " + datasource + ", check your connection", Level.SEVERE);
throw new UserException(-1, "Could not connect to database: " + datasource + " ()" + ", check your connection");
} else {
if (this.debug) {
Access.writeToConsole(myAccess, this.getClass() + ": returned a good connection from the broker manager\n");
}
}
this.transactionContext = con.hashCode();
logger.info(":::Creating transactioncontext: {}", transactionContext);
this.ownContext = true;
JdbcResourceComponent.getInstance().registerTransaction(con.hashCode(), con);
this.connectionId = con.hashCode();
if (this.debug) {
Access.writeToConsole(myAccess, this.getClass() + ": put connection no. " + this.connectionId + " into the connection map\n");
}
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class JDBCMap method getDBResultSet.
/*
* (non-Javadoc)
*
* @see com.dexels.navajo.adapter.JDBCMappable#getDBResultSet(boolean)
*/
@Override
public final ResultSet getDBResultSet(boolean updateOnly) throws SQLException, UserException {
createConnection();
if (con == null) {
AuditLog.log("SQLMap", "Could not connect to database: " + datasource + ", check your connection", Level.SEVERE, (myAccess != null ? myAccess.accessID : "unknown access"));
throw new UserException(-1, "in SQLMap. Could not open database connection']");
}
if (debug) {
Access.writeToConsole(myAccess, "SQLMAP, GOT CONNECTION, STARTING QUERY\n");
}
if (updateOnly && ((this.query == null) || (this.query.length() == 0)) && (this.update != null) && (this.update.indexOf(SQLBatchUpdateHelper.DELIMITER) >= 0)) {
if (this.debug) {
Access.writeToConsole(myAccess, this.getClass() + ": detected batch mode, trying a batch update\n");
}
SQLBatchUpdateHelper helper = new SQLBatchUpdateHelper(this.update, this.con, this.parameters, this.myAccess, this.dbIdentifier, this, this.isLegacyMode, this.debug, updateOnly);
this.updateCount = helper.getUpdateCount();
return (helper.getResultSet());
}
if (debug) {
Access.writeToConsole(myAccess, "BEFORE PREPARESTATEMENT()\n");
}
// Check for open statement.
if (this.statement != null) {
try {
this.statement.close();
} catch (Exception e) {
}
this.statement = null;
}
if (query != null) {
this.statement = con.prepareStatement(query);
} else {
this.statement = con.prepareStatement(update);
}
if (debug) {
Access.writeToConsole(myAccess, "AFTER PREPARESTATEMENT(), SETTING MAXROWS...\n");
}
if (debug) {
Access.writeToConsole(myAccess, "SET MAXROWS DONE..SETTING STATEMENT PARAMETERS\n");
}
setStatementParameters(statement);
ResultSet rs = null;
if (updateOnly) {
this.statement.executeUpdate();
} else {
if (debug) {
Access.writeToConsole(myAccess, "CALLING EXECUTEQUERY()\n");
}
rs = this.statement.executeQuery();
if (debug) {
Access.writeToConsole(myAccess, "GOT RESULTSET!!!!!\n");
}
}
this.updateCount = this.statement.getUpdateCount();
// dump any SQL warnings
if (debug) {
SQLWarning warning = this.statement.getWarnings();
while (warning != null) {
Access.writeToConsole(myAccess, "SQL warning: " + warning.getMessage() + "\n");
warning = warning.getNextWarning();
}
}
return rs;
}
Aggregations