private void writeResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload) throws IOException { boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && shouldCompressResponse(request, response, responsePayload); RPCServletUtils.writeResponse(getServletContext(), response, responsePayload, gzipEncode); } }
/** * Returns <code>true</code> if the request accepts gzip encoding and the * response content's estimated UTF-8 byte length exceeds 256 bytes. * * @param request the request associated with the response content * @param responseContent a string that will be * @return <code>true</code> if the request accepts gzip encoding and the * response content's estimated UTF-8 byte length exceeds 256 bytes */ public static boolean shouldGzipResponseContent(HttpServletRequest request, String responseContent) { return acceptsGzipEncoding(request) && exceedsUncompressedContentLengthLimit(responseContent); }
/** * Returns the content of an {@link HttpServletRequest}, after verifying a * <code>gwt/x-gwt-rpc; charset=utf-8</code> content type. * * @param request the servlet request whose content we want to read * @return the content of an {@link HttpServletRequest} by decoding it using * <code>UTF-8</code> * @throws IOException if the request's input stream cannot be accessed, read * from or closed * @throws ServletException if the request's content type is not * <code>gwt/x-gwt-rpc; charset=utf-8</code>, ignoring case */ public static String readContentAsGwtRpc(HttpServletRequest request) throws IOException, ServletException { return readContent(request, GWT_RPC_CONTENT_TYPE, CHARSET_UTF8_NAME); }
throws IOException, ServletException { if (expectedContentType != null) { checkContentTypeIgnoreCase(request, expectedContentType); checkCharacterEncodingIgnoreCase(request, expectedCharSet); return new String(out.toByteArray(), getCharset(expectedCharSet)); } finally { if (in != null) {
@RequestMapping(value = "/commandService", method = RequestMethod.POST) public void processPostRpc(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { String requestPayload = RPCServletUtils.readContentAsGwtRpc(request); RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, CommandService.class, this); String responsePayload = RPC.invokeAndEncodeResponse(commandService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload); RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode); } catch (Exception e) { this.logger.error("Request processing failed", e); throw Throwables.propagate(e); } }
@Override protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { String requestPayload = this.readContent(request); RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, this.getClass(), this); String responsePayload = RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload); RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode); } catch (Exception e) { this.logger.error("Request processing failed", e); throw Throwables.propagate(e); } } }
/** * Determines whether the response to a given servlet request should or should * not be GZIP compressed. This method is only called in cases where the * requester accepts GZIP encoding. * <p> * This implementation currently returns <code>true</code> if the response * string's estimated byte length is longer than 256 bytes. Subclasses can * override this logic. * </p> * * @param request the request being served * @param response the response that will be written into * @param responsePayload the payload that is about to be sent to the client * @return <code>true</code> if responsePayload should be GZIP compressed, * otherwise <code>false</code>. */ protected boolean shouldCompressResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload) { return RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload); }
/** * Override this method in order to control the parsing of the incoming * request. For example, you may want to bypass the check of the Content-Type * and character encoding headers in the request, as some proxies re-write the * request headers. Note that bypassing these checks may expose the servlet to * some cross-site vulnerabilities. Your implementation should comply with the * HTTP/1.1 specification, which includes handling both requests which include * a Content-Length header and requests utilizing <code>Transfer-Encoding: * chuncked</code>. * * @param request the incoming request * @return the content of the incoming request encoded as a string. */ protected String readContent(HttpServletRequest request) throws ServletException, IOException { return RPCServletUtils.readContentAsGwtRpc(request); }
RPCServletUtils.writeResponseForUnexpectedFailure(servletContext, getThreadLocalResponse(), e);
gzipOutputStream.finish(); gzipOutputStream.flush(); setGzipEncodingHeader(response); responseBytes = output.toByteArray(); } catch (IOException e) {
@Override protected void processPost(HttpServletRequest request, HttpServletResponse response) throws Throwable { try { String requestPayload = this.readContent(request); RPCRequest rpcRequest = RPC.decodeRequest(requestPayload, this.getClass(), this); String responsePayload = RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(), rpcRequest.getFlags()); boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload); RPCServletUtils.writeResponse(null, response, responsePayload, gzipEncode); } catch (Exception e) { this.logger.error("Request processing failed", e); throw Throwables.propagate(e); } } }
throws IOException, ServletException { if (expectedContentType != null) { checkContentTypeIgnoreCase(request, expectedContentType); checkCharacterEncodingIgnoreCase(request, expectedCharSet); return new String(out.toByteArray(), getCharset(expectedCharSet)); } finally { if (in != null) {
/** * Determines whether the response to a given servlet request should or should * not be GZIP compressed. This method is only called in cases where the * requester accepts GZIP encoding. * <p> * This implementation currently returns <code>true</code> if the response * string's estimated byte length is longer than 256 bytes. Subclasses can * override this logic. * </p> * * @param request the request being served * @param response the response that will be written into * @param responsePayload the payload that is about to be sent to the client * @return <code>true</code> if responsePayload should be GZIP compressed, * otherwise <code>false</code>. */ protected boolean shouldCompressResponse(HttpServletRequest request, HttpServletResponse response, String responsePayload) { return RPCServletUtils.exceedsUncompressedContentLengthLimit(responsePayload); }
/** * Override this method in order to control the parsing of the incoming * request. For example, you may want to bypass the check of the Content-Type * and character encoding headers in the request, as some proxies re-write the * request headers. Note that bypassing these checks may expose the servlet to * some cross-site vulnerabilities. Your implementation should comply with the * HTTP/1.1 specification, which includes handling both requests which include * a Content-Length header and requests utilizing <code>Transfer-Encoding: * chuncked</code>. * * @param request the incoming request * @return the content of the incoming request encoded as a string. */ protected String readContent(HttpServletRequest request) throws ServletException, IOException { return RPCServletUtils.readContentAsGwtRpc(request); }
/** * Override this method to control what should happen when an exception * escapes the {@link #processCall(String)} method. The default * implementation will log the failure and send a generic failure response to * the client. * <p/> * * An "expected failure" is an exception thrown by a service method that is * declared in the signature of the service method. These exceptions are * serialized back to the client, and are not passed to this method. This * method is called only for exceptions or errors that are not part of the * service method's signature, or that result from SecurityExceptions, * SerializationExceptions, or other failures within the RPC framework. * <p/> * * Note that if the desired behavior is to both send the GENERIC_FAILURE_MSG * response AND to rethrow the exception, then this method should first send * the GENERIC_FAILURE_MSG response itself (using getThreadLocalResponse), * and then rethrow the exception. Rethrowing the exception will cause it to * escape into the servlet container. * * @param e * the exception which was thrown */ protected void RemoteServiceServlet_doUnexpectedFailure(Throwable e) { ServletContext servletContext = getServletContext(); RPCServletUtils.writeResponseForUnexpectedFailure(servletContext, getThreadLocalResponse(), e); }
gzipOutputStream.finish(); gzipOutputStream.flush(); setGzipEncodingHeader(response); responseBytes = output.toByteArray(); } catch (IOException e) {
protected static void writeResponse(HttpServletRequest request, HttpServletResponse response, ServletContext context, String responsePayload) throws IOException { boolean gzipEncode = RPCServletUtils.acceptsGzipEncoding(request) && shouldCompressResponse(request, response, responsePayload); RPCServletUtils.writeResponse(context, response, responsePayload, gzipEncode); }
/** * Returns <code>true</code> if the request accepts gzip encoding and the * response content's estimated UTF-8 byte length exceeds 256 bytes. * * @param request the request associated with the response content * @param responseContent a string that will be * @return <code>true</code> if the request accepts gzip encoding and the * response content's estimated UTF-8 byte length exceeds 256 bytes */ public static boolean shouldGzipResponseContent(HttpServletRequest request, String responseContent) { return acceptsGzipEncoding(request) && exceedsUncompressedContentLengthLimit(responseContent); }
/** * Returns the content of an {@link HttpServletRequest} by decoding it using * the UTF-8 charset. * * @param request the servlet request whose content we want to read * @return the content of an {@link HttpServletRequest} by decoding it using * the UTF-8 charset * @throws IOException if the requests input stream cannot be accessed, read * from or closed * @throws ServletException if the content length of the request is not * specified of if the request's content type is not * 'text/x-gwt-rpc' and 'charset=utf-8' * @deprecated Use {@link #readContent} instead. */ @Deprecated public static String readContentAsUtf8(HttpServletRequest request) throws IOException, ServletException { return readContent(request, null, null); }
throws IOException, ServletException { if (expectedContentType != null) { checkContentTypeIgnoreCase(request, expectedContentType); checkCharacterEncodingIgnoreCase(request, expectedCharSet); return new String(out.toByteArray(), getCharset(expectedCharSet)); } finally { if (in != null) {