List of usage examples for javax.script ScriptException ScriptException
public ScriptException(Exception e)
ScriptException
wrapping an Exception
thrown by an underlying interpreter. From source file:io.cloudslang.lang.runtime.bindings.ScriptEvaluator.java
public Serializable evalExpr(String expr, Map<String, ? extends Serializable> context) { ScriptContext scriptContext = new SimpleScriptContext(); for (Map.Entry<String, ? extends Serializable> entry : context.entrySet()) { scriptContext.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); }/* w w w. j a v a 2 s. c o m*/ if (scriptContext.getAttribute(TRUE) == null) scriptContext.setAttribute(TRUE, Boolean.TRUE, ScriptContext.ENGINE_SCOPE); if (scriptContext.getAttribute(FALSE) == null) scriptContext.setAttribute(FALSE, Boolean.FALSE, ScriptContext.ENGINE_SCOPE); try { return (Serializable) engine.eval(expr, scriptContext); } catch (ScriptException e) { ScriptException scriptException = new ScriptException(e); throw new RuntimeException("Error in running script expression or variable reference, for expression: '" + expr + "',\n\tScript exception is: " + scriptException.getMessage(), scriptException); } }
From source file:org.openscore.lang.runtime.bindings.ScriptEvaluator.java
public Serializable evalExpr(String expr, Map<String, ? extends Serializable> context) { ScriptContext scriptContext = new SimpleScriptContext(); for (Map.Entry<String, ? extends Serializable> entry : context.entrySet()) { scriptContext.setAttribute(entry.getKey(), entry.getValue(), ScriptContext.ENGINE_SCOPE); }// ww w. j a v a 2 s .co m if (scriptContext.getAttribute(TRUE) == null) scriptContext.setAttribute(TRUE, Boolean.TRUE, ScriptContext.ENGINE_SCOPE); if (scriptContext.getAttribute(FALSE) == null) scriptContext.setAttribute(FALSE, Boolean.FALSE, ScriptContext.ENGINE_SCOPE); try { return (Serializable) engine.eval(expr, scriptContext); } catch (ScriptException e) { ScriptException scriptException = new ScriptException(e); throw new RuntimeException("Error in running script expression or variable reference, for expression: '" + expr + "', Script exception is: \n" + scriptException.getMessage(), scriptException); } }
From source file:org.wso2.carbon.apimgt.hostobjects.oidc.OIDCRelyingPartyObject.java
/** * @param cx - Context/*from ww w. j av a 2 s . c o m*/ * @param args - args[0]-issuerId, this issuer need to be registered in Identity server. * @param ctorObj - function * @param inNewExpr - boolean * @return - host object * @throws Exception */ public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws Exception { int argLength = args.length; if (argLength != 1 || !(args[0] instanceof String)) { throw new ScriptException("Invalid arguments!, IssuerId is missing in parameters."); } OIDCRelyingPartyObject relyingPartyObject = oidcRelyingPartyObjectMap.get((String) args[0]); if (relyingPartyObject == null) { relyingPartyObject = new OIDCRelyingPartyObject(); relyingPartyObject.setOIDCProperty(OIDCConstants.ISSUER_ID, (String) args[0]); oidcRelyingPartyObjectMap.put((String) args[0], relyingPartyObject); } return relyingPartyObject; }
From source file:com.googlecode.starflow.core.script.spel.SpelScriptEngine.java
private static final String readFully(Reader reader) throws ScriptException { char[] arr = new char[8 * 1024]; StringBuilder buf = new StringBuilder(); int numChars; try {// w w w. j a v a 2 s . c o m while ((numChars = reader.read(arr, 0, arr.length)) > 0) { buf.append(arr, 0, numChars); } } catch (IOException exp) { throw new ScriptException(exp); } return buf.toString(); }
From source file:org.wso2.carbon.apimgt.hostobjects.oidc.OIDCRelyingPartyObject.java
/** * Building authentication request URL. This URL allows to redirect in to OIDC server and authenticate. * @param cx - Context/*from ww w. j a va 2 s . com*/ * @param thisObj - This Object * @param args - takes nonce and state parameters * @param funObj - Function * @return URL which redirects to OIDC server and allow to authenticate * @throws Exception */ public static String jsFunction_buildAuthRequestUrl(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { int argLength = args.length; if (argLength != 2 || !(args[0] instanceof String) || !(args[1] instanceof String)) { throw new ScriptException("Invalid argument. Nonce or State not set properly"); } String nonce = (String) args[0]; String state = (String) args[1]; OIDCRelyingPartyObject relyingPartyObject = (OIDCRelyingPartyObject) thisObj; try { log.debug(" Building auth request Url"); URIBuilder uriBuilder = new URIBuilder( relyingPartyObject.getOIDCProperty(OIDCConstants.AUTHORIZATION_ENDPOINT_URI)); uriBuilder.addParameter(OIDCConstants.RESPONSE_TYPE, relyingPartyObject.getOIDCProperty(OIDCConstants.RESPONSE_TYPE)); uriBuilder.addParameter(OIDCConstants.CLIENT_ID, relyingPartyObject.getOIDCProperty(OIDCConstants.CLIENT_ID)); uriBuilder.addParameter(OIDCConstants.SCOPE, relyingPartyObject.getOIDCProperty(OIDCConstants.SCOPE)); uriBuilder.addParameter(OIDCConstants.REDIRECT_URI, relyingPartyObject.getOIDCProperty(OIDCConstants.REDIRECT_URI)); uriBuilder.addParameter(OIDCConstants.NONCE, nonce); uriBuilder.addParameter(OIDCConstants.STATE, state); // Optional parameters: //for (Map.Entry<String, String> option : options.entrySet()) { // uriBuilder.addParameter(option.getKey(), option.getValue()); //} //uriBuilder.addParameter("requestURI", requestURI); return uriBuilder.build().toString(); } catch (URISyntaxException e) { log.error("Build Auth Request Failed", e); throw new Exception("Build Auth Request Failed", e); } }
From source file:com.qwazr.webapps.transaction.ControllerManager.java
private void handleFile(WebappTransaction transaction, File controllerFile) throws IOException, ScriptException, PrivilegedActionException, InterruptedException, ReflectiveOperationException, ServletException { String ext = FilenameUtils.getExtension(controllerFile.getName()); if (StringUtils.isEmpty(ext)) throw new ScriptException("Unsupported controller " + controllerFile.getName()); if ("js".equals(ext)) handleJavascript(transaction, controllerFile); else/*from w w w. j ava 2s . co m*/ throw new ScriptException("Unsupported controller extension: " + controllerFile.getName()); }
From source file:com.thinkbiganalytics.spark.repl.SparkScriptEngine.java
@Override protected void execute(@Nonnull final String script) throws ScriptException { log.debug("Executing script:\n{}", script); // Convert script to single line (for checking security violations) final StringBuilder safeScriptBuilder = new StringBuilder(script.length()); for (final String line : script.split("\n")) { if (!LINE_CONTINUATION.matcher(line).find()) { safeScriptBuilder.append(';'); }/*w w w. j a v a 2 s . c o m*/ safeScriptBuilder.append(line); } final String safeScript = COMMENT.matcher(safeScriptBuilder.toString()).replaceAll(""); // Check for security violations for (final Pattern pattern : getDenyPatterns()) { if (pattern.matcher(safeScript).find()) { log.error("Not executing script that matches deny pattern: {}", pattern); throw new ScriptException("Script not executed due to security policy."); } } // Execute script try { getInterpreter().interpret(safeScript); } catch (final AssertionError e) { log.warn("Caught assertion error when executing script. Retrying...", e); reset(); getInterpreter().interpret(safeScript); } }
From source file:com.thinkbiganalytics.spark.service.TransformService.java
/** * Executes the specified transformation and returns the name of the Hive table containing the results. * * @param request the transformation request * @return the Hive table containing the results * @throws IllegalStateException if this service is not running * @throws ScriptException if the script cannot be executed *//*w ww .j a v a 2 s . c om*/ @Nonnull public TransformResponse execute(@Nonnull final TransformRequest request) throws ScriptException { log.trace("entry params({})", request); // Generate destination final String table = newTableName(); // Build bindings list final List<NamedParam> bindings = new ArrayList<>(); bindings.add(new NamedParamClass("profiler", Profiler.class.getName(), profiler)); bindings.add(new NamedParamClass("sparkContextService", SparkContextService.class.getName(), sparkContextService)); bindings.add(new NamedParamClass("tableName", "String", table)); if (request.getDatasources() != null && !request.getDatasources().isEmpty()) { if (datasourceProviderFactory != null) { final DatasourceProvider datasourceProvider = datasourceProviderFactory .getDatasourceProvider(request.getDatasources()); bindings.add(new NamedParamClass("datasourceProvider", DatasourceProvider.class.getName() + "[org.apache.spark.sql.DataFrame]", datasourceProvider)); } else { final ScriptException e = new ScriptException( "Script cannot be executed because no data source provider factory is available."); log.error("Throwing {}", e); throw e; } } // Execute script final Object result = this.engine.eval(toScript(request), bindings); final TransformJob job; if (result instanceof Callable) { @SuppressWarnings("unchecked") final Callable<TransformResponse> callable = (Callable) result; job = new TransformJob(table, callable, engine.getSparkContext()); tracker.submitJob(job); } else { final IllegalStateException e = new IllegalStateException( "Unexpected script result type: " + (result != null ? result.getClass() : null)); log.error("Throwing {}", e); throw e; } // Build response TransformResponse response; try { response = job.get(500, TimeUnit.MILLISECONDS); tracker.removeJob(table); } catch (final ExecutionException cause) { final ScriptException e = new ScriptException(cause); log.error("Throwing {}", e); throw e; } catch (final InterruptedException | TimeoutException e) { log.trace("Timeout waiting for script result", e); response = new TransformResponse(); response.setProgress(0.0); response.setStatus(TransformResponse.Status.PENDING); response.setTable(table); } log.trace("exit with({})", response); return response; }
From source file:org.wso2.carbon.apimgt.hostobjects.oidc.OIDCRelyingPartyObject.java
/** * @param cx - Context/*from w w w .j a v a2 s . c o m*/ * @param thisObj - This object * @param args - argument list * @param funObj - function * @return - boolean * @throws Exception */ public static boolean jsFunction_validateOIDCSignature(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { log.debug("Validating OIDC signature"); boolean isSignatureValid; OIDCRelyingPartyObject relyingPartyObject = (OIDCRelyingPartyObject) thisObj; ServerConfiguration serverConfiguration = getServerConfiguration(relyingPartyObject); AuthClient authClient = getClientConfiguration(relyingPartyObject); int argLength = args.length; if (argLength != 3 || !(args[0] instanceof String)) { throw new ScriptException( "Invalid argument. Authorization Code, Nonce value or session ID is missing."); } String authorizationCode = (String) args[0]; String storedNonce = (String) args[1]; String jsonResponse = getTokenFromTokenEP(serverConfiguration, authClient, authorizationCode); AuthenticationToken oidcAuthenticationToken = getAuthenticationToken(jsonResponse); String userName = getUserName(oidcAuthenticationToken, serverConfiguration); if (userName == null || userName.equals("")) { log.error("Authentication Request is rejected. " + "User Name is Null"); return false; } isSignatureValid = validateSignature(serverConfiguration, authClient, oidcAuthenticationToken, storedNonce); // If come here and signatureValid then set session as a authenticated one SessionInfo sessionInfo = new SessionInfo((String) args[2]); //sessionInfo.setSessionIndex(sessionIndex); sessionInfo.setLoggedInUser(userName); // sessionInfo.setSamlToken(userInfoJson); relyingPartyObject.addSessionInfo(sessionInfo); /////////////////////// return isSignatureValid; }
From source file:com.seajas.search.contender.service.modifier.ModifierScriptProcessor.java
/** * Transforms the given Reader content to an XSL-transformed document. * * @param script//from w w w. jav a 2 s . co m * @param input * @param uri * @return String * @throws ScriptException */ private String transformXML(final ModifierScript script, final String input, final URI uri) throws ScriptException { try { Transformer transformer = transformerCache.getTransformer(script.getId(), "modifier", script.getModificationDate()); if (transformer == null) transformer = transformerCache.putContent(script.getId(), "modifier", script.getModificationDate(), script.getScriptContent()); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Node document = documentBuilder.parse(new InputSource(new StringReader(input))); StringWriter buffer = new StringWriter(); transformer.transform(new DOMSource(document), new StreamResult(buffer)); return buffer.toString(); } catch (TransformerConfigurationException e) { logger.error("Unable to generate a (cached) transformer from the given content", e); throw new ScriptException("Unable to generate a (cached) transformer from the given content"); } catch (Exception e) { logger.error("Unable to perform content transformation modifier for " + uri, e); throw new ScriptException("Unable to perform content transformation modifier for " + uri); } }