List of usage examples for java.lang RuntimeException getMessage
public String getMessage()
From source file:com.espertech.esper.pattern.PatternExpressionUtil.java
private static Object evaluate(String objectName, ExprNode expression, EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext) throws EPException { try {//from w w w.j ava2 s .c o m return expression.getExprEvaluator().evaluate(eventsPerStream, true, exprEvaluatorContext); } catch (RuntimeException ex) { String message = objectName + " failed to evaluate expression"; if (ex.getMessage() != null) { message += ": " + ex.getMessage(); } log.error(message, ex); throw new EPException(message); } }
From source file:com.liferay.mobile.android.util.PortraitUtil.java
protected static void appendToken(StringBuilder sb, String uuid) { if (Validator.isNull(uuid)) { return;/* ww w . j a va 2 s. com*/ } try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(uuid.getBytes()); byte[] bytes = digest.digest(); String token = null; try { token = Base64.encodeToString(bytes, Base64.NO_WRAP); } catch (RuntimeException re) { if ("Stub!".equals(re.getMessage())) { token = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes); } } if (token != null) { sb.append("&img_id_token="); sb.append(URLEncoder.encode(token, "UTF8")); } } catch (Exception e) { Log.e(_CLASS_NAME, "Couldn't generate portrait image token", e); } }
From source file:com.espertech.esper.pattern.PatternExpressionUtil.java
/** * Ctor./*ww w. ja va2 s. c o m*/ * @param objectName is the pattern object name * @param beginState the pattern begin state * @param parameters object parameters * @param convertor for converting to a event-per-stream view for use to evaluate expressions * @param exprEvaluatorContext expression evaluation context * @return expression results * @throws EPException if the evaluate failed */ public static List<Object> evaluate(String objectName, MatchedEventMap beginState, List<ExprNode> parameters, MatchedEventConvertor convertor, ExprEvaluatorContext exprEvaluatorContext) throws EPException { List<Object> results = new ArrayList<Object>(); int count = 0; EventBean[] eventsPerStream = convertor.convert(beginState); for (ExprNode expr : parameters) { try { Object result = evaluate(objectName, expr, eventsPerStream, exprEvaluatorContext); results.add(result); count++; } catch (RuntimeException ex) { String message = objectName + " invalid parameter in expression " + count; if (ex.getMessage() != null) { message += ": " + ex.getMessage(); } log.error(message, ex); throw new EPException(message); } } return results; }
From source file:com.cloudera.flume.shell.CommandBuilder.java
/** * This takes a single string and parses it into a Command. *//*from w ww . jav a2 s. c o m*/ public static Command parseLine(String s) throws RecognitionException { try { CommonTree cmd = (CommonTree) getShellCmdParser(s).line().getTree(); CommonTree ast = (CommonTree) cmd.getChild(0); String command = toString(ast); cmd.deleteChild(0); ArrayList<String> lst = new ArrayList<String>(); for (int i = 0; i < cmd.getChildCount(); i++) { String tok = toString((CommonTree) cmd.getChild(i)); lst.add(tok); } return new Command(command, lst.toArray(new String[0])); } catch (RecognitionException e) { LOG.debug("Failed to parse line, '" + s + "' because of " + e.getMessage(), e); throw e; } catch (RuntimeException rex) { // right now lexer errors are RTE's LOG.debug("Failed to lex '" + s + "' because of " + rex.getMessage(), rex); throw new CommandLineException(rex); } }
From source file:io.apiman.gateway.platforms.vertx3.api.auth.KeycloakOAuthFactory.java
private static AuthHandler directGrant(Vertx vertx, VertxEngineConfig apimanConfig, JsonObject authConfig, OAuth2FlowType flowType, String role) { return new AuthHandler() { @Override//from w ww.j a v a 2 s . c om public void handle(RoutingContext context) { try { String[] auth = Basic.decodeWithScheme(context.request().getHeader("Authorization")); doBasic2Oauth(context, role, auth[0], auth[1]); } catch (RuntimeException e) { handle400(context, e.getMessage()); } } private void doBasic2Oauth(RoutingContext context, String role, String username, String password) { JsonObject params = new JsonObject().put("username", username).put("password", password); OAuth2Auth oauth2 = KeycloakAuth.create(vertx, flowType, authConfig); oauth2.getToken(params, tokenResult -> { if (tokenResult.succeeded()) { log.debug("OAuth2 Keycloak exchange succeeded."); AccessToken token = tokenResult.result(); token.isAuthorised(role, res -> { if (res.result()) { context.next(); } else { String message = MessageFormat.format("User {0} does not have required role: {1}.", username, role); log.error(message); handle403(context, "insufficient_scope", message); } }); } else { String message = tokenResult.cause().getMessage(); log.error("Access Token Error: {0}.", message); handle401(context, "invalid_token", message); } }); } private void handle400(RoutingContext context, String message) { if (message != null) context.response().setStatusMessage(message); context.fail(400); } private void handle401(RoutingContext context, String error, String message) { String value = MessageFormat.format("Basic realm=\"{0}\" error=\"{1}\" error_message=\"{2}\"", "apiman-gw", error, message); context.response().putHeader("WWW-Authenticate", value); context.fail(401); } private void handle403(RoutingContext context, String error, String message) { String value = MessageFormat.format("Basic realm=\"{0}\" error=\"{1}\" error_message=\"{2}\"", "apiman-gw", error, message); context.response().putHeader("WWW-Authenticate", value); context.fail(403); } @Override public AuthHandler addAuthority(String authority) { return this; } @Override public AuthHandler addAuthorities(Set<String> authorities) { return this; } }; }
From source file:com.espertech.esper.epl.view.OutputConditionPolledCrontab.java
private static Object[] evaluate(ExprEvaluator[] parameters, ExprEvaluatorContext exprEvaluatorContext) { Object[] results = new Object[parameters.length]; int count = 0; for (ExprEvaluator expr : parameters) { try {// w w w .j av a 2 s . c o m results[count] = expr.evaluate(null, true, exprEvaluatorContext); count++; } catch (RuntimeException ex) { String message = "Failed expression evaluation in crontab timer-at for parameter " + count + ": " + ex.getMessage(); log.error(message, ex); throw new IllegalArgumentException(message); } } return results; }
From source file:com.smartitengineering.cms.client.impl.RootResourceImpl.java
public static RootResource getRoot(URI uri) { try {/*from w ww . ja va 2s . c om*/ RootResource resource = new RootResourceImpl(uri); return resource; } catch (RuntimeException ex) { LOGGER.error(ex.getMessage(), ex); throw ex; } }
From source file:net.servicefixture.PluginManager.java
@SuppressWarnings("unchecked") private static Class newClass(String classname) { try {/*w w w . ja v a 2 s . c om*/ return ReflectionUtils.newClass(classname); } catch (RuntimeException e) { throw new ServiceFixtureException("Unable to load plugins due to:" + e.getMessage()); } }
From source file:br.upf.contatos.udp.ClienteUDP.java
public static boolean comando(String[] args) throws SocketException, IOException { while (true) { Scanner scanner = new Scanner(System.in); String line = scanner.nextLine(); String[] comandos = line.split(" "); if (comandos[0].equals("help")) { System.out.println("Listar = Lista todos os contatos" + "incluir = Inclui um contato, incluir nome NOMEtudoJUNTO email EMAIL end ENDERECO comp COPM cep CEP cid CID est EST \n" + "editar = edita um contato, escrever editar numeroDoID label VALORaSERalterado\n" + "deletar = deletar id numero \n" + "parar = finaliza conexao \n" + "cidade = lista por cidade escrever cidade nomeCidade\n" + "Comandos seguidos de outras informacoes sempre separar por espaco, nomes tudo junto\n"); return true; } else if (comandos[0].equals("parar")) { return false; } else {/*from w w w . ja v a 2s .c o m*/ UDPConexao udpConnection = new UDPConexao(HOST, PORTA); udpConnection.connect(); switch (comandos[0]) { case "listar": { for (ContatoBean cb : udpConnection.getAll()) { System.out.println(new JSONObject(cb)); } udpConnection.disconnect(); break; } // TERMINA LISTAR case "incluir": { ContatoBean cb = new ContatoBean(); if (comandos[1].equals("label=nome")) cb.setNome(comandos[2]); if (comandos[3].equals("label=email")) cb.setEmail(comandos[4]); if (comandos[5].equals("label=end")) cb.setEndereco(comandos[6]); if (comandos[7].equals("label=comp")) cb.setComplemento(comandos[8]); if (comandos[9].equals("label=cep")) cb.setCep(Integer.parseInt(comandos[10])); if (comandos[11].equals("label=cid")) cb.setCidade(comandos[12]); if (comandos[13].equals("label=est")) cb.setEstado(comandos[14]); try { cb = udpConnection.insert(cb); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //TERMINA INCLUIR case "editar": { int numIdEdi = Integer.parseInt(args[1]); ContatoBean contact = new ContatoBean(); contact = udpConnection.getById(numIdEdi); switch (args[2]) { case "id": contact.setId(Integer.parseInt(args[3])); break; case "nome": contact.setNome(args[3]); break; case "email": contact.setEmail(args[3]); break; case "end": contact.setEndereco(args[3]); break; case "comp": contact.setComplemento(args[3]); break; case "cep": contact.setCep(Integer.parseInt(args[3])); break; case "cid": contact.setCidade(args[3]); break; case "est": contact.setEstado(args[3]); break; }// FINALIZA CASE DE TROCA DE DADOS try { contact = udpConnection.update(contact); System.out.println(new JSONObject(contact)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); } // TERMINA EDITAR case "cidade": { ContatoBean cob = new ContatoBean(); cob.setCidade(args[1]); try { cob = udpConnection.getByCidade(cob); System.out.println(new JSONObject(cob)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //termina listar CIDADE case "deletar": { ContatoBean cb = new ContatoBean(); cb.setId(Integer.parseInt(args[1])); try { cb = udpConnection.delete(cb.getId()); System.out.println(new JSONObject(cb)); } catch (RuntimeException e) { System.out.println(e.getMessage()); } udpConnection.disconnect(); break; } //termina DELETAR }//TERMINA SWTICH } // TERMINA ELSE ANTES DO SWITCH } //TERMINA WILHER TRUE }
From source file:net.servicefixture.PluginManager.java
@SuppressWarnings("unchecked") private static Object newInstance(String classname, Class baseClazz) { try {//from w w w. ja v a2 s .com Class clazz = ReflectionUtils.newClass(classname); if (baseClazz.isAssignableFrom(clazz)) { return ReflectionUtils.newInstance(clazz); } } catch (RuntimeException e) { throw new ServiceFixtureException("Unable to load plugins due to:" + e.getMessage()); } throw new ServiceFixtureException( "Unable to load plugins, class " + classname + " doesn't implement " + baseClazz.getName()); }