Example usage for com.google.gwt.user.server.rpc SerializationPolicyLoader getSerializationPolicyFileName

List of usage examples for com.google.gwt.user.server.rpc SerializationPolicyLoader getSerializationPolicyFileName

Introduction

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

Prototype

public static String getSerializationPolicyFileName(String serializationPolicyStrongName) 

Source Link

Document

Returns the serialization policy file name from the serialization policy strong name.

Usage

From source file:com.brightedu.server.BrightServlet.java

License:Apache License

/**
 * Used by HybridServiceServlet.//from www .  j  a  va2  s .c  o  m
 */
static SerializationPolicy loadSerializationPolicy(HttpServlet servlet, HttpServletRequest request,
        String moduleBaseURL, String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = request.getContextPath();

    String modulePath = null;
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            servlet.log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet
     * itself. If you need to implement a scheme different than this,
     * override this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        servlet.log(message);
    } else {
        // Strip off the context path from the module base URL. It should be
        // a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file and read its contents.
        InputStream is = servlet.getServletContext().getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    servlet.log("ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'",
                            e);
                } catch (IOException e) {
                    servlet.log("ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'",
                            e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                servlet.log(message);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}

From source file:com.dotspots.rpcplus.flexiblerpc.FlexibleRemoteServiceServlet.java

License:Apache License

/**
 * Gets the {@link SerializationPolicy} for given module base URL and strong name if there is one.
 * /*from   w w  w . j  a  v  a2  s . c  o m*/
 * Override this method to provide a {@link SerializationPolicy} using an alternative approach.
 * 
 * @param request
 *            the HTTP request being serviced
 * @param moduleBaseURL
 *            as specified in the incoming payload
 * @param strongName
 *            a strong name that uniquely identifies a serialization policy file
 * @return a {@link SerializationPolicy} for the given module base URL and strong name, or <code>null</code> if
 *         there is none
 */
protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL,
        String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = request.getContextPath();

    String modulePath = null;
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet itself. If you need to implement a
     * scheme different than this, override this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        log(message, null);
    } else {
        // Strip off the context path from the module base URL. It should be a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file read its contents.
        InputStream is = getServletContext().getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    log("ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'", e);
                } catch (IOException e) {
                    log("ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'", e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                log(message, null);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}

From source file:com.gdevelop.gwt.syncrpc.RemoteServiceSyncProxy.java

License:Apache License

public RemoteServiceSyncProxy(String moduleBaseURL, String remoteServiceRelativePath,
        String serializationPolicyName, SessionManager connectionManager) {
    this.moduleBaseURL = moduleBaseURL;
    if (remoteServiceRelativePath.startsWith("/")) {
        int idx = moduleBaseURL.indexOf("//") + 2;
        idx = moduleBaseURL.indexOf("/", idx);
        this.remoteServiceURL = moduleBaseURL.substring(0, idx) + remoteServiceRelativePath;
    } else {//from  www . j  av a2 s  . c  o  m
        this.remoteServiceURL = moduleBaseURL + remoteServiceRelativePath;
    }
    this.serializationPolicyName = serializationPolicyName;
    this.connectionManager = connectionManager;
    if (serializationPolicyName == null) {
        serializationPolicy = new DummySerializationPolicy();
    } else {
        // TODO
        if (true) {
            // serializationPolicy = new DummySerializationPolicy();
            // return;
        }
        String policyFileName = SerializationPolicyLoader
                .getSerializationPolicyFileName(serializationPolicyName);
        // if pre-loaded, use the pre-loaded version.
        if (connectionManager instanceof DefaultSessionManager) {
            // may be unnecessary check and instead modify SessionManager
            // interface
            serializationPolicy = ((DefaultSessionManager) connectionManager)
                    .getSerializationPolicy(serializationPolicyName);
        }
        if (serializationPolicy == null) {
            InputStream is = getClass().getResourceAsStream("/" + policyFileName);
            try {
                serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
            } catch (Exception e) {
                throw new InvocationException(
                        "Error while loading serialization policy " + serializationPolicyName, e);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        // Ignore this error
                    }
                }
            }
        } // en
    }
    unionizeWhitelists();
}

