List of usage examples for java.lang Throwable Throwable
public Throwable()
From source file:com.opentable.logging.RedisAppenderTest.java
@Test public void testLog() throws Exception { context.getLogger("test").info("Herro!"); context.getLogger("womp").warn("flop", new Throwable()); final CommonLogFields log1, log2; try (Jedis jedis = new Jedis("localhost", redis.getPort())) { log1 = read(jedis.lpop("logs")); log2 = read(jedis.lpop("logs")); assertNull(jedis.lpop("logs")); }// w ww .jav a 2 s.co m assertEquals("Herro!", log1.getMessage()); assertEquals("test", log1.getLogClass()); assertEquals("INFO", log1.getSeverity()); assertEquals("flop", log2.getMessage()); assertEquals("womp", log2.getLogClass()); assertEquals("WARN", log2.getSeverity()); }
From source file:org.blockfreie.element.hydrogen.murikate.ApplicationUtil.java
/** * Returns application wide property./*from ww w. jav a2 s. c o m*/ * * @param key * the name of property to retrieve * @return the value of property */ public static String getProperty(String key) { String result = null; String classname = new Throwable().getStackTrace()[1].getClassName(); String saltedkey = String.format("%s.%s", classname, key); result = PROPERTY.getProperty(saltedkey); result = (result == null) ? PROPERTY.getProperty(key) : result; LOGGER.log(Level.INFO, String.format("%s:%s", saltedkey, result)); return result; }
From source file:com.esd.vs.controller.SMSController.java
/** * ?// w w w . ja va 2 s . com * * @return */ @RequestMapping(value = "/send", method = RequestMethod.GET) @ResponseBody public String send(HttpServletRequest request, HttpSession session) { Sms sms = new Sms(); String resultCode = "-1"; String ip = getRemoteAddress(request); //String appId = request.getParameter("appId"); if (ipFilter(appId, ip) == false) { logger.debug("??"); return resultCode; } logger.debug("??"); String phone = request.getParameter("phone"); String code = request.getParameter("code"); sms.setIp(ip); sms.setPhone(phone); sms.setCode(code); sms.setAccountSid(accountSid); sms.setAccountToken(accountToken); sms.setAppid(appId); sms.setCreateMethod(new Throwable().getStackTrace()[0].toString()); smsService.save(sms); // logger.debug("phone:{} code:{}", phone, code); // // HashMap<String, Object> result = null; // CCPRestSDK restAPI = new CCPRestSDK(); // restAPI.init("sandboxapp.cloopen.com", "8883");// // ?????????https:// // restAPI.setAccount(accountSid, accountToken);// ??????? // restAPI.setAppId(appId);// ?ID // result = restAPI.sendTemplateSMS(phone, "1", new String[] { code }); // // String resultCode = String.valueOf(result.get("statusCode")); // sms.setUpdateMethod(new Throwable().getStackTrace()[0].toString()); // sms.setStatusCode(resultCode); // sms.setResult(result.get("data").toString()); // if ("000000".equals(resultCode) == false) { // logger.error("?=" + result.get("statusCode") + " ?= " + // result.get("statusMsg")); // } smsService.update(sms); return resultCode; }
From source file:com.jivesoftware.os.amza.api.ring.RingHost.java
public static RingHost fromBytes(byte[] bytes) throws Exception { if (bytes[0] == 0) { int port = UIO.bytesInt(bytes, 1); String host = new String(bytes, 1 + 4, bytes.length - (1 + 4), StandardCharsets.UTF_8); return new RingHost("", "", host, port); } else if (bytes[0] == 1) { int i = 1; int port = UIO.bytesInt(bytes, i); i += 4;// w ww.j av a 2 s .co m int hostLength = UIO.bytesInt(bytes, i); i += 4; String host = new String(bytes, i, hostLength, StandardCharsets.UTF_8); i += hostLength; int rackLength = UIO.bytesInt(bytes, i); i += 4; String rack = new String(bytes, i, rackLength, StandardCharsets.UTF_8); i += rackLength; int datacenterLength = UIO.bytesInt(bytes, i); i += 4; String datacenter = new String(bytes, i, datacenterLength, StandardCharsets.UTF_8); return new RingHost(datacenter, rack, host, port); } LOG.error("Bad RingHost bytes, bytes={}", new Object[] { Arrays.toString(bytes) }, new Throwable()); return null; // Sorry caller }
From source file:com.orange.cepheus.broker.Subscriptions.java
/** * Add a subscription./* w ww. ja v a2 s . co m*/ * @param subscribeContext * @return the subscriptionId * @throws SubscriptionException, SubscriptionPersistenceException */ public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { //if duration is not present, then lb set duration to P1M Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } // Compile all entity patterns now to check for conformance (result is cached for later use) try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } // Generate a subscription id String subscriptionId = UUID.randomUUID().toString(); //create subscription and set the expiration date and subscriptionId Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); //save subscription subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }
From source file:com.amazonaws.services.kinesis.multilang.MessageWriterTest.java
@Test public void writeCheckpointMessageWithErrorTest() throws IOException, InterruptedException, ExecutionException { Future<Boolean> future = this.messageWriter.writeCheckpointMessageWithError("1234", new Throwable()); future.get();//ww w.j ava 2s . c o m Mockito.verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt()); Mockito.verify(this.stream, Mockito.atLeastOnce()).flush(); }
From source file:de.micromata.genome.gdbfs.ZipWriteFileSystem.java
/** * Unsupported op./*from w w w . ja v a 2 s. c o m*/ */ protected void unsupportedOp() { StackTraceElement[] els = new Throwable().getStackTrace(); throw new FsException("Unsupported operation: " + els[1].getMethodName()); }
From source file:jetbrains.exodus.query.TreeKeepingEntityIterable.java
public TreeKeepingEntityIterable(@Nullable final Iterable<Entity> entityIterable, @NotNull String entityType, @NotNull final NodeBase queryTree, @Nullable String leftChildPresentation, @Nullable String rightChildPresentation, @NotNull QueryEngine queryEngine) { super(queryEngine); final Explainer explainer = queryEngine.getPersistentStore().getExplainer(); isExplainOn = explainer.isExplainOn(); origin = explainer.genOrigin();// w w w.j av a 2 s.co m if (isExplainOn) { strippedStacktrace = Explainer.stripStackTrace(new Throwable()); } // get entityType from iterable if (entityIterable instanceof StaticTypedEntityIterable) { final String entityIterableType = ((StaticTypedEntityIterable) entityIterable).getEntityType(); if (!(entityType.equals(entityIterableType)) && Utils.isTypeOf(entityIterableType, entityType, queryEngine.getModelMetaData())) { entityType = entityIterableType; } } // if (isExplainOn) { if (queryTree instanceof BinaryOperator && (leftChildPresentation != null || rightChildPresentation != null)) { BinaryOperator binaryOperator = (BinaryOperator) queryTree; if (leftChildPresentation == null) { leftChildPresentation = binaryOperator.getLeft().toString(); } if (rightChildPresentation == null) { rightChildPresentation = binaryOperator.getRight().toString(); } annotatedTree = "at " + strippedStacktrace + '\n' + binaryOperator.getClass().getSimpleName() + ('\n' + leftChildPresentation + '\n' + rightChildPresentation).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT); } else { annotatedTree = "at " + strippedStacktrace + '\n' + queryTree; } } if (entityIterable instanceof TreeKeepingEntityIterable) { final TreeKeepingEntityIterable instanceTreeIt = (TreeKeepingEntityIterable) entityIterable; final NodeBase instanceTree = instanceTreeIt.sourceTree; if (queryTree instanceof Sort && ((UnaryNode) queryTree).getChild().equals(NodeFactory.all())) { sourceTree = queryTree.getClone(); sourceTree.replaceChild(((UnaryNode) sourceTree).getChild(), instanceTree.getClone()); if (isExplainOn) { annotatedTree = "at " + strippedStacktrace + '\n' + sourceTree.getClass().getSimpleName() + ("\n" + (instanceTreeIt.annotatedTree != null ? instanceTreeIt.annotatedTree : instanceTree)).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT); } } else { sourceTree = instanceTree instanceof GetAll ? queryTree : new And(instanceTree.getClone(), queryTree); if (isExplainOn && !(instanceTree instanceof GetAll)) { annotatedTree = "at " + strippedStacktrace + "\nAnd" + ("\n" + (instanceTreeIt.annotatedTree != null ? instanceTreeIt.annotatedTree : instanceTree) + '\n' + annotatedTree).replace("\n", '\n' + NodeBase.TREE_LEVEL_INDENT); } } instance = instanceTreeIt.instance; } else { instance = entityIterable; sourceTree = queryTree; } this.entityType = entityType; optimizedTree = null; }
From source file:com.redhat.rhn.testing.TestUtils.java
/** * method to find a file relative to the calling class. primarily * useful when writing tests that need access to external data. * this lets you put the data relative to the test class file. * * @param path the path, relative to caller's location * @return URL a URL referencing the file * @throws ClassNotFoundException if the calling class can not be found * (i.e., should not happen)/*from w w w .java 2 s.co m*/ * @throws IOException if the specified file in an archive (eg. jar) and * it cannot be copied to a temporary location */ public static URL findTestData(String path) throws ClassNotFoundException, IOException { Throwable t = new Throwable(); StackTraceElement[] ste = t.getStackTrace(); String className = ste[1].getClassName(); Class clazz = Class.forName(className); URL ret = clazz.getResource(path); if (ret.toString().contains("!")) { // file is from an archive String tempPath = "/tmp/" + filePrefix + ret.hashCode(); InputStream input = clazz.getResourceAsStream(path); OutputStream output = new FileOutputStream(tempPath); IOUtils.copy(input, output); return new File(tempPath).toURI().toURL(); } return ret; }
From source file:neembuu.vfs.progresscontrol.GeneralThrottleTestMeasurement.java
@Override public void write(byte[] b) throws IOException { if (!firstObv) { new Throwable().printStackTrace(); firstObv = true;//w ww.j a v a 2 s . c o m } if (buffSize != b.length) { buffSize = b.length; //System.out.println("buffchanged to "+buffSize); } downloadSpeedObv.progressed(b.length); //long i = System.currentTimeMillis(); controlThrottle.trace .addPoint(new TracePoint2D(System.currentTimeMillis(), downloadSpeedObv.getSpeed_KiBps())); controlThrottle.smallDownloadSpeedLabel.setText(downloadSpeedObv.getSpeed_KiBps() + "KiBps"); controlThrottle.averageSpeed.setText(downloadSpeedObv.getAverage_KiBps() + " KBps"); /*long f = System.currentTimeMillis(); ift*=ind; ift+=(f-i); ind++; ift/=ind; System.out.println("tog="+ift);*/ calculateSleepInterval(); try { if (throttleEnabled) { if (sleepPerByteDownloaded > 0) { double millis = sleepPerByteDownloaded * b.length * 1000; int nanos = ((int) (millis * 1000000)) % 1000000; //if(millis>2){ Thread.sleep((int) (millis), nanos); //} } } } catch (Exception a) { } }