org.apache.sling.extensions.gwt.user.server.rpc
Class SlingRemoteServiceServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
              extended by com.google.gwt.user.server.rpc.RemoteServiceServlet
                  extended by org.apache.sling.extensions.gwt.user.server.rpc.SlingRemoteServiceServlet
All Implemented Interfaces:
com.google.gwt.user.server.rpc.SerializationPolicyProvider, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class SlingRemoteServiceServlet
extends com.google.gwt.user.server.rpc.RemoteServiceServlet

Extending google's remote service servlet to enable resolving of resources through a bundle (for policy file loading).

This class is for version 2.0.4 of the GWT gwt-servlet.jar edition and it is highly recommended to compile client apps with the corresponding 2.0.4 GWT gwt-user.jar only!

GWT service servlets that are used in sling are required to extend the SlingRemoteServiceServlet instead of google's own RemoteServiceServlet.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
perThreadRequest, perThreadResponse
 
Constructor Summary
SlingRemoteServiceServlet()
           
 
Method Summary
protected  com.google.gwt.user.server.rpc.SerializationPolicy doGetSerializationPolicy(javax.servlet.http.HttpServletRequest request, java.lang.String moduleBaseURL, java.lang.String strongName)
          Gets the SerializationPolicy for given module base URL and strong name if there is one.
 java.lang.String processCall(java.lang.String payload)
          Process a call originating from the given request.
protected  void setBundle(org.osgi.framework.Bundle bundle)
          Allows the extending OSGi service to set the bundle it is part of.
protected  void setClassLoader(java.lang.ClassLoader classLoader)
          Allows the extending OSGi service to set its classloader.
 
Methods inherited from class com.google.gwt.user.server.rpc.RemoteServiceServlet
getSerializationPolicy, onAfterResponseSerialized, onBeforeRequestDeserialized, processPost, shouldCompressResponse
 
Methods inherited from class com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet
doPost, doUnexpectedFailure, getPermutationStrongName, getThreadLocalRequest, getThreadLocalResponse, onAfterRequestDeserialized, readContent
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlingRemoteServiceServlet

public SlingRemoteServiceServlet()
Method Detail

processCall

public java.lang.String processCall(java.lang.String payload)
                             throws com.google.gwt.user.client.rpc.SerializationException
Process a call originating from the given request. Uses the RPC.invokeAndEncodeResponse(Object, java.lang.reflect.Method, Object[]) method to do the actual work.

Subclasses may optionally override this method to handle the payload in any way they desire (by routing the request to a framework component, for instance). The HttpServletRequest and HttpServletResponse can be accessed via the AbstractRemoteServiceServlet.getThreadLocalRequest() and AbstractRemoteServiceServlet.getThreadLocalResponse() methods.

This is public so that it can be unit tested easily without HTTP.

In order to properly operate within Sling/OSGi, the classloader used by GWT has to be rerouted from Thread.currentThread().getContextClassLoader() to the classloader provided by the bundle.

Overrides:
processCall in class com.google.gwt.user.server.rpc.RemoteServiceServlet
Parameters:
payload - the UTF-8 request payload
Returns:
a string which encodes either the method's return, a checked exception thrown by the method, or an IncompatibleRemoteServiceException
Throws:
com.google.gwt.user.client.rpc.SerializationException - if we cannot serialize the response
com.google.gwt.user.server.rpc.UnexpectedException - if the invocation throws a checked exception that is not declared in the service method's signature
java.lang.RuntimeException - if the service method throws an unchecked exception (the exception will be the one thrown by the service)

doGetSerializationPolicy

protected com.google.gwt.user.server.rpc.SerializationPolicy doGetSerializationPolicy(javax.servlet.http.HttpServletRequest request,
                                                                                      java.lang.String moduleBaseURL,
                                                                                      java.lang.String strongName)
Gets the SerializationPolicy for given module base URL and strong name if there is one.

Override this method to provide a SerializationPolicy using an alternative approach.

This method has been overriden, so that the serialization policy can be properly loaded as a bundle entry, as Sling does not support ServletContext.getResourceAsStream().

Overrides:
doGetSerializationPolicy in class com.google.gwt.user.server.rpc.RemoteServiceServlet
Parameters:
request - the HTTP request being serviced
moduleBaseURL - as specified in the incoming payload
strongName - a strong name that uniquely identifies a serialization policy file
Returns:
a SerializationPolicy for the given module base URL and strong name, or null if there is none

setBundle

protected void setBundle(org.osgi.framework.Bundle bundle)
Allows the extending OSGi service to set the bundle it is part of. The bundle is used to provide access to the policy file otherwise loaded by getServletContext().getResourceAsStream() which is not supported in Sling.

Parameters:
bundle - The bundle to load the resource (policy file) from.

setClassLoader

protected void setClassLoader(java.lang.ClassLoader classLoader)
Allows the extending OSGi service to set its classloader.

Parameters:
classLoader - The classloader to provide to the SlingRemoteServiceServlet.


Copyright © 2007-2010 The Apache Software Foundation. All Rights Reserved.