check if the request contains a valid number of items to retrieve

@param request
Tomcat servlet request
@param response
response object
@return number of items to retrieve<br>
zero if the number is invalid
337177
private static int checkNumItems(final HttpServletRequest request,
			final ReadResponse response) {
		final String sNumItems = request
				.getParameter(ProtocolConstants.Parameters.Read.NUM_ITEMS);
		if (sNumItems != null) {
			int numItems;
			try {
				numItems = Integer.valueOf(sNumItems);
				if (numItems > 0) {
					return numItems;
				}

				response.numItemsInvalid("Please provide a number greater than zero.");
			} catch (final NumberFormatException e) {
				response.numItemsInvalid("\""
						+ sNumItems
						+ "\" is not a number. Please provide a number such as \"15\" to retrieve that number of items.");
			}
		} else {
			response.numItemsMissing();
		}

		return 0;
	}
66996
boolean isErrorResponse(HttpResponse response) {
        StatusLine status = response.getStatusLine();
        if (status == null || status.getStatusCode() != 200) {
            return true;
        }
        return false;
    }
565325
private static boolean checkSuccess(HttpResponse response, boolean dryRun, TaskListener listener) {
        StatusLine status = response.getStatusLine();
        String content = "";
        try {
            content = ExtractorUtils.entityToString(response.getEntity());
            ExtractorUtils.validateStringNotBlank(content);
            JSONObject json = JSONObject.fromObject(content);
            String message = json.getString("message");
            if (assertResponseStatus(dryRun, listener, status, message)) {
                listener.getLogger().println(message);
                return true;
            }
        } catch (IOException e) {
            String parsingErrorStr = "Failed parsing distribution response";
            if (StringUtils.isNotBlank(content)) {
                parsingErrorStr = ": " + content;
            }
            e.printStackTrace(listener.error(parsingErrorStr));
        }
        return false;
    }
148099
public static boolean isScOk(HttpResponse response) {
        return response != null && response.getStatusLine()!= null &&
                response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
    }
920890
private boolean responseIsInValid() {
        if (response == null) {
            return true;
        }
        else if (!response.isHeadless() && validityCheck) {
            return request.getTransactionID() != response.getTransactionID();
        }
        else {
            return false;
        }
    }
92153
private CmsWebdavRange parseContentRange(HttpServletRequest request, HttpServletResponse response) {

        // Retrieving the content-range header (if any is specified
        String rangeHeader = request.getHeader(HEADER_CONTENTRANGE);

        if (rangeHeader == null) {
            return null;
        }

        // bytes is the only range unit supported
        if (!rangeHeader.startsWith("bytes")) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return null;
        }

        rangeHeader = rangeHeader.substring(6).trim();

        int dashPos = rangeHeader.indexOf('-');
        int slashPos = rangeHeader.indexOf('/');

        if (dashPos == -1) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return null;
        }

        if (slashPos == -1) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return null;
        }

        CmsWebdavRange range = new CmsWebdavRange();

        try {
            range.setStart(Long.parseLong(rangeHeader.substring(0, dashPos)));
            range.setEnd(Long.parseLong(rangeHeader.substring(dashPos + 1, slashPos)));
            range.setLength(Long.parseLong(rangeHeader.substring(slashPos + 1, rangeHeader.length())));
        } catch (NumberFormatException e) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return null;
        }

        if (!range.validate()) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return null;
        }

        return range;
    }
59485
public boolean status(int responseCode) {
		if (urlConnection instanceof HttpURLConnection) {
			HttpURLConnection http = (HttpURLConnection) urlConnection;
			try {
				return http.getResponseCode() == responseCode;
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}
		} else
			return false;
	}
544221
private static boolean hasResponseBody(int requestMethod, int responseCode) {
        return requestMethod != Request.Method.HEAD
            && !(HttpStatus.SC_CONTINUE <= responseCode && responseCode < HttpStatus.SC_OK)
            && responseCode != HttpStatus.SC_NO_CONTENT
            && responseCode != HttpStatus.SC_NOT_MODIFIED;
    }
474155
@Internal
    public static Optional<NettyMutableHttpResponse> set(NettyHttpRequest<?> request, HttpResponse<?> response) {
        request.attr(KEY).set((NettyMutableHttpResponse) response);
        return Optional.ofNullable((NettyMutableHttpResponse) response);
    }
88817
private boolean isRateLimitReached(ResponseEntity<String> response) {
        HttpHeaders header = response.getHeaders();
        List<String> limit = header.get("X-RateLimit-Remaining");
        boolean rateLimitReached =  CollectionUtils.isEmpty(limit) ? false : Integer.valueOf(limit.get(0)) < settings.getRateLimitThreshold();
        if (rateLimitReached) {
            LOG.error("Github rate limit reached. Threshold =" + settings.getRateLimitThreshold() + ". Current remaining ="+Integer.valueOf(limit.get(0)));
        }
        return rateLimitReached;
    }
