public boolean canExecute ( @ Nonnull final IRequestWebScopeWithoutResponse aRequestScope , @ Nonnull final MutableInt aStatusCode ) { if ( aRequestScope == null ) return false ; // Note: HTTP method was already checked in APIDescriptorList // Check required headers for ( final String sRequiredHeader : m_aDescriptor . requiredHeaders ( ) ) if ( aRequestScope . headers ( ) . getFirstHeaderValue ( sRequiredHeader ) == null ) { LOGGER . warn ( "Request '" + m_sPath + "' is missing required HTTP header '" + sRequiredHeader + "'" ) ; return false ; } // Check required parameters for ( final String sRequiredParam : m_aDescriptor . requiredParams ( ) ) if ( ! aRequestScope . params ( ) . containsKey ( sRequiredParam ) ) { LOGGER . warn ( "Request '" + m_sPath + "' is missing required HTTP parameter '" + sRequiredParam + "'" ) ; return false ; } // Check explicit filter if ( m_aDescriptor . hasExecutionFilter ( ) ) if ( ! m_aDescriptor . getExecutionFilter ( ) . canExecute ( aRequestScope ) ) { LOGGER . warn ( "Request '" + m_sPath + "' cannot be executed because of ExecutionFilter" ) ; return false ; } if ( m_aDescriptor . allowedMimeTypes ( ) . isNotEmpty ( ) ) { final String sContentType = aRequestScope . getContentType ( ) ; // Parse to extract any parameters etc. final MimeType aMT = MimeTypeParser . safeParseMimeType ( sContentType ) ; // If parsing fails, use the provided String final String sMimeTypeToCheck = aMT == null ? sContentType : aMT . getAsStringWithoutParameters ( ) ; if ( ! m_aDescriptor . allowedMimeTypes ( ) . contains ( sMimeTypeToCheck ) && ! m_aDescriptor . allowedMimeTypes ( ) . contains ( sMimeTypeToCheck . toLowerCase ( CGlobal . DEFAULT_LOCALE ) ) ) { LOGGER . warn ( "Request '" + m_sPath + "' contains the Content-Type '" + sContentType + "' which is not in the allowed list of " + m_aDescriptor . allowedMimeTypes ( ) ) ; // Special error code HTTP 415 aStatusCode . set ( HttpServletResponse . SC_UNSUPPORTED_MEDIA_TYPE ) ; return false ; } } return true ; }
Check if all pre - requisites are handled correctly . This checks if all required headers and params are present .