Skip to content

Instantly share code, notes, and snippets.

@liweinan
Created May 6, 2012 13:58
Show Gist options
  • Save liweinan/2622424 to your computer and use it in GitHub Desktop.
Save liweinan/2622424 to your computer and use it in GitHub Desktop.
RESTEasy Code Reading
# Two different startup procedure
The one is to use ConfigurationBootstrap.
The other one is to use javax.ws.rs.Application as servlet name.
TODO: add more informations/code details on it.
# Startup Procedure
ResteasyBootstrap
-> creates
ListenerBootstrap extends org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap
-> calls
org.jboss.resteasy.spi.ResteasyDeployment
-> start() -> registration() -> processApplication()
createFromInjectorFactory:
net.bluedash.resteasy.BluedashResteasyApplication
*ResteasyDeployment.start() is important.*
-> init
HttpServletDispatcher
-> init
ServletContainerDispatcher
uses SynchronousDispatcher.java in its class;
SynchronousDispatcher uses ResourceInvoker to invoke resource
servletContainerDispatcher = new ServletContainerDispatcher();
ServletBootstrap bootstrap = new ServletBootstrap(servletConfig);
servletContainerDispatcher.init(servletConfig.getServletContext(), bootstrap, this, this);
servletContainerDispatcher.getDispatcher().getDefaultContextObjects().put(ServletConfig.class, servletConfig);
-> ResourceInvoker has two implementations:
ResourceLocator and ResourceMethod. ResourceLocator calls ResourceMethod.
----
When access the application first time, ServletContainerDispatcher begins to work:
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher
SEVERE: ***: providerFactory is not null
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher
SEVERE: ***: application: null
# Pending Issues
There must be some relationships between Dispatchers and ResteasyDeployment, so I should try to find it. In ResteasyDeployment it should setup the
# ResteasyProviderFactory
ResteasyProviderFactory stores all the information about runtime Providers in a project.
ResteasyProviderFactory is handled in ResteasyDeployment.
protected ResteasyProviderFactory providerFactory;
protected ThreadLocalResteasyProviderFactory threadLocalProviderFactory;
# ResteasyDeployment
After ResteasyDeployment start, the Resteasy Framework begins to work.
## public void start()
start() -> registration() -> processApplication()
## public void registration()
It register all providers
It added per request resource into registry.
## protected boolean processApplication(Application config)
It adds all the resources and providers into ResteasyDeployment itself.
processApplication is the very beginning startup step.
logger.info("Deploying " + Application.class.getName() + ": " + config.getClass());
# Registry
ResourceInvoker stores in Registry:
ResourceInvoker invoker = registry.getResourceInvoker(request);
# Bootstrap Classes
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ConfigurationBootstrap.java
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/FilterBootstrap.java
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ListenerBootstrap.java
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ResteasyBootstrap.java
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ServletBootstrap.java
ServletBootstrap, FilterBootstrap extends ListenerBootstrap
ListenerBootstrap extends ConfigurationBootstrap
ConfigurationBootstrap implements ResteasyConfiguration
ResteasyBootstrap implements javax.servlet.ServletContextListener
# ResteasyBootstrap
ResteasyBootstrap is the entry point of whole RESTEasy Framework.
It creates ListenerBootstrap, and using it to create deployment and then start the deployment.
ResteasyProviderFactory, Dispatcher, Registry from deployment are registered into ServletContext.
# Dispatchers
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/Dispatcher.java
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/AsynchronousDispatcher.java
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/SynchronousDispatcher.java
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/FilterDispatcher.java
public class FilterDispatcher implements Filter, HttpRequestFactory, HttpResponseFactory
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/HttpServletDispatcher.java
public class HttpServletDispatcher extends HttpServlet implements HttpRequestFactory, HttpResponseFactory - standard servlet interface.
enable FilterDispatcher and ServletContainerDispatcher.java
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ServletContainerDispatcher.java
Has no relationship with Dispatcher interface - Standalone class.
*Standard Dispatcher interface is used in ServletContainerDispatcher*
public class ServletContainerDispatcher
{
protected Dispatcher dispatcher;
}
./resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/InternalDispatcher.java
## invoke()
invoke() -> ResourceInvoker
pushContextObjects(request, response);
Response jaxrsResponse = getResponse(request, response, invoker);
writeJaxrsResponse(request, response, jaxrsResponse);
clearContextData();
## pushContextObjects()
Map contextDataMap = ResteasyProviderFactory.getContextDataMap();
## getResponse()
jaxrsResponse = invoker.invoke(request, response);
# ResourceInvoker
ResourceLocator and ResourceMethod.
## ResourceLocator
ResourceLocator calls ResourceMethod.
## ResourceMethod
Uses MethodInjectorImpl to call method.
# ServletContainerDispatcher
ServletContainerDispatcher has no relationship with Dispatcher interface.
# HttpRequestPreprocessor
HttpRequestPreprocessor -> ExtensionHttpPreprocessor
# ResourceInvoker
liweinan@cute:~/projs/Resteasy$ grep -rl 'implements ResourceInvoker' *
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceLocator.java
jaxrs/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethod.java
ResourceMethod uses MethodInjectorImpl to deal with method calling.
# MethodInjectorImpl
invoke() -> injectArguments() -> method.invoke()
uses ValueInjector in injectArguments
# ValueInjector
src/main/java/org/jboss/resteasy/core/ContextParameterInjector.java
src/main/java/org/jboss/resteasy/core/CookieParamInjector.java
src/main/java/org/jboss/resteasy/core/FormInjector.java
src/main/java/org/jboss/resteasy/core/FormParamInjector.java
src/main/java/org/jboss/resteasy/core/HeaderParamInjector.java
src/main/java/org/jboss/resteasy/core/MatrixParamInjector.java
src/main/java/org/jboss/resteasy/core/MessageBodyParameterInjector.java
src/main/java/org/jboss/resteasy/core/PathParamInjector.java
src/main/java/org/jboss/resteasy/core/QueryParamInjector.java
src/main/java/org/jboss/resteasy/core/SuspendInjector.java
protected ValueInjector[] params;
params = new ValueInjector[method.getParameterTypes().length];
params[i] = factory.getInjectorFactory().createParameterExtractor(root, method, type, genericType, annotations);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment