/** * This method may be invoked by user code to notify interceptors that a nested * operation is being invoked which is denoted by this request details. */ public void notifyIncomingRequestPreHandled(RestOperationTypeEnum theOperationType) { RequestDetails requestDetails = getRequestDetails(); if (requestDetails == null) { return; } IRestfulServerDefaults server = requestDetails.getServer(); if (server == null) { return; } List<IServerInterceptor> interceptors = server.getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, this); } }
boolean continueProcessing = next.incomingRequestPreProcessed(theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); boolean continueProcessing = next.incomingRequestPostProcessed(requestDetails, theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); IServerInterceptor next = getInterceptors().get(i); try { next.processingCompletedNormally(requestDetails); } catch (Throwable t) { ourLog.error("Failure in interceptor method", t); if (!next.handleException(requestDetails, e, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); exception = next.preProcessOutgoingException(requestDetails, e, theRequest); if (exception != null) { ourLog.debug("Interceptor {} returned false, not continuing processing"); if (!next.handleException(requestDetails, exception, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return;
@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { IBaseResource response = doInvokeServer(theServer, theRequest); Set<SummaryEnum> summaryMode = RestfulServerUtils.determineSummaryMode(theRequest); ResponseDetails responseDetails = new ResponseDetails(); responseDetails.setResponseResource(response); responseDetails.setResponseCode(Constants.STATUS_HTTP_200_OK); HttpServletRequest servletRequest = null; HttpServletResponse servletResponse = null; if (theRequest instanceof ServletRequestDetails) { servletRequest = ((ServletRequestDetails) theRequest).getServletRequest(); servletResponse = ((ServletRequestDetails) theRequest).getServletResponse(); } for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = theServer.getInterceptors().get(i); boolean continueProcessing = next.outgoingResponse(theRequest, response); if (!continueProcessing) { return null; } continueProcessing = next.outgoingResponse(theRequest, responseDetails, servletRequest, servletResponse); if (!continueProcessing) { return null; } } boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); return theRequest.getResponse().streamResponseAsResource(responseDetails.getResponseResource(), prettyPrint, summaryMode, responseDetails.getResponseCode(), null, theRequest.isRespondGzip(), isAddContentLocationHeader()); }
boolean continueProcessing = next.incomingRequestPreProcessed(theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); boolean continueProcessing = next.incomingRequestPostProcessed(requestDetails, theRequest, theResponse); if (!continueProcessing) { ourLog.debug("Interceptor {} returned false, not continuing processing"); IServerInterceptor next = getInterceptors().get(i); try { next.processingCompletedNormally(requestDetails); } catch (Throwable t) { ourLog.error("Failure in interceptor method", t); if (!next.handleException(requestDetails, e, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return; for (int i = getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = getInterceptors().get(i); exception = next.preProcessOutgoingException(requestDetails, e, theRequest); if (exception != null) { ourLog.debug("Interceptor {} returned false, not continuing processing"); if (!next.handleException(requestDetails, exception, theRequest, theResponse)) { ourLog.debug("Interceptor {} returned false, not continuing processing"); return;
protected final Object invokeServerMethod(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) { // Handle server action interceptors RestOperationTypeEnum operationType = getRestOperationType(theRequest); if (operationType != null) { for (IServerInterceptor next : theServer.getInterceptors()) { ActionRequestDetails details = new ActionRequestDetails(theRequest); populateActionRequestDetailsForInterceptor(theRequest, details, theMethodParams); next.incomingRequestPreHandled(operationType, details); } } // Actually invoke the method try { Method method = getMethod(); return method.invoke(getProvider(), theMethodParams); } catch (InvocationTargetException e) { if (e.getCause() instanceof BaseServerResponseException) { throw (BaseServerResponseException) e.getCause(); } throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } catch (Exception e) { throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } }
boolean continueProcessing = next.outgoingResponse(theRequest, outcome); if (!continueProcessing) { return null; continueProcessing = next.outgoingResponse(theRequest, responseDetails, servletRequest, servletResponse); if (!continueProcessing) { return null;
public void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails theRequestDetails) { if (theRequestDetails.getId() != null && theRequestDetails.getId().hasResourceType() && isNotBlank(theRequestDetails.getResourceType())) { if (theRequestDetails.getId().getResourceType().equals(theRequestDetails.getResourceType()) == false) { throw new InternalErrorException( "Inconsistent server state - Resource types don't match: " + theRequestDetails.getId().getResourceType() + " / " + theRequestDetails.getResourceType()); } } if (theRequestDetails.getUserData().get(PROCESSING_SUB_REQUEST) == Boolean.TRUE) { theRequestDetails.notifyIncomingRequestPreHandled(theOperationType); } List<IServerInterceptor> interceptors = getConfig().getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, theRequestDetails); } }
@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { IBaseResource response = doInvokeServer(theServer, theRequest); Set<SummaryEnum> summaryMode = RestfulServerUtils.determineSummaryMode(theRequest); ResponseDetails responseDetails = new ResponseDetails(); responseDetails.setResponseResource(response); responseDetails.setResponseCode(Constants.STATUS_HTTP_200_OK); HttpServletRequest servletRequest = null; HttpServletResponse servletResponse = null; if (theRequest instanceof ServletRequestDetails) { servletRequest = ((ServletRequestDetails) theRequest).getServletRequest(); servletResponse = ((ServletRequestDetails) theRequest).getServletResponse(); } for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) { IServerInterceptor next = theServer.getInterceptors().get(i); boolean continueProcessing = next.outgoingResponse(theRequest, response); if (!continueProcessing) { return null; } continueProcessing = next.outgoingResponse(theRequest, responseDetails, servletRequest, servletResponse); if (!continueProcessing) { return null; } } boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theServer, theRequest); return theRequest.getResponse().streamResponseAsResource(responseDetails.getResponseResource(), prettyPrint, summaryMode, responseDetails.getResponseCode(), null, theRequest.isRespondGzip(), isAddContentLocationHeader()); }
/** * This method may be invoked by user code to notify interceptors that a nested * operation is being invoked which is denoted by this request details. */ public void notifyIncomingRequestPreHandled(RestOperationTypeEnum theOperationType) { RequestDetails requestDetails = getRequestDetails(); if (requestDetails == null) { return; } IRestfulServerDefaults server = requestDetails.getServer(); if (server == null) { return; } List<IServerInterceptor> interceptors = server.getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, this); } }
boolean continueProcessing = next.outgoingResponse(theRequest, outcome); if (!continueProcessing) { return null; continueProcessing = next.outgoingResponse(theRequest, responseDetails, servletRequest, servletResponse); if (!continueProcessing) { return null;
protected final Object invokeServerMethod(IRestfulServer<?> theServer, RequestDetails theRequest, Object[] theMethodParams) { // Handle server action interceptors RestOperationTypeEnum operationType = getRestOperationType(theRequest); if (operationType != null) { for (IServerInterceptor next : theServer.getInterceptors()) { ActionRequestDetails details = new ActionRequestDetails(theRequest); populateActionRequestDetailsForInterceptor(theRequest, details, theMethodParams); next.incomingRequestPreHandled(operationType, details); } } // Actually invoke the method try { Method method = getMethod(); return method.invoke(getProvider(), theMethodParams); } catch (InvocationTargetException e) { if (e.getCause() instanceof BaseServerResponseException) { throw (BaseServerResponseException) e.getCause(); } throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } catch (Exception e) { throw new InternalErrorException("Failed to call access method: " + e.getCause(), e); } }
public void notifyInterceptors(RestOperationTypeEnum theOperationType, ActionRequestDetails theRequestDetails) { if (theRequestDetails.getId() != null && theRequestDetails.getId().hasResourceType() && isNotBlank(theRequestDetails.getResourceType())) { if (theRequestDetails.getId().getResourceType().equals(theRequestDetails.getResourceType()) == false) { throw new InternalErrorException( "Inconsistent server state - Resource types don't match: " + theRequestDetails.getId().getResourceType() + " / " + theRequestDetails.getResourceType()); } } if (theRequestDetails.getUserData().get(PROCESSING_SUB_REQUEST) == Boolean.TRUE) { theRequestDetails.notifyIncomingRequestPreHandled(theOperationType); } List<IServerInterceptor> interceptors = getConfig().getInterceptors(); for (IServerInterceptor next : interceptors) { next.incomingRequestPreHandled(theOperationType, theRequestDetails); } }