From source file:com.openforevent.gwt.gwtrpc.server.GwtRpcServiceImpl.java

License:Apache License

static SerializationPolicy loadSerializationPolicy(HttpServlet servlet, HttpServletRequest request,
        String moduleBaseURL, String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = request.getContextPath();

    String modulePath = null;/* ww  w  .jav  a 2s  .  c  o m*/
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            servlet.log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet
     * itself. If you need to implement a scheme different than this, override
     * this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        servlet.log(message, null);
    } else {
        // Strip off the context path from the module base URL. It should be a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file and read its contents.
        InputStream is = servlet.getServletContext().getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    servlet.log("ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'",
                            e);
                } catch (IOException e) {
                    servlet.log("ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'",
                            e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                servlet.log(message);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}

From source file:com.truong.brook.server.CustomRemoteServiceServlet.java

License:Apache License

/**
   * Used by HybridServiceServlet.//from   w  w  w.  j a  va 2s . c o m
   */
static SerializationPolicy loadSerializationPolicy(HttpServlet servlet, HttpServletRequest request,
        String moduleBaseURL, String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = request.getContextPath();

    String modulePath = null;
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            servlet.log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet
     * itself. If you need to implement a scheme different than this, override
     * this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        servlet.log(message);
    } else {
        // Strip off the context path from the module base URL. It should be a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file and read its contents.
        InputStream is = servlet.getServletContext().getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    servlet.log("ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'",
                            e);
                } catch (IOException e) {
                    servlet.log("ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'",
                            e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                servlet.log(message);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}

From source file:de.csenk.gwt.ws.rebind.filter.serialization.GWTSerializerGenerator.java

License:Open Source License

/**
 * @param serializerLogger// ww  w. j a v  a2 s .c  o m
 * @param context
 * @param typesSentFromBrowser
 * @param typesSentToBrowser
 * @param typeStrings
 * @return
 */
private String writeSerializationPolicyFile(TreeLogger logger, GeneratorContext ctx,
        SerializableTypeOracle serializationSto, SerializableTypeOracle deserializationSto,
        Map<JType, String> typeStrings, JClassType serializerInterface) throws UnableToCompleteException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(baos,
                SerializationPolicyLoader.SERIALIZATION_POLICY_FILE_ENCODING);
        TypeOracle oracle = ctx.getTypeOracle();
        PrintWriter pw = new PrintWriter(osw);

        JType[] serializableTypes = unionOfTypeArrays(serializationSto.getSerializableTypes(),
                deserializationSto.getSerializableTypes(), new JType[] { serializerInterface });

        for (int i = 0; i < serializableTypes.length; ++i) {
            JType type = serializableTypes[i];
            String binaryTypeName = TypeOracleMediator.computeBinaryClassName(type);
            pw.print(binaryTypeName);
            pw.print(", " + Boolean.toString(deserializationSto.isSerializable(type)));
            pw.print(", " + Boolean.toString(deserializationSto.maybeInstantiated(type)));
            pw.print(", " + Boolean.toString(serializationSto.isSerializable(type)));
            pw.print(", " + Boolean.toString(serializationSto.maybeInstantiated(type)));
            pw.print(", " + typeStrings.get(type));

            /*
             * Include the serialization signature to bump the RPC file name
             * if obfuscated identifiers are used.
             */
            pw.print(", " + SerializationUtils.getSerializationSignature(oracle, type));
            pw.print('\n');

            /*
             * Emit client-side field information for classes that may be
             * enhanced on the server. Each line consists of a
             * comma-separated list containing the keyword '@ClientFields',
             * the class name, and a list of all potentially serializable
             * client-visible fields.
             */
            if ((type instanceof JClassType) && ((JClassType) type).isEnhanced()) {
                JField[] fields = ((JClassType) type).getFields();
                JField[] rpcFields = new JField[fields.length];
                int numRpcFields = 0;
                for (JField f : fields) {
                    if (f.isTransient() || f.isStatic() || f.isFinal()) {
                        continue;
                    }
                    rpcFields[numRpcFields++] = f;
                }

                pw.print(SerializationPolicyLoader.CLIENT_FIELDS_KEYWORD);
                pw.print(',');
                pw.print(binaryTypeName);
                for (int idx = 0; idx < numRpcFields; idx++) {
                    pw.print(',');
                    pw.print(rpcFields[idx].getName());
                }
                pw.print('\n');
            }
        }

        // Closes the wrapped streams.
        pw.close();

        byte[] serializationPolicyFileContents = baos.toByteArray();
        String serializationPolicyName = Util.computeStrongName(serializationPolicyFileContents);

        String serializationPolicyFileName = SerializationPolicyLoader
                .getSerializationPolicyFileName(serializationPolicyName);
        OutputStream os = ctx.tryCreateResource(logger, serializationPolicyFileName);
        if (os != null) {
            os.write(serializationPolicyFileContents);
            GeneratedResource resource = ctx.commitResource(logger, os);

            /*
             * Record which proxy class created the resource. A manifest
             * will be emitted by the RpcPolicyManifestLinker.
             */
            ctx.commitArtifact(logger,
                    new RpcPolicyFileArtifact(serializerInterface.getQualifiedSourceName(), resource));
        } else {
            logger.log(TreeLogger.TRACE, "SerializationPolicy file for RemoteService '"
                    + serializerInterface.getQualifiedSourceName() + "' already exists; no need to rewrite it.",
                    null);
        }

        return serializationPolicyName;
    } catch (UnsupportedEncodingException e) {
        logger.log(TreeLogger.ERROR,
                SerializationPolicyLoader.SERIALIZATION_POLICY_FILE_ENCODING + " is not supported", e);
        throw new UnableToCompleteException();
    } catch (IOException e) {
        logger.log(TreeLogger.ERROR, null, e);
        throw new UnableToCompleteException();
    }
}

