Example usage for com.google.gwt.rpc.server HostedModeClientOracle HostedModeClientOracle

List of usage examples for com.google.gwt.rpc.server HostedModeClientOracle HostedModeClientOracle

Introduction

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

Prototype

HostedModeClientOracle

Source Link

Usage

From source file:net.zschech.gwt.comet.server.CometServlet.java

License:Apache License

protected ClientOracle getClientOracle(HttpServletRequest request) throws IOException {
    String permutationStrongName = request.getParameter(CometTransport.STRONG_NAME_PARAMETER);
    if (permutationStrongName == null) {
        return null;
    }/*from w w  w  .j a  v a 2s . co m*/

    ClientOracle toReturn;
    synchronized (clientOracleCache) {
        if (clientOracleCache.containsKey(permutationStrongName)) {
            toReturn = clientOracleCache.get(permutationStrongName).get();
            if (toReturn != null) {
                return toReturn;
            }
        }

        if ("HostedMode".equals(permutationStrongName)) {
            // if (!allowHostedModeConnections()) {
            // throw new SecurityException("Blocked hosted mode request");
            // }
            toReturn = new HostedModeClientOracle();
        } else {
            String moduleBase = request.getParameter(CometTransport.MODULE_BASE_PARAMETER);
            if (moduleBase == null) {
                return null;
            }

            String basePath = new URL(moduleBase).getPath();
            if (basePath == null) {
                throw new MalformedURLException(
                        "Blocked request without GWT base path parameter (XSRF attack?)");
            }

            String contextPath = getServletContext().getContextPath();
            if (!basePath.startsWith(contextPath)) {
                throw new MalformedURLException(
                        "Blocked request with invalid GWT base path parameter (XSRF attack?)");
            }
            basePath = basePath.substring(contextPath.length());

            InputStream in = findClientOracleData(basePath, permutationStrongName);

            toReturn = WebModeClientOracle.load(in);
        }
        clientOracleCache.put(permutationStrongName, new SoftReference<ClientOracle>(toReturn));
    }

    return toReturn;
}

From source file:org.atmosphere.gwt.server.impl.RPCUtil.java

License:Apache License

protected static ClientOracle getClientOracle(HttpServletRequest request, ServletContext context)
        throws IOException {
    String permutationStrongName = request.getParameter(Constants.STRONG_NAME_PARAMETER);
    if (permutationStrongName == null) {
        return null;
    }//from  www  .j  av a 2s. c  o  m

    ClientOracle toReturn;
    synchronized (clientOracleCache) {
        if (clientOracleCache.containsKey(permutationStrongName)) {
            toReturn = clientOracleCache.get(permutationStrongName).get();
            if (toReturn != null) {
                return toReturn;
            }
        }

        if ("HostedMode".equals(permutationStrongName)) {
            // if (!allowHostedModeConnections()) {
            // throw new SecurityException("Blocked hosted mode request");
            // }
            toReturn = new HostedModeClientOracle();
        } else {
            String moduleBase = request.getParameter(Constants.MODULE_BASE_PARAMETER);
            if (moduleBase == null) {
                return null;
            }

            String basePath = new URL(moduleBase).getPath();
            if (basePath == null) {
                throw new MalformedURLException(
                        "Blocked request without GWT base path parameter (XSRF attack?)");
            }

            String contextPath = context.getContextPath();
            if (!basePath.startsWith(contextPath)) {
                throw new MalformedURLException(
                        "Blocked request with invalid GWT base path parameter (XSRF attack?)");
            }
            basePath = basePath.substring(contextPath.length());

            InputStream in = findClientOracleData(basePath, permutationStrongName, context);

            toReturn = WebModeClientOracle.load(in);
        }
        clientOracleCache.put(permutationStrongName, new SoftReference<ClientOracle>(toReturn));
    }

    return toReturn;
}