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

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

Introduction

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

Prototype

public static SerializationPolicy loadFromStream(InputStream inputStream,
        List<ClassNotFoundException> classNotFoundExceptions) throws IOException, ParseException 

Source Link

Document

Loads a SerializationPolicy from an input stream and optionally record any ClassNotFoundException s.

Usage

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

License:Apache License

/**
 * Used by HybridServiceServlet./*from  www. j  ava  2s. com*/
 */
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.
 * //  w  w  w  .j a v a  2  s  . c om
 * 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 w w w.ja  v  a  2  s.  c  om
        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.gdevelop.gwt.syncrpc.RpcFinderUtil.java

License:Apache License

public static SerializationPolicy getSchedulePolicy(String rpcUrl) {
    SerializationPolicy result = null;/* www  . j a  v a 2s.  com*/
    String responseText = null;
    try {
        responseText = getResponseText(rpcUrl);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    InputStream is = new java.io.StringBufferInputStream(responseText);
    try {
        result = SerializationPolicyLoader.loadFromStream(is, null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

From source file:com.metadot.book.connectr.server.utils.ChannelServer.java

License:Apache License

/**
 * Creates a new SerializationPolicy for push RPC.
 *///from  w  w w  .  jav a 2 s  .c  o  m
private static SerializationPolicy createPushSerializationPolicy() {

    File[] files = new File("connectr").listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".gwt.rpc");
        }
    });

    List<SerializationPolicy> policies = new ArrayList<SerializationPolicy>();

    for (File f : files) {
        try {
            BufferedInputStream input = new BufferedInputStream(new FileInputStream(f));
            policies.add(SerializationPolicyLoader.loadFromStream(input, null));
        } catch (Exception e) {
            throw new RuntimeException("Unable to load a policy file: " + f.getAbsolutePath());
        }
    }

    return new MergedSerializationPolicy(policies);
}

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;/* w w  w .  j  ava  2 s .  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   ww w  .j  a  va  2  s. com
   */
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.server.filter.serialization.ServletContextSerializationPolicyProvider.java

License:Open Source License

/**
 * @param moduleBaseURL//from   w ww.j a  va2s . c  o m
 * @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 SerializationPolicy loadSerializationPolicy(HttpServletRequest request, String moduleBasePath,
        String strongName) throws IncompatibleRemoteServiceException, CwtRpcException {
    final String relativeModuleBasePath;
    final String policyFilePath;
    final InputStream is;
    final SerializationPolicy serializationPolicy;

    if (log.isDebugEnabled()) {
        log.debug("Trying to load serialization policy " + "for module base path '" + moduleBasePath
                + "' with strong name '" + strongName + "'");
    }/*www  .  j av  a  2s.  c  o m*/
    relativeModuleBasePath = getRelativeModuleBasePath(request, moduleBasePath);
    policyFilePath = getPolicyPath(relativeModuleBasePath, strongName);

    if (log.isDebugEnabled()) {
        log.debug("Trying to load policy file '" + policyFilePath + "' from servlet context");
    }
    is = getServletContext().getResourceAsStream(policyFilePath);
    try {
        if (is != null) {
            try {
                serializationPolicy = SerializationPolicyLoader.loadFromStream(is, null);
            } catch (ParseException e) {
                log.error("Failed to parse policy file '" + policyFilePath + "'", e);
                throw new CwtRpcException("System error while initializing serialization");
            } catch (IOException e) {
                log.error("Error while reading policy file '" + policyFilePath + "'", e);
                throw new CwtRpcException("System error while initializing serialization");
            }
        } else {
            if (log.isWarnEnabled()) {
                log.warn("Requested policy file '" + policyFilePath + "' does not exist");
            }
            throw new IncompatibleRemoteServiceException(
                    "Strong name '" + strongName + "' seems to be invalid");
        }
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
            log.error("Error while closing servlet context resource '" + policyFilePath + "'", e);
        }
    }

    return serializationPolicy;
}

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 2  s . c  om
 */
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;
}