protected void handleDeclaredThrownException(Exception e, RouteContext routeContext) { if (e instanceof RuntimeException) { // pass-through the thrown exception throw (RuntimeException) e; } // undeclared exception, wrap & throw throw new PippoRuntimeException(e); }
public void setAbsoluteUriPattern(String absoluteUriPattern) { if (this.absoluteUriPattern != null) { // when group1.addRoute(route); group2.addRoute(route); throw new PippoRuntimeException("This route is already in a group"); } this.absoluteUriPattern = absoluteUriPattern; }
@Override public WebServer<WebServerSettings> addListener(Class<? extends EventListener> listener) { throw new PippoRuntimeException("This feature is not available for this server type"); }
private SpymemcachedFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
private InfinispanFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
private JedisFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
private EhcacheFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
private MongoDBFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
private XmemcachedFactory() { throw new PippoRuntimeException("You can't make a instance of factory."); }
@SuppressWarnings("unchecked") public static <T> Class<T> getClass(String className) { try { return (Class<T>) Class.forName(className); } catch (Exception e) { throw new PippoRuntimeException("Failed to get class '{}'", className); } }
@Override public <T extends Controller> T createController(Class<T> controllerClass) { try { return controllerClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new PippoRuntimeException(e, "Could not instantiate '{}'", controllerClass.getName()); } }
private Date getDateObject(Object value) { if (value instanceof Date) { return (Date) value; } else if (value instanceof Calendar) { return ((Calendar) value).getTime(); } else if (value instanceof Long) { return new Date((Long) value); } else { throw new PippoRuntimeException("Failed to get a date object from {}!", value); } }
@Override public void stop() { if (server != null) { try { server.stop(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); //don't lose interrupted state: https://www.ibm.com/developerworks/java/library/j-jtp05236/index.html throw new PippoRuntimeException(e, "Interrupted while waiting for Jetty Server to stop."); } catch (Exception e) { throw new PippoRuntimeException(e, "Cannot stop Jetty Server"); } } }
static void validateFilterUrlPattern(String urlPattern) { if (!urlPattern.startsWith("/") || !urlPattern.endsWith("/*")) { throw new PippoRuntimeException("Your '{}' must start with '{}' and end with '{}'. It's '{}'", FILTER_MAPPING_PARAM, "/", "/*", urlPattern); } }
private Date getDateObject(Object value) { if (value instanceof Date) { return (Date) value; } else if (value instanceof Calendar) { return ((Calendar) value).getTime(); } else if (value instanceof Long) { return new Date((Long) value); } else { throw new PippoRuntimeException("Failed to get a date object from {}!", value); } }
private Date getDateObject(Object value) { if (value instanceof Date) { return (Date) value; } else if (value instanceof Calendar) { return ((Calendar) value).getTime(); } else if (value instanceof Long) { return new Date((Long) value); } else { throw new PippoRuntimeException("Failed to get a date object from {}!", value); } }
private Date getDateObject(Object value) { if (value instanceof Date) { return (Date) value; } else if (value instanceof Calendar) { return ((Calendar) value).getTime(); } else if (value instanceof Long) { return new Date((Long) value); } else { throw new PippoRuntimeException("Failed to get a date object from {}!", value); } }
@Override protected InputStream getInputStream(String path) { Path resolvedPath = Paths.get(targetClasses).resolve(path); if (Files.notExists(resolvedPath)) { return null; } try { return Files.newInputStream(resolvedPath); } catch (IOException e) { throw new PippoRuntimeException(e); } }
private void createApplication(ServletConfig servletConfig) { String applicationClassName = servletConfig.getInitParameter(APPLICATION_CLASS_PARAM); if (applicationClassName == null) { log.error("Servlet init param '{}' is missing", APPLICATION_CLASS_PARAM); throw new PippoRuntimeException("Cannot found application class name"); } try { Class<?> applicationClass = Class.forName(applicationClassName); application = (Application) applicationClass.newInstance(); } catch (Exception e) { log.error("Cannot create application with className '{}'", applicationClassName, e); throw new PippoRuntimeException(e); } }
@Override public String encode(SessionData sessionData) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream)) { objectOutputStream.writeObject(sessionData); byte[] bytes = outputStream.toByteArray(); return Base64.getEncoder().encodeToString(bytes); } catch (IOException e) { throw new PippoRuntimeException(e); } }