/** * <p>getClassForName.</p> * * @param className a {@link java.lang.String} object. * @return a {@link java.lang.Class} object. */ public Class getClassForName(final String className) { try { final OsgiRegistry osgiRegistry = ReflectionHelper.getOsgiRegistryInstance(); if (osgiRegistry != null) { return osgiRegistry.classForNameWithException(className); } else { return AccessController.doPrivileged(ReflectionHelper.classForNameWithExceptionPEA(className)); } } catch (final ClassNotFoundException ex) { throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), ex); } catch (final PrivilegedActionException pae) { final Throwable cause = pae.getCause(); if (cause instanceof ClassNotFoundException) { throw new RuntimeException(LocalizationMessages.ERROR_SCANNING_CLASS_NOT_FOUND(className), cause); } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else { throw new RuntimeException(cause); } } }
/** * Uses {@link AsyncContext} to suspend current request * * @return obtained {@link AsyncContext} or throws error */ private AsyncContext suspend() { final AsyncContext context = asyncContext.get(); if (!context.suspend()) { throw new ProcessingException(LocalizationMessages.ERROR_SUSPENDING_ASYNC_REQUEST()); } return context; }
@Override public Response dispatch(Object resource, ContainerRequest request) throws ProcessingException { final AsyncContext context = this.asyncContext.get(); if(!context.suspend()) throw new ProcessingException(LocalizationMessages.ERROR_SUSPENDING_ASYNC_REQUEST()); final ContainerRequestContext requestContext = containerRequestContext.get(); Publisher pub = (Publisher)originalDispatcher.dispatch(resource, request) .getEntity(); Spouts.from(pub).onEmptySwitch(()->Spouts.of(Response.noContent().build())) .forEach(1,context::resume, context::resume); return null; }
@Override public Duration fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return Duration.parse(value); }
@Override public String toString(Duration value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public Period fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return Period.parse(value); }
@Override public String toString(Period value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public Instant fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return parseInstant(value); }
@Override public String toString(Instant value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public LocalDate fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return LocalDate.from(parseInstant(value)); }
@Override public String toString(LocalDate value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public LocalDateTime fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return LocalDateTime.from(parseInstant(value)); }
@Override public String toString(LocalDateTime value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public LocalTime fromString(String value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return LocalTime.from(parseInstant(value)); }
@Override public String toString(LocalTime value) { if (value == null) { throw new IllegalArgumentException( LocalizationMessages.METHOD_PARAMETER_CANNOT_BE_NULL("value") ); } return value.toString(); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if(!authorize(requestContext, resourcePermission)) { throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED()); } }