965897
private boolean validBatchGetRequest(Map<Class<?>, List<KeyPair>> itemsToGet) {
        if (itemsToGet == null || itemsToGet.size() == 0) {
            return false;
        }

        for (Class<?> clazz : itemsToGet.keySet()) {
            if (itemsToGet.get(clazz) != null && itemsToGet.get(clazz).size() > 0) {
                return true;
            }
        }
        return false;
    }
1091796
public static Tag status(@Nullable HttpServletResponse response) {
        return response == null ? STATUS_UNKNOWN : Tag.of("status", Integer.toString(response.getStatus()));
    }
422615
@SuppressWarnings("null")
  private boolean accepts(SlingHttpServletRequest request) {
    return request.getMethod().equalsIgnoreCase(METHOD_GET)
        && request.getResource() != null
        && StringUtils.equals(request.getResource().getValueMap().get(JCR_PRIMARYTYPE, String.class), NT_FILE);
  }
64061
boolean incrementRequestCount( HttpServletRequest request, HttpServletResponse response,
                                   ServletContext servletContext )
        throws IOException
    {
        //
        // First cache the max-concurrent-request-count value.
        //
        if ( _maxConcurrentRequestCount == -1 )
        {
            _maxConcurrentRequestCount = DEFAULT_MAX_CONCURRENT_REQUEST_COUNT;
            assert servletContext != null;

            String countStr = servletContext.getInitParameter( MAX_CONCURRENT_REQUESTS_PARAM );
            if ( countStr != null )
            {
                try
                {
                    _maxConcurrentRequestCount = Integer.parseInt( countStr );
                }
                catch ( NumberFormatException e )
                {
                    _log.error( "Invalid value for servlet context parameter" + MAX_CONCURRENT_REQUESTS_PARAM
                                + ": " + countStr, e );
                }

                if ( _maxConcurrentRequestCount < 1 )
                {
                    _maxConcurrentRequestCount = DEFAULT_MAX_CONCURRENT_REQUEST_COUNT;
                    _log.error( "Invalid value for servlet context parameter" + MAX_CONCURRENT_REQUESTS_PARAM
                                + ": " + countStr );
                }
            }
        }

        //
        // Now, if the current count of concurrent requests to this instance is greater than the max,
        // send an error on the response.
        //
        if ( _requestCount >= _maxConcurrentRequestCount )
        {
            if ( _log.isInfoEnabled() )
            {
                _log.info( "Too many requests to FlowController " + getDisplayName() + " ("
                           + ( _requestCount + 1 ) + '>' + _maxConcurrentRequestCount + "); returning error code "
                           + EXCEEDED_MAX_CONCURRENT_REQUESTS_ERRORCODE );
            }

            response.sendError( EXCEEDED_MAX_CONCURRENT_REQUESTS_ERRORCODE );
            return false;
        }

        //
        // We're ok -- increment the count and continue.
        //
        ++_requestCount;
        return true;
    }
448787
public static Header findHeader(HttpResponse response, String headerName) {
		Header[] headers = response.getHeaders(headerName);
		return headers.length > 0 ? headers[0] : null;
	}
17895
private boolean isSnapshotInProgressResponse(
            ClientResponse response) {
        if (response.getStatus() != ClientResponse.SUCCESS) {
            return false;
        }

        if (response.getResults() == null) {
            return false;
        }

        if (response.getResults().length < 1) {
            return false;
        }

        VoltTable results = response.getResults()[0];
        if (results.getRowCount() < 1) {
            return false;
        }

        boolean snapshotInProgress = false;
        while (results.advanceRow()) {
            if (results.getString("RESULT").equals("FAILURE")) {
                if (results.getString("ERR_MSG").equals("SNAPSHOT IN PROGRESS")) {
                    snapshotInProgress = true;
                }
            }
        }
        return snapshotInProgress;
    }
653454
private static Boolean checkOwnUpdates(final HttpServletRequest request,
			final ReadResponse response) {
		final String sOwnUpdates = request
				.getParameter(ProtocolConstants.Parameters.Read.OWN_UPDATES);
		if (sOwnUpdates != null) {
			try {
				final int iOwnUpdates = Integer.valueOf(sOwnUpdates);
				return (iOwnUpdates != 0);
			} catch (final NumberFormatException e) {
				response.ownUpdatesInvalid(sOwnUpdates);
			}
		} else {
			response.ownUpdatesMissing();
		}

		return null;
	}