From source file:de.csenk.gwt.ws.server.filter.serialization.ServletContextSerializationPolicyProvider.java

License:Open Source License

/**
 * @param moduleBaseURL/*  w  w w  .  j  a  v  a 2 s  .com*/
 * @param strongName
 * @return
 */
private SerializationPolicy doGetSerializationPolicy(String moduleBaseURL, String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = servletContext.getContextPath();

    String modulePath = null;
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            servletContext.log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet
     * itself. If you need to implement a scheme different than this,
     * override this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        servletContext.log(message, null);
    } else {
        // Strip off the context path from the module base URL. It should be
        // a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file and read its contents.
        InputStream is = servletContext.getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    servletContext.log(
                            "ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'", e);
                } catch (IOException e) {
                    servletContext.log(
                            "ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'", e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                servletContext.log(message);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}

From source file:de.itsvs.cwtrpc.core.DefaultExtendedSerializationPolicyProvider.java

License:Apache License

protected String getPolicyPath(String relativeModuleBasePath, String strongName) throws SecurityException {
    final StringBuilder strongNamePathBuilder;
    final String resultingPath;

    strongNamePathBuilder = new StringBuilder();
    strongNamePathBuilder.append(relativeModuleBasePath);
    strongNamePathBuilder.append(strongName);
    if (strongNamePathBuilder.indexOf("/..") >= 0) {
        throw new SecurityException("Specified combination of module base Url and "
                + "strong name contains relative path to " + "sub directory: " + strongNamePathBuilder);
    }//from w ww  .  j a  v a  2  s  . c  o m

    resultingPath = SerializationPolicyLoader.getSerializationPolicyFileName(strongNamePathBuilder.toString());
    return resultingPath;
}

From source file:es.upm.fi.dia.oeg.map4rdf.server.servlet.DispatchServiceServlet.java

License:Open Source License

/**
 * Used by HybridServiceServlet./*from  ww  w  .  j  a va  2s  .c o  m*/
 */
static SerializationPolicy loadSerializationPolicy(HttpServlet servlet, HttpServletRequest request,
        String moduleBaseURL, String strongName) {
    // The serialization policy path depends only by contraxt path

    SerializationPolicy serializationPolicy = null;

    String contextRelativePath = "/es.upm.fi.dia.oeg.map4rdf.map4rdf/";

    String serializationPolicyFilePath = SerializationPolicyLoader
            .getSerializationPolicyFileName(contextRelativePath + strongName);

    // Open the RPC resource file and read its contents.
    InputStream is = servlet.getServletContext().getResourceAsStream(serializationPolicyFilePath);
    try {
        if (is != null) {
            try {
                serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
            } catch (ParseException e) {
                servlet.log("ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'", e);
            } catch (IOException e) {
                servlet.log("ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'", e);
            }
        } else {
            String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                    + "' was not found; did you forget to include it in this deployment?";
            servlet.log(message);
        }
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                // Ignore this error
            }
        }
    }

    return serializationPolicy;
}

