/** * Returns the content length or -1 if the unknown. * * @param externalContext * the ExternalContext * @return the length or -1 */ public static final int getContentLength(ExternalContext externalContext) { RequestType type = getRequestType(externalContext); if(type.isRequestFromClient()) { try { Object request = externalContext.getRequest(); Method contentLenMethod = request.getClass().getMethod("getContentLength"); return (Integer) contentLenMethod.invoke(request); //this will autobox } catch(Exception e) { _LOG.error("Unsupported request type.", e); } } return -1; }
/** * Returns the request input stream if one is available * * @param externalContext * @return * @throws IOException */ public static final InputStream getRequestInputStream(ExternalContext externalContext) throws IOException { RequestType type = getRequestType(externalContext); if(type.isRequestFromClient()) { try { Object request = externalContext.getRequest(); Method method = request.getClass().getMethod(type.isPortlet()?"getPortletInputStream":"getInputStream"); return (InputStream) method.invoke(request); } catch (Exception e) { _LOG.error("Unable to get the request input stream because of an error", e); } } return null; }
if (!RequestType.SERVLET.equals(ExternalContextUtils.getRequestType(facesContext.getExternalContext())))