IMHO in your case you should try to use the RemoteServiceServlet implementation.

I imagine the you have a dispatch servlet that use your adapter, If
I'm true, let your  handler use this servlet (extending
RemoteServiceServlet) to decode the payload.
 You could inject this servlet (Spring Proxy. ) or expose it reference
with Static getInstances ...


On Wed, Nov 12, 2008 at 11:03 AM, Sam <[EMAIL PROTECTED]> wrote:
>
>
> Hello Olivier,
> Thanks for the reply, I have seen your code and it extends from
> RemoteServiceServlet. Thats why you can pass third parameter as
> "this" . In my case , the service does not extend from
> RemoteServiceServlet. The actual defination of my class is
>                                   public class GWTHandlerAdapter
> implements HandlerAdapter, ServletContextAware
> Hence I wont be able to pass third parameter as " this" to the API
> RPC.decodeRequest().
> It works as per expected if I copy the portion of the code from the
> RemoteServiceServlet and pasted it into MySerilizationPolicy.java. The
> code for the same is as follows.
>
> RPCRequest rpcRequest = RPC.decodeRequest(requestString,
> remote_service.getClass(), MySerializationPolicyProvider .getInstance
> (servletContext, request, response));
>
> (MySerializationPolicyProvider  implements
> SerializationPolicyProvider)
> My concern is , is this the best way to deal with the scenerio in
> which service class is not extending from RemoteServiceServlet. Or is
> there any other way to achive this. Code for
> MySerializationPolicyProvider  is given below which is actually a
> copied code from RemoteServiceServlet. However problem with this
> approch is, if in next build of GWT , google made any change in The
> methodes of RemoteServiceServlet then we also need to include that
> change in our MySerializationPolicyProvider class .
> So m looking for some other alternative if at all possible.
>
>
>
> public class MySerializationPolicyProvider implements
> SerializationPolicyProvider {
>
>    /**
>     * A cache of moduleBaseURL and serialization policy strong name
> to [EMAIL PROTECTED] SerializationPolicy}.
>     */
>
>    private ServletContext servletContext;
>
>    /** ptcSerializationPolicy is used for getting the serialization
> policy once initialized. */
>    private SerializationPolicy ptcSerializattionPolicy = null;
>
>    private final Map<String, SerializationPolicy>
> serializationPolicyCache = new HashMap<String, SerializationPolicy>();
>
>    private final ThreadLocal<HttpServletRequest> perThreadRequest =
> new ThreadLocal<HttpServletRequest>();
>
>    private final ThreadLocal<HttpServletResponse> perThreadResponse =
> new ThreadLocal<HttpServletResponse>();
>
>    private static MySerializationPolicyProvider
> MySerializationPolicyProviderInstance;
>
>    private static final org.apache.log4j.Logger log =
> wt.log4j.LogR.getLogger(MySerializationPolicyProvider.class
>            .getName());
>
>    private MySerializationPolicyProvider() {
>
>    }
>
>    /**
>     * Constructor for making the class Singelton .
>     *
>     * @param servletContext
>     * @param request
>     * @return response
>     */
>    private MySerializationPolicyProvider(ServletContext
> servletContext, HttpServletRequest request,
>            HttpServletResponse response) {
>        this.servletContext = servletContext;
>        perThreadRequest.set(request);
>        perThreadResponse.set(response);
>    }
>
>    /**
>     * API for getting MySerializationPolicyProvider instance.
>     *
>     * @param servletContext
>     * @param request
>     * @return response
>     */
>
>    public static MySerializationPolicyProvider getInstance
> (ServletContext servletContext, HttpServletRequest request,
>            HttpServletResponse response) {
>        if (MySerializationPolicyProviderInstance == null)
>            MySerializationPolicyProviderInstance = new
> MySerializationPolicyProvider(servletContext, request,
>                    response);
>
>        return MySerializationPolicyProviderInstance;
>
>    }
>
>    /**
>     * API for getting serializationPolicy.
>     *
>     * @param moduleBaseURL
>     * @param strongName
>     */
>
>    public SerializationPolicy getSerializationPolicy(String
> moduleBaseURL, String strongName) {
>
>        SerializationPolicy serializationPolicy =
> getCachedSerializationPolicy(moduleBaseURL, strongName);
>
>        if (serializationPolicy != null) {
>            this.ptcSerializattionPolicy = serializationPolicy;
>            return serializationPolicy;
>
>        }
>
>        serializationPolicy = doGetSerializationPolicy
> (getThreadLocalRequest(), moduleBaseURL, strongName);
>
>        if (serializationPolicy == null) {
>
>            // Failed to get the requested serialization policy; use
> the default
>            serializationPolicy = RPC.getDefaultSerializationPolicy();
>
>        }
>
>        // This could cache null or an actual instance. Either way we
> will not
>
>        // attempt to lookup the policy again.
>
>        putCachedSerializationPolicy(moduleBaseURL, strongName,
> serializationPolicy);
>
>        this.ptcSerializattionPolicy = serializationPolicy;
>        return serializationPolicy;
>
>    }
>
>    /**
>     * get the cached serialization policy.
>     *
>     * @param moduleBaseURL
>     * @param strongName
>     * @return
>     */
>    private SerializationPolicy getCachedSerializationPolicy(
>
>    String moduleBaseURL, String strongName) {
>
>        synchronized (serializationPolicyCache) {
>
>            return serializationPolicyCache.get(moduleBaseURL +
> strongName);
>
>        }
>
>    }
>
>    /**
>     *
>     * @param moduleBaseURL
>     * @param strongName
>     * @param serializationPolicy
>     */
>    private void putCachedSerializationPolicy(String moduleBaseURL,
>
>    String strongName, SerializationPolicy serializationPolicy) {
>
>        synchronized (serializationPolicyCache) {
>
>            serializationPolicyCache.put(moduleBaseURL + strongName,
> serializationPolicy);
>
>        }
>
>    }
>
>    /**
>     * Gets the <code>HttpServletRequest</code> object for the current
> call. It is stored thread-locally so that
>     * simultaneous invocations can have different request objects.
>     */
>    protected final HttpServletRequest getThreadLocalRequest() {
>        return perThreadRequest.get();
>    }
>
>    /**
>     * Gets the [EMAIL PROTECTED] SerializationPolicy} for given module base 
> URL
> and strong name if there is one.
>     *
>     * Override this method to provide a [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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.error("Malformed moduleBaseURL:", ex);
>                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.";
>
>            log.error(message);
>
>            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) {
>                        log.error("ERROR: Failed to parse the policy
> file '" + serializationPolicyFilePath + "'", e);
>
>                        getServletContext().log(
>                                "ERROR: Failed to parse the policy
> file '" + serializationPolicyFilePath + "'", e);
>                    } catch (IOException e) {
>                        log.error("ERROR: Could not read the policy
> file '" + serializationPolicyFilePath + "'", 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?";
>                    log.error(message);
>
>                    getServletContext().log(message);
>                }
>            } finally {
>                if (is != null) {
>                    try {
>                        is.close();
>                    } catch (IOException e) {
>                        // Ignore this error
>                    }
>                }
>            }
>        }
>
>        return serializationPolicy;
>    }
>
>    /**
>     * getter for servlet context.
>     * @return
>     */
>    public ServletContext getServletContext() {
>        return servletContext;
>    }
>
>    /**
>     * setter for serlet context
>     * @param servletContext
>     */
>    public void setServletContext(ServletContext servletContext) {
>        this.servletContext = servletContext;
>    }
>
>    /**
>     * getter for ptc serialization policy.
>     * @return
>     */
>    public SerializationPolicy getPtcSerializattionPolicy() {
>        return ptcSerializattionPolicy;
>    }
>
>    /**
>     * setter for ptc serialization policy.
>     * @param ptcSerializattionPolicy
>     */
>    public void setPtcSerializattionPolicy(SerializationPolicy
> ptcSerializattionPolicy) {
>        this.ptcSerializattionPolicy = ptcSerializattionPolicy;
>    }
>
> }
>
>
> >
>



-- 
Si l'ignorance peut servir de consolation, elle n'en est pas moins illusoire.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to