org.osgl.exception.UnexpectedException Java Examples
The following examples show how to use
org.osgl.exception.UnexpectedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Genie.java From java-di with Apache License 2.0 | 6 votes |
PostConstructProcessor postConstructProcessor(Annotation annotation) { Class<? extends Annotation> annoClass = annotation.annotationType(); PostConstructProcessor processor = postConstructProcessors.get(annoClass); if (null == processor) { if (!annoClass.isAnnotationPresent(PostConstructProcess.class)) { throw new UnexpectedException("Cannot find PostConstructProcessor on %s", annoClass); } PostConstructProcess pcp = annoClass.getAnnotation(PostConstructProcess.class); Class<? extends PostConstructProcessor> cls = pcp.value(); processor = get(cls); PostConstructProcessor p2 = postConstructProcessors.putIfAbsent(annoClass, processor); if (null != p2) { processor = p2; } } return processor; }
Example #2
Source File: RequestSpec.java From actframework with Apache License 2.0 | 6 votes |
@Override public void validate(Interaction interaction) throws UnexpectedException { if (S.notBlank(email)) { return; } if (null != get) { method = H.Method.GET; url = get; } else if (null != post) { method = H.Method.POST; url = post; } else if (null != put) { method = H.Method.PUT; url = put; } else if (null != delete) { method = H.Method.DELETE; url = delete; } E.unexpectedIf(null == method, "method not specified in request spec of interaction[%s]", interaction); if (null == url || ".".equals(url)) { url = ""; } }
Example #3
Source File: RequestSpec.java From actframework with Apache License 2.0 | 6 votes |
public void resolveParent(RequestTemplateManager manager) { if (resolved) { return; } if (null == parent) { parent = "global"; } RequestSpec parentSpec = manager.getTemplate(parent); if (null != parentSpec && this != parentSpec) { parentSpec.resolveParent(manager); extendsParent(parentSpec); } else if (!"global".equals(parent)) { throw new UnexpectedException("parent request template not found: " + parent); } resolved = true; }
Example #4
Source File: TestSession.java From actframework with Apache License 2.0 | 6 votes |
private Verifier tryLoadVerifier(String name) { boolean revert = false; if (name.startsWith("!") || name.startsWith("-")) { revert = true; name = name.substring(1).trim(); } else if (name.startsWith("not:") || name.startsWith("not ")) { revert = true; name = name.substring(4).trim(); } Class<?> c = tryLoadClass(name); if (null != c) { if (Verifier.class.isAssignableFrom(c)) { final Verifier v = (Verifier) (null != app ? app.getInstance(c) : $.newInstance(c)); return v.meOrReversed(revert); } else { throw new UnexpectedException("Class not supported: " + name); } } return null; }
Example #5
Source File: Interaction.java From actframework with Apache License 2.0 | 6 votes |
@Override public void validate(TestSession session) throws UnexpectedException { E.unexpectedIf(null == request, "request spec not specified in interaction[%s]", this); //E.unexpectedIf(null == response, "response spec not specified"); act.metric.Timer timer = metric.startTimer("validate"); try { request.resolveParent(session.requestTemplateManager); request.validate(this); if (null != response) { response.validate(this); } reset(); } finally { timer.stop(); } }
Example #6
Source File: Act.java From actframework with Apache License 2.0 | 6 votes |
private static void startNetworkLayer(NetworkBootupThread nbt) { if (network.isDestroyed()) { return; } LOGGER.debug("starting network layer ..."); try { nbt.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new UnexpectedException(e); } if (null != nbt.exception) { throw nbt.exception; } network.start(); }
Example #7
Source File: RequestHandlerProxy.java From actframework with Apache License 2.0 | 6 votes |
private ActionMethodMetaInfo findActionInfoFromParent(ControllerClassMetaInfo ctrlInfo, String methodName) { ActionMethodMetaInfo actionInfo; ControllerClassMetaInfo parent = ctrlInfo.parent(true); if (null == parent) { throw new UnexpectedException("Cannot find action method meta info: %s", actionPath); } while (true) { actionInfo = parent.action(methodName); if (null != actionInfo) { break; } parent = parent.parent(true); if (null == parent) { break; } } return new ActionMethodMetaInfo($.requireNotNull(actionInfo), ctrlInfo); }
Example #8
Source File: TextParser.java From actframework with Apache License 2.0 | 6 votes |
@Override public Map<String, String[]> parse(ActionContext context) { H.Request req = context.req(); InputStream is = req.inputStream(); try { Map<String, String[]> params = new HashMap<String, String[]>(); ByteArrayOutputStream os = new ByteArrayOutputStream(); int b; while ((b = is.read()) != -1) { os.write(b); } byte[] data = os.toByteArray(); params.put(ActionContext.REQ_BODY, data.length == 0 ? null : new String[] {new String(data, req.characterEncoding())}); return params; } catch (Exception e) { throw new UnexpectedException(e); } }
Example #9
Source File: PluginScanner.java From actframework with Apache License 2.0 | 6 votes |
public int scan() { Plugin.InfoRepo.clear(); List<Class<?>> pluginClasses = Act.pluginClasses(); int sz = pluginClasses.size(); for (int i = 0; i < sz; ++i) { Class<?> c = pluginClasses.get(i); try { Plugin p = (Plugin) $.newInstance(c); Plugin.InfoRepo.register(p); } catch (UnexpectedException e) { // ignore: some plugin does not provide default constructor logger.warn(e, "failed to register plugin: %s", c); } } return sz; }
Example #10
Source File: CSRF.java From actframework with Apache License 2.0 | 6 votes |
/** * Check CSRF token after session resolved * @param context the current context */ public void check(ActionContext context, H.Session session) { if (!enabled) { return; } String token = context.csrfPrefetched(); try { if (!csrfProtector.verifyToken(token, session, app)) { context.clearCsrfPrefetched(); raiseCsrfNotVerified(context); } } catch (UnexpectedException e) { Act.LOGGER.warn(e, "Error checking CSRF token"); raiseCsrfNotVerified(context); } }
Example #11
Source File: InterceptorTestController.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("bar") public int bar(int n) throws Exception { if (n % 2 == 0) { throw new ArrayIndexOutOfBoundsException("array:" + n); } else if (n % 3 == 0) { throw new UnexpectedException("unexpected:%s", n); } else { throw new Exception("exception:" + n); } }
Example #12
Source File: SimpleEventListenerMarkerTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("/event/custom_marker") public void test(EventBus eventBus) { eventReceived = null; eventBus.trigger(USER_LOGGED_IN); if (USER_LOGGED_IN == eventReceived) { ok(); } throw new UnexpectedException("failed"); }
Example #13
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("setter/boolean_setter_exists") public void itShallNotGenerateSetterForBooleanPropertyIfAlreadyExists() { DerivedSimpleBean bean = new DerivedSimpleBean("foo"); bean.weirdFlag = false; if (!bean.weirdFlag) { throw new UnexpectedException(); } }
Example #14
Source File: Codec.java From java-tool with Apache License 2.0 | 5 votes |
/** * Build an hexadecimal MD5 hash for a String * * @param value The String to hash * @return An hexadecimal Hash */ public static String hexMD5(String value) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.reset(); messageDigest.update(value.getBytes("utf-8")); byte[] digest = messageDigest.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new UnexpectedException(ex); } }
Example #15
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("getter/boolean_getter_exists") public void itShallNotGenerateGetterForBooleanPropertyIfAlreadyExists() { SimpleBeanWithoutDefaultConstructor bean = new SimpleBeanWithoutDefaultConstructor("foo"); if (!bean.magicFlag) { throw new UnexpectedException(); } }
Example #16
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("getter/boolean_getter") public void checkBooleanPropertyGetter() { SimpleBeanWithoutDefaultConstructor bean = new SimpleBeanWithoutDefaultConstructor("foo"); if (bean.active) { throw new UnexpectedException(); } }
Example #17
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("getter/field_read") public void itShallTurnFieldReadIntoGetterForSBean() { SimpleBeanWithoutDefaultConstructor bean = new SimpleBeanWithoutDefaultConstructor("foo"); bean.setMagicNumber(2); if (4 != bean.magicNumber) { throw new UnexpectedException(); } }
Example #18
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("getter/create_nsbean") public void itShallNotCreateGetterForNonSbean() { NotSimpleBeanWithoutDefaultConstructor bean = new NotSimpleBeanWithoutDefaultConstructor("foo"); try { $.invokeVirtual(bean, "getPropertyWithoutGetter"); throw new UnexpectedException(); } catch (UnexpectedNoSuchMethodException e) { if (!"foo".equals(bean.propertyWithoutGetter)) { throw new UnexpectedException(); }; } }
Example #19
Source File: Codec.java From java-tool with Apache License 2.0 | 5 votes |
/** * Build an hexadecimal SHA1 hash for a String * * @param value The String to hash * @return An hexadecimal Hash */ public static String hexSHA1(String value) { try { MessageDigest md; md = MessageDigest.getInstance("SHA-1"); md.update(value.getBytes("utf-8")); byte[] digest = md.digest(); return byteToHexString(digest); } catch (Exception ex) { throw new UnexpectedException(ex); } }
Example #20
Source File: Processor.java From act-doc with Apache License 2.0 | 5 votes |
@OnAppStart public void ensureWorkspace() { File file = workspace(); if (!file.exists()) { if (!file.mkdir()) { throw new UnexpectedException("Workspace not ready for use: " + file.getAbsolutePath()); } } }
Example #21
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("getter/create") public void itShallCreateGetterForProperty(App app) { SimpleBeanWithoutDefaultConstructor bean = new SimpleBeanWithoutDefaultConstructor("foo"); if (!"foo".equals($.invokeVirtual(bean, "getPropertyWithoutGetter"))){ throw new UnexpectedException(); }; }
Example #22
Source File: SimpleBeanTestBed.java From actframework with Apache License 2.0 | 5 votes |
@GetAction("def_const/nsbean_no_def_const") public void itShallNotCreateDefaultConstructorForNonSimpleBeanWithoutDefaultConstructor(App app) { try { app.getInstance(NotSimpleBeanWithoutDefaultConstructor.class); throw new UnexpectedException(); } catch (InjectException e) { // this is correct behavior ignore it } }
Example #23
Source File: YamlLoader.java From actframework with Apache License 2.0 | 5 votes |
private Class<?> loadModelType(String type) { if (type.contains(".") || $.isPrimitiveType(type)) { return classForName(type); } for (String pkg : modelPackages) { String patched = S.concat(pkg, type); try { return classForName(patched); } catch (Exception e) { // ignore } } throw new UnexpectedException("Cannot load type: %s", type); }
Example #24
Source File: Func.java From actframework with Apache License 2.0 | 5 votes |
private void parseParamPart(String s) { if ("true".equalsIgnoreCase(s)) { highPrecision = true; } else if ("false".equalsIgnoreCase(s)) { highPrecision = false; } else if (Keyword.of("highPrecision").equals(Keyword.of(s))) { highPrecision = true; } else if (Keyword.of("lowPrecision").equals(Keyword.of(s))) { highPrecision = false; } else if ("hp".equalsIgnoreCase(s)) { highPrecision = true; } else if ("lp".equalsIgnoreCase(s)) { highPrecision = false; } else if (s.startsWith("+")) { s = s.substring(1); delta = Time.parseDuration(s); } else { if (S.isInt(s)) { delta = Integer.parseInt(s); } else if (s.startsWith("-")) { s = s.substring(1); delta = -Time.parseDuration(s); } else { throw new UnexpectedException("Unknown time parameter: " + s); } } }
Example #25
Source File: Scenario.java From actframework with Apache License 2.0 | 5 votes |
@Override public void validate(TestSession session) throws UnexpectedException { errorIf(S.blank(name), "Scenario name not defined"); for (Interaction interaction : interactions) { interaction.validate(session); } processConstants(session); }
Example #26
Source File: ParamValueLoaderService.java From actframework with Apache License 2.0 | 5 votes |
protected ParamValueLoader[] findMethodParamLoaders( Method method, Class host, ActContext ctx, $.Var<Boolean> hasValidationConstraint) { Type[] types = method.getGenericParameterTypes(); int sz = types.length; if (0 == sz) { return DUMB; } ParamValueLoader[] loaders = new ParamValueLoader[sz]; Annotation[][] annotations = ReflectedInvokerHelper.requestHandlerMethodParamAnnotations(method); for (int i = 0; i < sz; ++i) { String name = paramName(i); Type type = types[i]; Map<String, Class> typeLookups = null; if (type instanceof TypeVariable || type instanceof ParameterizedType) { typeLookups = Generics.buildTypeParamImplLookup(host); } BeanSpec spec = BeanSpec.of(type, annotations[i], name, injector, typeLookups); if (hasValidationConstraint(spec)) { hasValidationConstraint.set(true); } ParamValueLoader loader = paramValueLoaderOf(spec, ctx); if (null == loader) { throw new UnexpectedException("Cannot find param value loader for param: " + spec); } loaders[i] = loader; } return loaders; }
Example #27
Source File: AppCrypto.java From actframework with Apache License 2.0 | 5 votes |
/** * Returns decrypted message. * * Note this method uses {@link act.conf.AppConfigKey#SECRET confiured application secret} * * @param message the message to be decrypted. * @return the decrypted message. */ public String decrypt(String message) { try { return Crypto.decryptAES(message, secret); } catch (UnexpectedException e) { Throwable cause = e.getCause(); if (cause instanceof InvalidKeyException) { LOGGER.error("Cannot encrypt/decrypt! Please download Java Crypto Extension pack from Oracle: http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html"); } throw e; } }
Example #28
Source File: AppCrypto.java From actframework with Apache License 2.0 | 5 votes |
/** * Returns encrypted message. * * Note this method uses {@link act.conf.AppConfigKey#SECRET confiured application secret} * * @param message the message to be encrypted * @return the encrypted message */ public String encrypt(String message) { try { return Crypto.encryptAES(message, secret); } catch (UnexpectedException e) { Throwable cause = e.getCause(); if (cause instanceof InvalidKeyException) { LOGGER.error("Cannot encrypt/decrypt! Please download Java Crypto Extension pack from Oracle: http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html"); } throw e; } }
Example #29
Source File: ViewManager.java From actframework with Apache License 2.0 | 5 votes |
private <T extends VarDef> void _register(T var, Map<String, T> map, boolean fromApp) { if (map.containsKey(var.name())) { throw new UnexpectedException("Implicit variable[%s] has already been registered", var.name()); } map.put(var.name(), var); if (fromApp) { appDefined.put(var.name(), var); } }
Example #30
Source File: ViewManager.java From actframework with Apache License 2.0 | 5 votes |
void register(View view) { E.NPE(view); if (registered(view)) { throw new UnexpectedException("View[%s] already registered", view.name()); } viewList.add(view); }