From source file:net.latin.server.GwtBaseAction.java

License:Apache License

/**
 * Gets the {@link SerializationPolicy} for given module base URL and strong
 * name if there is one.//w w  w  . jav  a2 s  .  co  m
 *
 * Override this method to provide a {@link SerializationPolicy} using an
 * alternative approach.
 *
 * @param request
 *            the HTTP request being serviced
 * @param moduleBaseURL
 *            as specified in the incoming payload
 * @param strongName
 *            a strong name that uniquely identifies a serialization policy
 *            file
 * @return a {@link SerializationPolicy} for the given module base URL and
 *         strong name, or <code>null</code> if there is none
 */
protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL,
        String strongName) {
    // The request can tell you the path of the web app relative to the
    // container root.
    String contextPath = request.getContextPath();

    String modulePath = null;
    if (moduleBaseURL != null) {
        try {
            modulePath = new URL(moduleBaseURL).getPath();
        } catch (MalformedURLException ex) {
            // log the information, we will default
            getServletContext().log("Malformed moduleBaseURL: " + moduleBaseURL, ex);
        }
    }

    SerializationPolicy serializationPolicy = null;

    /*
     * Check that the module path must be in the same web app as the servlet
     * itself. If you need to implement a scheme different than this,
     * override this method.
     */
    if (modulePath == null || !modulePath.startsWith(contextPath)) {
        String message = "ERROR: The module path requested, " + modulePath
                + ", is not in the same web application as this servlet, " + contextPath
                + ".  Your module may not be properly configured or your client and server code maybe out of date.";
        getServletContext().log(message);
    } else {
        // Strip off the context path from the module base URL. It should be
        // a
        // strict prefix.
        String contextRelativePath = modulePath.substring(contextPath.length());

        String serializationPolicyFilePath = SerializationPolicyLoader
                .getSerializationPolicyFileName(contextRelativePath + strongName);

        // Open the RPC resource file read its contents.
        InputStream is = getServletContext().getResourceAsStream(serializationPolicyFilePath);
        try {
            if (is != null) {
                try {
                    serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
                } catch (ParseException e) {
                    getServletContext().log(
                            "ERROR: Failed to parse the policy file '" + serializationPolicyFilePath + "'", e);
                } catch (IOException e) {
                    getServletContext().log(
                            "ERROR: Could not read the policy file '" + serializationPolicyFilePath + "'", e);
                }
            } else {
                String message = "ERROR: The serialization policy file '" + serializationPolicyFilePath
                        + "' was not found; did you forget to include it in this deployment?";
                getServletContext().log(message);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    // Ignore this error
                }
            }
        }
    }

    return serializationPolicy;
}