|
Generated by JDiff |
||||||||
PREV PACKAGE NEXT PACKAGE FRAMES NO FRAMES |
This file contains all the changes in documentation in the packagecom.google.inject.servlet
as colored differences. Deletions are shownlike this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.
Apply this filter in web.xml above all other filters (typically), to all requests where you planto use servlet scopes. This is also needed in order to dispatch requests to injectable filtersand servlets:<filter> <filter-name>guiceFilter</filter-name> <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> </filter> <filter-mapping> <filter-name>guiceFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>This filter must appear before every filter that makes use of Guice injection orservlet scopesservlet scopes functionality. Typically, you will only register this filter in web.xml andregisterregister anyotherother filters (and servlets) using a ServletModule. @author crazybob@google.com (Bob Lee) @author dhanji@gmail.com (Dhanji R. Prasanna)
As of Guice 2.0 you can still use (your subclasses of) {@code GuiceServletContextListener}Class GuiceServletContextListener, Injector getInjector()classclass as a logical place to create and configure your injector. This will ensure theinjectorinjectorisis created when the web application is deployed.@author Kevin Bourrillion (kevinb@google.com) @since 2.0
Override this method to create (or otherwise obtain a reference to)youryour injector.
A binding to a single instance of a filter.@author sameb@google.com @since 3.0
A binding to a single instance of a servlet.@author sameb@google.com @since 3.0
A linked binding to a filter.@author sameb@google.com @since 3.0
A linked binding to a servlet.@author sameb@google.com @since 3.0
Apply this to field or parameters of type {@code Map} when you want theHTTPHTTP request parameter map to be injected. @author crazybob@google.com (Bob Lee)
Opens up the request scope until the returned object is closed.Implementations shouldensureensure (e.g. by blocking) that multiplethreadsthreads cannot open the same request scope concurrently. Itisis allowable toopenopen the same request scope on the same thread, as long as open/close calls are correctly nested.
Annotates a GuiceFilter that provides scope functionality,butbut doesn't dispatch to ServletModule bound servlets or filters. @author iqshum@google.com (Isaac Shum) @since 4.0
Configures the servlet scopes and creates bindings for the servletClass ServletModule, void configureServlets()APIAPI objects so you caninjectinject the request, response, session, etc.
You should subclass this module to register servletsandand filters in the .configureServlets() method. @author crazybob@google.com (Bob Lee) @author dhanji@gmail.com (Dhanji R. Prasanna)
Class ServletModule, ServletContext getServletContext()Servlet Mapping EDSL
Part of the EDSL builder language for configuringservletsservlets and filters with guice-servlet. Think of this as an in-code replacement for web.xml.Filters and servlets are configuredherehere using simple java method calls. Here is atypicaltypical example of registering a filter whencreatingcreating your Guice injector:Guice.createInjector(..., new ServletModule() { {@literal @}Override protected void configureServlets() { serve("*.html").with(MyServlet.class) } }This registers a servlet (subclass of {@code HttpServlet}) called {@code MyServlet} to service any web pages ending in {@code .html}. You can also use a path-style syntax to register servlets:serve("/my/*").with(MyServlet.class)Every servlet (or filter) is required to be a singleton. If you cannot annotate the class directly, you should add a separate {@code bind(..).in(Singleton.class)} rule elsewhereininyouryour module. Mapping a servlet that is bound under any other scope is an error.
Dispatch Order
You are free to register as many servlets and filters as you like this way. Theywillwillbebe compared and dispatched in the order in which the filter methods are called:Guice.createInjector(..., new ServletModule() { {@literal @}Override protected void configureServlets() { filter("/*").through(MyFilter.class); filter("*.css").through(MyCssFilter.class); filter("*.jpg").through(new MyJpgFilter()); // etc.. serve("*.html").with(MyServlet.class); serve("/my/*").with(MyServlet.class); serve("*.jpg").with(new MyServlet()); // etc.. } }This will traverse down the list of rules in lexical order. For example, aurlurl "{@codecode /my/file.js}" (after it runs through the matching filters) willfirstfirst be compared againstthethe servlet mapping:serve("*.html").with(MyServlet.class);And failing that, it will descend to the next servlet mapping:serve("/my/*").with(MyServlet.class);Since this rule matches, Guice Servlet will dispatch to {@code MyServlet}.TheseThese twomappingmapping rules can also be written in more compact form using varargs syntax:serve("*.html", "/my/*").with(MyServlet.class);This way you can map several URI patterns to the same servlet. A similar syntaxis alsois also available for filter mappings.
Regular Expressions
You can also map servlets (or filters) to URIs using regular expressions:serveRegex("(.)*ajax(.)*").with(MyAjaxServlet.class)This will map any URI containing the text "ajax" in it to {@code MyAjaxServlet}. Such as:
- http://www.google.com/ajax.
htmlhtml- http://www.google.com/content/ajax/
indexindex- http://www.google.com/it/is_totally_
ajaxianajaxianInitialization Parameters
Servlets (and filters) allow you to pass in initparamsparams using the {@code} tag inin web.xml. You can similarly pass in parameterstoto Servlets and filters registeredinin Guice-servlet using a java.util.Map ofparameterparameter name/value pairs. For example,toto initialize {@code MyServlet} with twoparametersparameters ({@code name="Dhanji", site="google.com"})youyou could write:Map<String, String> params = new HashMap<String, String>(); params.put("name", "Dhanji"); params.put("site", "google.com"); ... serve("/*").with(MyServlet.class, params)
Binding Keys
You can also bind keys rather than classes. This lets youhidehide implementationswithwith package-local visbility and expose themusingusing only a Guice module and an annotation:... filter("/*").through(Key.get(Filter.class, Fave.class));Where {@code Filter.class} refers to the Servlet API interface and {@code Fave.class} is a custom binding annotation. Elsewhere (in one of your own modules) you can bindthisthis filter'ss implementation:bind(Filter.class).annotatedWith(Fave.class).to(MyFilterImpl.class);See com.google.inject.Binder for more information on binding syntax.
Multiple Modules
It is sometimes useful to capture servlet and filter mappings from multipledifferentdifferent modules. This is essential if you want to package and offer drop-in Guice pluginsthatthat provideservletservlet functionality.
Guice Servlet allows you to register several instances of {@code ServletModule} to your injector. The order in which these modules are installed determines the dispatchorder oforder of filters and the precedence order of servlets. For example, if you had two servlet modules, {@code RpcModule} and {@code WebServiceModule} and they each contained a filter thatmappedmappedtoto the same URI pattern, {@code "/*"}:
In {@code RpcModule}:filter("/*").through(RpcFilter.class);In {@code WebServiceModule}:filter("/*").through(WebServiceFilter.class);Then the order in which these filters are dispatched is determined by the order inwhich thewhich the modules are installed:install(new WebServiceModule()); install(new RpcModule());In the case shown above {@code WebServiceFilter} will run first.@since 2.0
This method only works if you are using the GuiceServletContextListenerto createto create your injector. Otherwise, it returns null.@return The current servlet context. @since 3.0
A binding created by ServletModule.@author sameb@google.com (Sam Berlin) @since 3.0
A visitor for the servlet extension.Class ServletModuleTargetVisitor, V visit(InstanceFilterBinding)If your BindingTargetVisitor implements this interface, bindings created by using ServletModule will be visited through this interface.
@since 3.0 @author sameb@google.com (Sam Berlin)
Visits a filter binding created by ServletModule.filterClass ServletModuleTargetVisitor, V visit(InstanceServletBinding)wherewhere FilterKeyBindingBuilder.through is called with a Filter.If multiple patterns were specified, this will be called multiple times.
Visits a servlet binding created by ServletModule.serve whereClass ServletModuleTargetVisitor, V visit(LinkedFilterBinding)ServletKeyBindingBuilder.with, is called with an HttpServlet.If multiple patterns were specified, this will be called multiple times.
Visits a filter binding created by ServletModule.filter,Class ServletModuleTargetVisitor, V visit(LinkedServletBinding)wherewhere FilterKeyBindingBuilder.through is called with a Class or Key.If multiple patterns were specified, this will be called multiple times.
Visits a servlet binding created by ServletModule.servewherewhere ServletKeyBindingBuilder.with, is called with a Class or Key.If multiple patterns were specified, this will be called multiple times.
Wraps the given callable in a contextual callable that "continues"Class ServletScopes, boolean isRequestScoped(Binding<?>)thethe HTTP request inanotheranother thread. This acts as a way oftransportingtransporting request context data from the requestprocessingprocessing thread to toworkerworker threads.
There are some limitations:
- Derived objects (i.e. anything marked @RequestScoped will not
bebe transported.- State changes to the HttpServletRequest after this method is
calledcalled will not be seen inthethe continued thread.- Only the HttpServletRequest, ServletContext and request
parameterparametermap are available inthethe continued thread. The response andsessionsessionare not available.The returned callable will throw a ScopingException when
calledcalled if the HTTPrequestrequest scope is still active on the current thread. @param callable code to be executed in another thread, which dependsonon the request scope. @param seedMap the initial set of scoped instances for Guice to seedthethe request scope with. ToToseed a key with null, use {@code null}asas the value. @return a callable that will invoke the given callable, making therequestrequest context available tocontextavailabletoit. @throws OutOfScopeException if this method is called from a non-requestrequest thread, or ifthethe request has completed.@since 3.0 @deprecated You probably want to use {@code transferRequest} instead
Returns true if {@code binding} is request-scoped. If the binding isClass ServletScopes, Callable<T> scopeRequest(Callable<T>, Map<Key<?>, Object>)aa linked key bindingandand belongs to an injector (i. e.itit was retrievedviavia Injector.getBinding()), then this method will also return true if the target binding is request-scoped. @since 4.0
Scopes the given callable inside a request scope. This is not theClass ServletScopes, RequestScoper scopeRequest(Map<Key<?>, Object>)samesame as the HTTPrequestrequest scope, but is used if no HTTP request scope isinin progress. In this way, keys can bescopedscoped as @RequestScoped andexistexist in non-HTTP requests (for example: RPC requests) as well as in HTTP request threads.The returned callable will throw a ScopingException when
calledcalled if there isaa request scope already active on the current thread. @param callable code to be executed which depends on the request scope.Typically in anotherTypicallyinanotherthread, but not necessarily so. @param seedMap the initial set of scoped instances for Guice to seedthethe request scope with. ToToseed a key with null, use {@code null}asas the value. @return a callable that when called will run inside the a requestscopescope that exposes thethatexposestheinstances in the {@code seedMap} as scoped keys. @since 3.0
Returns an object that will apply request scope to a block of code. ThisClass ServletScopes, RequestScoper transferRequest()isis not the same asthethe HTTP request scope, but is used if no HTTPrequestrequest scope is in progress. In this way, keyscancan be scoped as @RequestScopedandand exist in non-HTTP requests (for example: RPC requests) aswellwell as inHTTPHTTP request threads.The returned object will throw a ScopingException when
openedopened if there is arequestrequest scope already active on the current thread. @param seedMap the initial set of scoped instances for Guice to seedthethe request scope with. ToToseed a key with null, use {@code null}asas the value. @return an object that when opened will initiate the request scope @since 4.1
Returns an object that "transfers" the request to another thread. ThisClass ServletScopes, Callable<T> transferRequest(Callable<T>)actsacts as a wayofof transporting request context data from the current thread toaa future thread. Thetransferredtransferred scope is the one active for the threadthatthat calls this method. A later call to {@code open()} activates thetransferredtransferred the scope, including propagating any objects scoped at that time.As opposed to .continueRequest, this method propagates
allall existing scoped objects. The primary use case is in serverimplementationsimplementations where you can detach the requestprocessingprocessing thread while waiting for data,and reattach to a different thread to finish processing ataa later time.Because request-scoped objects are not typically thread-safe, it
isis important toavoidavoid applying the same request scope concurrently.TheThe returned Scoper will block on open untilthethe current thread hasreleasedreleased the request scope. @return an object that when opened will initiate the request scope @throws OutOfScopeException if this method is called from a non-requestrequest thread, or ifthethe request has completed. @since 4.1
Wraps the given callable in a contextual callable that "transfers"thethe request toanotheranother thread. This acts as a way oftransportingtransporting request context data from the current thread toaa future thread.As opposed to .continueRequest, this method propagates
allall existing scoped objects. The primary use case is in serverimplementationsimplementations where you can detach the requestprocessingprocessing thread while waiting for data,and reattach to a different thread to finish processing ataa later time.Because request-scoped objects are not typically thread-safe,
thethe callable returned bythisthis method must not be run on a differentthreadthread until the current request scope has terminated. The returned callablewillwill block until the current thread has released the request scope. @param callable code to be executed in another thread, which dependsonon the request scope. @return a callable that will invoke the given callable, making therequestrequest context available tocontextavailabletoit. @throws OutOfScopeException if this method is called from a non-requestrequest thread, or ifthethe request has completed. @since 4.0
An enumeration of the available URI-pattern matchingstylesstyles@since 3.0