use of org.xdi.exception.PythonException in project oxCore by GluuFederation.
the class CustomScriptManager method createExternalType.
private BaseExternalType createExternalType(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) {
String customScriptInum = customScript.getInum();
BaseExternalType externalType;
try {
externalType = createExternalTypeFromStringWithPythonException(customScript, configurationAttributes);
} catch (PythonException ex) {
log.error("Failed to prepare external type '{0}'", ex, customScriptInum);
return null;
}
if (externalType == null) {
log.debug("Using default external type class");
externalType = customScript.getScriptType().getDefaultImplementation();
}
return externalType;
}
use of org.xdi.exception.PythonException in project oxTrust by GluuFederation.
the class RegistrationInterceptionService method createRegistrationScriptFromStringWithPythonException.
private RegistrationScript createRegistrationScriptFromStringWithPythonException(RegistrationInterceptorScript script) {
String pythonScriptText = script.getCustomScript();
if (pythonScriptText == null) {
return null;
}
RegistrationScript pythonScript = null;
InputStream bis = null;
try {
bis = new ByteArrayInputStream(pythonScriptText.getBytes(Util.UTF8_STRING_ENCODING));
pythonScript = pythonService.loadPythonScript(bis, "RegistrationScriptClass", RegistrationScript.class, new PyObject[] { new PyLong(System.currentTimeMillis()) });
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
} catch (PythonException e) {
log.error(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(bis);
}
return pythonScript;
}
use of org.xdi.exception.PythonException in project oxCore by GluuFederation.
the class CustomScriptManager method createExternalTypeFromStringWithPythonException.
public BaseExternalType createExternalTypeFromStringWithPythonException(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) throws PythonException {
String script = customScript.getScript();
if (script == null) {
return null;
}
CustomScriptType customScriptType = customScript.getScriptType();
BaseExternalType externalType = null;
InputStream bis = null;
try {
bis = new ByteArrayInputStream(script.getBytes("UTF-8"));
externalType = pythonService.loadPythonScript(bis, customScriptType.getPythonClass(), customScriptType.getCustomScriptType(), new PyObject[] { new PyLong(System.currentTimeMillis()) });
} catch (UnsupportedEncodingException e) {
log.error(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(bis);
}
if (externalType == null) {
return null;
}
boolean initialized = false;
try {
initialized = externalType.init(configurationAttributes);
} catch (Exception ex) {
log.error("Failed to initialize custom script: '{0}'", ex, customScript.getName());
}
if (initialized) {
return externalType;
}
return null;
}
use of org.xdi.exception.PythonException in project oxCore by GluuFederation.
the class PythonService method loadPythonScript.
@SuppressWarnings("unchecked")
private <T> T loadPythonScript(String scriptPythonType, Class<T> scriptJavaType, PyObject[] constructorArgs, PythonInterpreter interpreter) throws PythonException {
PyObject scriptPythonTypeObject = interpreter.get(scriptPythonType);
if (scriptPythonTypeObject == null) {
return null;
}
PyObject scriptPythonTypeClass;
try {
scriptPythonTypeClass = scriptPythonTypeObject.__call__(constructorArgs);
} catch (Exception ex) {
log.error("Failed to initialize python class", ex.getMessage());
throw new PythonException(String.format("Failed to initialize python class '%s'", scriptPythonType), ex);
}
Object scriptJavaClass = scriptPythonTypeClass.__tojava__(scriptJavaType);
if (!ReflectHelper.assignableFrom(scriptJavaClass.getClass(), scriptJavaType)) {
return null;
}
return (T) scriptJavaClass;
}
Aggregations