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:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
@Override public TbMsg executeUpdate(TbMsg msg) throws ScriptException { JsonNode result = executeScript(msg); if (!result.isObject()) { log.warn("Wrong result type: {}", result.getNodeType()); throw new ScriptException("Wrong result type: " + result.getNodeType()); }/* ww w . ja v a 2 s . c o m*/ return unbindMsg(result, msg); }
From source file:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
@Override public TbMsg executeGenerate(TbMsg prevMsg) throws ScriptException { JsonNode result = executeScript(prevMsg); if (!result.isObject()) { log.warn("Wrong result type: {}", result.getNodeType()); throw new ScriptException("Wrong result type: " + result.getNodeType()); }/* ww w . ja va 2 s . c o m*/ return unbindMsg(result, prevMsg); }
From source file:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
@Override public String executeToString(TbMsg msg) throws ScriptException { JsonNode result = executeScript(msg); if (!result.isTextual()) { log.warn("Wrong result type: {}", result.getNodeType()); throw new ScriptException("Wrong result type: " + result.getNodeType()); }//from w w w. jav a2s. c o m return result.asText(); }
From source file:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
@Override public boolean executeFilter(TbMsg msg) throws ScriptException { JsonNode result = executeScript(msg); if (!result.isBoolean()) { log.warn("Wrong result type: {}", result.getNodeType()); throw new ScriptException("Wrong result type: " + result.getNodeType()); }//from w w w.j a v a 2 s .co m return result.asBoolean(); }
From source file:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
@Override public Set<String> executeSwitch(TbMsg msg) throws ScriptException { JsonNode result = executeScript(msg); if (result.isTextual()) { return Collections.singleton(result.asText()); } else if (result.isArray()) { Set<String> nextStates = Sets.newHashSet(); for (JsonNode val : result) { if (!val.isTextual()) { log.warn("Wrong result type: {}", val.getNodeType()); throw new ScriptException("Wrong result type: " + val.getNodeType()); } else { nextStates.add(val.asText()); }/*from w ww.j a va2s. c o m*/ } return nextStates; } else { log.warn("Wrong result type: {}", result.getNodeType()); throw new ScriptException("Wrong result type: " + result.getNodeType()); } }
From source file:org.thingsboard.server.service.script.RuleNodeJsScriptEngine.java
private JsonNode executeScript(TbMsg msg) throws ScriptException { try {/*from w w w. ja v a 2s . c o m*/ String[] inArgs = prepareArgs(msg); String eval = sandboxService.invokeFunction(this.scriptId, inArgs[0], inArgs[1], inArgs[2]).get() .toString(); return mapper.readTree(eval); } catch (ExecutionException e) { if (e.getCause() instanceof ScriptException) { throw (ScriptException) e.getCause(); } else if (e.getCause() instanceof RuntimeException) { throw new ScriptException(e.getCause().getMessage()); } else { throw new ScriptException(e); } } catch (Exception e) { throw new ScriptException(e); } }
From source file:org.wso2.carbon.apimgt.hostobjects.MutualAuthHostObject.java
/** * Validate the provided user name against user store * @param cx context//from ww w. ja va2 s. c o m * @param thisObj this object * @param args arguments * @return boolean * @throws Exception */ public static boolean jsFunction_validateUserNameHeader(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { int argLength = args.length; if (argLength != 1 || !(args[0] instanceof String)) { throw new ScriptException("Invalid argument. User Name is not set properly"); } boolean isValidUser = false; String userNameHeader = (String) args[0]; try { String tenantDomain = MultitenantUtils.getTenantDomain(userNameHeader); String userName = MultitenantUtils.getTenantAwareUsername(userNameHeader); TenantManager tenantManager = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager(); int tenantId = tenantManager.getTenantId(tenantDomain); UserStoreManager userstore = ServiceReferenceHolder.getInstance().getRealmService() .getTenantUserRealm(tenantId).getUserStoreManager(); if (userstore.isExistingUser(userName)) { isValidUser = true; } } catch (Exception e) { log.error("Error validating the user " + e.getMessage(), e); throw new ScriptException("Error validating the user " + userNameHeader); } return isValidUser; }
From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java
/** * @param cx//from w w w . j a v a 2s . c o m * @param args - args[0]-issuerId, this issuer need to be registered in Identity server. * @param ctorObj * @param inNewExpr * @return * @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."); } SAMLSSORelyingPartyObject relyingPartyObject = ssoRelyingPartyMap.get((String) args[0]); if (relyingPartyObject == null) { relyingPartyObject = new SAMLSSORelyingPartyObject(); relyingPartyObject.setSSOProperty(SSOConstants.ISSUER_ID, (String) args[0]); ssoRelyingPartyMap.put((String) args[0], relyingPartyObject); } return relyingPartyObject; }
From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java
/** * @param cx// w w w . j a v a 2 s. c o m * @param thisObj * @param args -args[0]- SAML response xml * @param funObj * @return * @throws Exception */ public static boolean jsFunction_validateSignature(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { int argLength = args.length; if (argLength != 1 || !(args[0] instanceof String)) { throw new ScriptException("Invalid argument. SAML response is missing."); } String decodedString = Util.decode((String) args[0]); XMLObject samlObject = Util.unmarshall(decodedString); String tenantDomain = Util.getDomainName(samlObject); int tenantId = Util.getRealmService().getTenantManager().getTenantId(tenantDomain); if (samlObject instanceof Response) { Response samlResponse = (Response) samlObject; SAMLSSORelyingPartyObject relyingPartyObject = (SAMLSSORelyingPartyObject) thisObj; return Util.validateSignature(samlResponse, relyingPartyObject.getSSOProperty(SSOConstants.KEY_STORE_NAME), relyingPartyObject.getSSOProperty(SSOConstants.KEY_STORE_PASSWORD), relyingPartyObject.getSSOProperty(SSOConstants.IDP_ALIAS), tenantId, tenantDomain); } if (log.isWarnEnabled()) { log.warn("SAML response in signature validation is not a SAML Response."); } return false; }
From source file:org.wso2.carbon.hostobjects.sso.SAMLSSORelyingPartyObject.java
/** * @param cx/*from ww w.j a v a2 s .com*/ * @param thisObj * @param args -args[0]-Logout request xml as a string. * @param funObj * @return * @throws Exception */ public static boolean jsFunction_isLogoutRequest(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws Exception { int argLength = args.length; if (argLength != 1 || !(args[0] instanceof String)) { throw new ScriptException("Invalid argument. Logout request xml is missing."); } String decodedString = Util.decode((String) args[0]); XMLObject samlObject = Util.unmarshall(decodedString); return samlObject instanceof LogoutRequest; }