Skip to content

Instantly share code, notes, and snippets.

@realityforge
Created February 13, 2021 06:36
Show Gist options
  • Save realityforge/0ce01c0c1a21ce6282c8692c1acf0829 to your computer and use it in GitHub Desktop.
Save realityforge/0ce01c0c1a21ce6282c8692c1acf0829 to your computer and use it in GitHub Desktop.
Example of doGetSerializationPolicy implementation
@Override
protected com.google.gwt.user.server.rpc.SerializationPolicy doGetSerializationPolicy( @javax.annotation.Nonnull final javax.servlet.http.HttpServletRequest request,
@javax.annotation.Nonnull final String moduleBase,
@javax.annotation.Nonnull final String strongName )
{
java.net.URL moduleBaseURL = null;
if ( null != moduleBase )
{
try
{
moduleBaseURL = new java.net.URL( moduleBase );
}
catch ( final java.net.MalformedURLException e )
{
// log the information, we will default
log( "Malformed moduleBaseURL: " + moduleBase, e );
return null;
}
}
final String contextPath = request.getContextPath();
java.io.InputStream stream = null;
String path = strongName;
if ( null != moduleBaseURL && moduleBaseURL.getPath().startsWith( contextPath ) )
{
final String contextRelativePath = moduleBaseURL.getPath().substring( contextPath.length() );
path = contextRelativePath + strongName + ".gwt.rpc";
stream = getServletContext().getResourceAsStream( path );
}
else if ( null != moduleBaseURL )
{
path = moduleBaseURL.toExternalForm() + strongName + ".gwt.rpc";
try
{
stream = new java.net.URL( path ).openStream();
}
catch ( final java.io.IOException e )
{
log( "ERROR: Failed to read the remote policy file '" + path + "'", e );
return null;
}
}
if ( null != stream )
{
try ( java.io.InputStream input = stream )
{
return com.google.gwt.user.server.rpc.SerializationPolicyLoader.loadFromStream( input, null );
}
catch ( final java.text.ParseException e )
{
log( "ERROR: Failed to parse the policy file '" + path + "'", e );
}
catch ( final java.io.IOException e )
{
log( "ERROR: Could not read the policy file '" + path + "'", e );
}
}
// If CodeServerPolicyUrl is available then we are probably in development and thus
// the policies are not expected to be part of the deployment
else if ( null == getCodeServerPolicyUrl( strongName ) )
{
final String message =
"ERROR: The serialization policy file '" + path + "' was not found; " +
"did you forget to include it in this deployment?";
log( message );
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment