ServerGwtBridge() { threadProperties = new ThreadLocal<PropertiesImpl>() { @Override protected PropertiesImpl initialValue() { return new PropertiesImpl(); } }; // register built-in instantiators register(Object.class, new ObjectNew()); register(Localizable.class, new LocalizableInstantiator()); }
/** * Sets all GWT properties from the request. * <p> * If this method is overridden, this version should be called first and then * any modifications to property values should be done. * * @param req */ protected void setGwtProperties(HttpServletRequest req) { ServerGwtBridge.getInstance().setThreadProperty("locale", getGwtLocale(req)); // TODO(jat): other properties, such as user.agent? } }
@SuppressWarnings("unchecked") @Override public <T> T create(Class<?> clazz, Properties properties) { return tryCreate((Class<T>) clazz); } }
/** * Replaces the stack traces in the given Throwable and its causes with deobfuscated stack traces * wherever possible. * * @param throwable the Throwable that needs its stack trace to be deobfuscated * @param strongName the GWT permutation strong name */ public final void deobfuscateStackTrace(Throwable throwable, String strongName) { throwable.setStackTrace(resymbolize(throwable.getStackTrace(), strongName)); if (throwable.getCause() != null) { deobfuscateStackTrace(throwable.getCause(), strongName); } }
private SourceMapping loadSourceMap(String permutationStrongName, int fragmentId) { SourceMapping toReturn = sourceMaps.get(permutationStrongName + fragmentId); if (toReturn == null) { try { String sourceMapString = loadStreamAsString( getSourceMapInputStream(permutationStrongName, fragmentId)); toReturn = SourceMapConsumerFactory.parse(sourceMapString); sourceMaps.put(permutationStrongName + fragmentId, toReturn); } catch (Exception e) { } } return toReturn; }
/** * This function is only for server-side use which is why it's not in the * LoggingRequest interface. * * @param dir a directory, specified as a String */ public static void setSymbolMapsDirectory(String dir) { deobfuscator = StackTraceDeobfuscator.fromFileSystem(dir); }
public StackTraceElement[] deobfuscateStackTrace(StackTraceElement[] st, String strongName) { return super.resymbolize(st, strongName); }
/** * Retrieves a new {@link InputStream} for the given permutation strong name. This implementation, * which subclasses may override, returns a {@link InputStream} for the <code> * <i>permutation-strong-name</i>.symbolMap</code> file. * * @param permutationStrongName the GWT permutation strong name * @return a new {@link InputStream} */ protected InputStream getSymbolMapInputStream(String permutationStrongName) throws IOException { return openInputStream(permutationStrongName + ".symbolMap"); }
public static LogRecord deobfuscateLogRecord( StackTraceDeobfuscator deobfuscator, LogRecord lr, String strongName) { if (lr.getThrown() != null && strongName != null) { deobfuscator.deobfuscateStackTrace(lr.getThrown(), strongName); } return lr; }
/** * Set a property value globally. This value will be overridden by any * thread-specific property value of the same name. * * @param property * @param value */ public void setGlobalProperty(String property, String value) { globalProperties.setProperty(property, value); }
/** * Get the value of the named property, preferring a value specific to this * thread (see {@link #setThreadProperty(String, String)}) over one that is * set globally (see {@link #setGlobalProperty(String, String)}). * * @param property * @return the property's value or null if none */ public String getProperty(String property) { return properties.getProperty(property); }
@Override protected PropertiesImpl initialValue() { return new PropertiesImpl(); } };
@Override public String getProperty(String name) { String val = threadProperties.get().getProperty(name); if (val == null) { val = globalProperties.getProperty(name); } return val; } }
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { setGwtProperties(req); super.service(req, resp); }
/** * @param <T> * @param className * @return class instance or null */ protected <T> T tryCreate(String className) { try { Class<?> clazz = Class.forName(className); @SuppressWarnings("unchecked") T obj = (T) tryCreate(clazz); return obj; } catch (ClassNotFoundException e) { } return null; } }
/** * Get the singleton {@link ServerGwtBridge} instance, creating it if * necessary. The instance will be registered via * {@link GWT#setBridge(GWTBridge)} and will have the default instantiators * registered on it. * * @return the singleton {@link ServerGwtBridge} instance */ public static ServerGwtBridge getInstance() { synchronized (instanceLock) { if (instance == null) { instance = new ServerGwtBridge(); GWT.setBridge(instance); } return instance; } }
/** * By default, this service does not do any deobfuscation. In order to do * server-side deobfuscation, you must copy the symbolMaps files to a * directory visible to the server and set the directory using this method. */ public void setSymbolMapsDirectory(String symbolMapsDir) { deobfuscator = StackTraceDeobfuscator.fromFileSystem(symbolMapsDir); } }
protected InputStream getSourceMapInputStream(String permutationStrongName, int fragmentNumber) throws IOException { return openInputStream(permutationStrongName + "_sourceMap" + fragmentNumber + ".json"); }
/** * Set a property value for only the current thread. This value will override * any global property value of the same name. * * @param property * @param value */ public void setThreadProperty(String property, String value) { threadProperties.get().setProperty(property, value); } }
public static GwtLocale getLocale(Properties properties) { String propVal = properties.getProperty("locale"); if (propVal == null) { propVal = "default"; } return factory.fromString(propVal); }