Example usage for com.google.gwt.user.server.rpc RPCServletUtils readContentAsUtf8

List of usage examples for com.google.gwt.user.server.rpc RPCServletUtils readContentAsUtf8

Introduction

In this page you can find the example usage for com.google.gwt.user.server.rpc RPCServletUtils readContentAsUtf8.

Prototype

@Deprecated
public static String readContentAsUtf8(HttpServletRequest request) throws IOException, ServletException 

Source Link

Document

Returns the content of an HttpServletRequest by decoding it using the UTF-8 charset.

Usage

From source file:org.pentaho.mantle.server.DebugMantleServlet.java

License:Open Source License

public void doPost(HttpServletRequest req, HttpServletResponse resp) {
    // use HTTPClient to forward on the data to whatever server we want
    // eg. http://localhost:8080/pentaho/MantleService
    // 1. set the contentType
    // 2. add the data
    // 3. tack the response onto our response
    try {/* w  ww.j  a v  a  2  s  .com*/
        HttpClient client = new HttpClient();

        // If server userid/password was supplied, use basic authentication to
        // authenticate with the server.
        Credentials creds = new UsernamePasswordCredentials("joe", "password"); //$NON-NLS-1$ //$NON-NLS-2$
        client.getState().setCredentials(AuthScope.ANY, creds);
        client.getParams().setAuthenticationPreemptive(true);

        //      Enumeration attributes = req.getAttributeNames();
        //      while (attributes.hasMoreElements()) {
        //        System.out.println("Attribute: " + attributes.nextElement());
        //      }
        //
        //      Enumeration params = req.getParameterNames();
        //      while (params.hasMoreElements()) {
        //        System.out.println("Parameter: " + params.nextElement());
        //      }
        //
        //      Enumeration headers = req.getHeaderNames();
        //      while (headers.hasMoreElements()) {
        //        String headerName = (String) headers.nextElement();
        //        String headerValue = req.getHeader(headerName).replaceAll("8888", "8080");
        //        System.out.println("Header: " + headerName + "=" + headerValue);
        //        if (!headerName.equals("accept-encoding") && !headerName.equals("content-type") && !"content-length".equals(headerName)) {
        //          postMethod.setRequestHeader(headerName, headerValue);
        //        }
        //      }

        String requestPayload = RPCServletUtils.readContentAsUtf8(req);
        System.out.println("INCOMING: " + requestPayload); //$NON-NLS-1$
        requestPayload = requestPayload.replaceAll("8888/mantle", "8080/pentaho/mantle"); //$NON-NLS-1$ //$NON-NLS-2$

        PostMethod postMethod = null;
        if (requestPayload.indexOf("MantleLoginService") != -1) { //$NON-NLS-1$
            postMethod = new PostMethod(
                    "http://localhost:8080/pentaho/mantleLogin/MantleLoginService?userid=joe&password=password"); //$NON-NLS-1$
        } else if (requestPayload.indexOf("MantleService") != -1) { //$NON-NLS-1$
            postMethod = new PostMethod(
                    "http://localhost:8080/pentaho/mantle/MantleService?userid=joe&password=password"); //$NON-NLS-1$
        }
        requestPayload = requestPayload.replaceAll("org.pentaho.mantle.MantleApplication", "pentaho/mantle"); //$NON-NLS-1$ //$NON-NLS-2$
        requestPayload = requestPayload.replaceAll("org.pentaho.mantle.login.MantleLogin", //$NON-NLS-1$
                "pentaho/mantleLogin"); //$NON-NLS-1$

        System.out.println("OUTGOING: " + requestPayload); //$NON-NLS-1$

        StringRequestEntity stringEntity = new StringRequestEntity(requestPayload, "text/x-gwt-rpc", "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
        postMethod.setRequestEntity(stringEntity);

        try {
            @SuppressWarnings("unused")
            int status = client.executeMethod(postMethod);
            String postResult = postMethod.getResponseBodyAsString();
            resp.getOutputStream().write(postResult.getBytes("UTF-8")); //$NON-NLS-1$
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
    }
}

From source file:org.pentaho.mantle.server.DebugRemoteServiceServlet.java

License:Open Source License

/**
 * Standard HttpServlet method: handle the POST.
 * /* w  ww  .  j  a v a  2  s  .  com*/
 * This doPost method swallows ALL exceptions, logs them in the
 * ServletContext, and returns a GENERIC_FAILURE_MSG response with status code
 * 500.
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
    PentahoSystem.systemEntryPoint();
    try {
        // Store the request & response objects in thread-local storage.
        //
        perThreadRequest.set(request);
        perThreadResponse.set(response);

        // Read the request fully.
        //
        String requestPayload = RPCServletUtils.readContentAsUtf8(request);

        // Let subclasses see the serialized request.
        //
        onBeforeRequestDeserialized(requestPayload);

        // Invoke the core dispatching logic, which returns the serialized
        // result.
        //
        String responsePayload = processCall(requestPayload);

        // Let subclasses see the serialized response.
        //
        onAfterResponseSerialized(responsePayload);

        // Write the response.
        //
        writeResponse(request, response, responsePayload);
        return;
    } catch (Throwable e) {
        // Give a subclass a chance to either handle the exception or rethrow it
        //
        doUnexpectedFailure(e);
    } finally {
        // null the thread-locals to avoid holding request/response
        //
        perThreadRequest.set(null);
        perThreadResponse.set(null);
        PentahoSystem.systemExitPoint();
    }
}