@Override public void onEvent(final RequestEvent event) { if (event.getType() == RequestEvent.Type.RESOURCE_METHOD_START) { final UnitOfWork unitOfWork = this.methodMap.get(event.getUriInfo() .getMatchedResourceMethod().getInvocable().getDefinitionMethod()); this.unitOfWorkAspect.beforeStart(unitOfWork); } else if (event.getType() == RequestEvent.Type.RESP_FILTERS_START) { try { this.unitOfWorkAspect.afterEnd(); } catch (final Exception e) { throw new MappableException(e); } } else if (event.getType() == RequestEvent.Type.ON_EXCEPTION) { this.unitOfWorkAspect.onError(); } }
@Override public void onEvent(RequestEvent event) { final RequestEvent.Type eventType = event.getType(); if (eventType == RequestEvent.Type.RESOURCE_METHOD_START) { UnitOfWork unitOfWork = methodMap.get(event.getUriInfo() .getMatchedResourceMethod().getInvocable().getDefinitionMethod()); unitOfWorkAspect.beforeStart(unitOfWork); } else if (eventType == RequestEvent.Type.RESP_FILTERS_START) { try { unitOfWorkAspect.afterEnd(); } catch (Exception e) { throw new MappableException(e); } } else if (eventType == RequestEvent.Type.ON_EXCEPTION) { unitOfWorkAspect.onError(); } else if (eventType == RequestEvent.Type.FINISHED) { EntityManagerContext.unBindAll(EntityManager::close); } }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { try { for (Map.Entry<AuthorizingAnnotationHandler, Annotation> authzCheck : authzChecks.entrySet()) { AuthorizingAnnotationHandler handler = authzCheck.getKey(); Annotation authzSpec = authzCheck.getValue(); handler.assertAuthorized(authzSpec); } } catch (AuthorizationException e) { throw new MappableException(e); // TODO Try without wrapping } }
/** {@inheritDoc} */ @Override public Response toResponse(Throwable exception) { int status = parseHttpStatus(exception); ErrorMessage message = new ErrorMessage(); if (exception instanceof MappableException && exception.getCause() != null) { exception = exception.getCause(); } message.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString()); message.setStatus(status); message.setThrowable(exception); message.setMessage(parseMessage(exception, status)); message.setDescription(parseDescription(exception, status)); message.setErrors(parseErrors(exception, status)); MediaType type = ExceptionMapperUtils.getResponseType(status); if (status == 500) { String uri = ""; if (Requests.getRequest() != null) { uri = " > " + Requests.getUriInfo().getRequestUri(); } logger.error(message.getMessage() + uri, exception); } else if (status == 404) { Requests.setProperty(BEFORE_EXCEPTION_KEY, exception); } return Response.status(status) .type(type) .entity(message).build(); }
@Override public void onEvent(RequestEvent event) { if (event.getType() == RequestEvent.Type.RESOURCE_METHOD_START) { this.unitOfWork = this.methodMap.get(event.getUriInfo().getMatchedResourceMethod().getInvocable() .getDefinitionMethod()); if (unitOfWork != null) { this.session = route().openSession(); try { configureSession(); ManagedSessionContext.bind(this.session); beginTransaction(); } catch (Throwable th) { this.session.close(); this.session = null; ManagedSessionContext.unbind(route()); throw th; } } } else if (event.getType() == RequestEvent.Type.RESP_FILTERS_START) { if (this.session != null) { try { commitTransaction(); } catch (Exception e) { rollbackTransaction(); throw new MappableException(e); } finally { this.session.close(); this.session = null; ManagedSessionContext.unbind(route()); } } } else if (event.getType() == RequestEvent.Type.ON_EXCEPTION) { if (this.session != null) { try { rollbackTransaction(); } finally { this.session.close(); this.session = null; ManagedSessionContext.unbind(route()); } } } }