All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cedarsolutions.wiring.gwt.rpc.XsrfRpcProxyGenerator Maven / Gradle / Ivy

There is a newer version: 5.8.4
Show newest version
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *              C E D A R
 *          S O L U T I O N S       "Software done right."
 *           S O F T W A R E
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Copyright (c) 2013 Kenneth J. Pronovici.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Apache License, Version 2.0.
 * See LICENSE for more information about the licensing terms.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Author   : Kenneth J. Pronovici 
 * Language : Java 6
 * Project  : Common Java Functionality
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package com.cedarsolutions.wiring.gwt.rpc;

import com.google.gwt.core.ext.GeneratorContext;
import com.google.gwt.core.ext.RebindResult;
import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.core.ext.UnableToCompleteException;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.user.rebind.rpc.ProxyCreator;
import com.google.gwt.user.rebind.rpc.ServiceInterfaceProxyGenerator;

/**
 * GWT generator to create a customized proxy that knows how to make CSRF/XSRF-protected requests.
 *
 * 

* When you request an RPC interface with GWT.create(MyRemoteService.class), * GWT normally does some magic to implement an asynchronous proxy over your * remote service interface. Below, we generate customized code that knows how * to call the CSRF/XSRF token service before making the actual RPC call. That * way, RPC clients don't need to know anything about the way the service is * actually invoked — it's all controlled by annotations. *

* *

* To configure this generator, put the following lines in your .gwt.xml * configuration file: *

* *
 *    <generate-with class="com.cedarsolutions.wiring.gwt.rpc.XsrfRpcProxyGenerator">
 *       <when-type-assignable class="com.google.gwt.user.client.rpc.RemoteService" />
 *    </generate-with>
 * 
* * @see GWT RPC XSRF protection * @author Kenneth J. Pronovici */ public class XsrfRpcProxyGenerator extends ServiceInterfaceProxyGenerator { /** Tree logger that should be used for messages. */ protected TreeLogger logger; /** Generator context that is in place. */ protected GeneratorContext generatorContext; /** Instantiate the proxy generator. */ public XsrfRpcProxyGenerator() { super(); } /** Hook into the generatior process so we can get access to the generator context. */ @Override public RebindResult generateIncrementally(TreeLogger logger, GeneratorContext ctx, String requestedClass) throws UnableToCompleteException { this.setLogger(logger); this.setGeneratorContext(ctx); return super.generateIncrementally(this.logger, ctx, requestedClass); } /** Use our customzied proxy creator. */ @Override protected ProxyCreator createProxyCreator(JClassType remoteService) { return new XsrfRpcProxyCreator(remoteService); } /** Set the logger if it's not set already. */ protected void setLogger(TreeLogger logger) { if (this.logger == null) { this.logger = logger; } } /** Set the generator context if not set already. */ protected void setGeneratorContext(GeneratorContext generatorContext) { if (this.generatorContext == null) { this.generatorContext = generatorContext; } } /** Log a message, if the logger is configured. */ protected void log(String message) { if (this.logger != null) { this.logger.log(TreeLogger.DEBUG, message); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy