public class ERXRouteRequestHandler
extends com.webobjects.appserver._private.WODirectActionRequestHandler
ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(); routeRequestHandler.addDefaultRoutes(Person.ENTITY_NAME); ERXRouteRequestHandler.register(routeRequestHandler);or
ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(); routeRequestHandler.addRoute(new ERXRoute("/people/{action}", PeopleController.class)); routeRequestHandler.addRoute(new ERXRoute("/person/{person:Person}", PeopleController.class, "show")); ... ERXRouteRequestHandler.register(routeRequestHandler);Note that addDefaultRoutes sets up many routes automatically (not just the 2 that are shown above), and for most cases should be your starting point for adding new entities rather than manually adding them. in PeopleController:
public class PeopleController extends ERXRouteController { public PeopleController(WORequest request) { super(request); } public Person person() { Person person = (Person) routeObjectForKey("person"); return person; } public ERXKeyFilter showFilter() { ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes(); filter.include(Person.COMPANY).includeAttributes(); return filter; } public ERXKeyFilter updateFilter() { ERXKeyFilter filter = ERXKeyFilter.filterWithAttributes(); filter.include(Person.COMPANY); return filter; } public WOActionResults createAction() { Person person = (Person) create(Person.ENTITY_NAME, updateFilter()); editingContext().saveChanges(); return response(person, showFilter()); } public WOActionResults updateAction() { Person person = person(); update(person, updateFilter()); editingContext().saveChanges(); return response(person, showFilter()); } public WOActionResults showAction() { return response(person(), showFilter()); } public WOActionResults indexAction() { NSArray<Person> people = Person.fetchPersons(editingContext(), null, Person.LAST_NAME.asc().then(Person.FIRST_NAME.asc())); return response(editingContext(), Person.ENTITY_NAME, people, showFilter()); } }in browser:
http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.xml http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.json http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/people.plist http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100.json http://localhost/cgi-bin/WebObjects/YourApp.woa/ra/person/100/edit.json
Name | Description |
---|---|
ERXRest.missingControllerName | (default "ERXMissingRouteController") Allow you to specify which controller to use when a route doesn't exist |
ERXRest.parseUnknownExtensions | (default "true") If set to "false", will return a 404 status code if the format doesn't exist |
ERXRest.pluralEntityNames | ERXRest.pluralEntityNames |
ERXRest.routeCase | ERXRest.routeCase |
ERXRest.lowercaseEntityNames | ERXRest.lowercaseEntityNames |
Modifier and Type | Class and Description |
---|---|
static class |
ERXRouteRequestHandler.NameFormat
NameFormat specifies how routes and controller names should be capitalized by default.
|
Modifier and Type | Field and Description |
---|---|
static ERXRouteRequestHandler.NameFormat |
EMBER |
static String |
ExtensionKey |
static String |
Key |
static String |
KeysKey |
static String |
PathKey |
static ERXRouteRequestHandler.NameFormat |
RAILS
A NameFormat that behaves like Rails -- plural entities, plural routes, lowercase underscore names
(names_like_this).
|
static String |
RouteKey |
static String |
TypeKey |
static ERXRouteRequestHandler.NameFormat |
WO
A NameFormat that behaves like WO -- singular entities, singular routes, camel names (NamesLikeThis).
|
static ERXRouteRequestHandler.NameFormat |
WO_LOWER
A NameFormat that behaves like WO -- singular entities, singular routes, lowercase camel names (namesLikeThis).
|
Constructor and Description |
---|
ERXRouteRequestHandler()
Constructs a new ERXRouteRequestHandler with the default entity name format.
|
ERXRouteRequestHandler(ERXRouteRequestHandler.NameFormat entityNameFormat)
Constructs a new ERXRouteRequestHandler.
|
Modifier and Type | Method and Description |
---|---|
void |
_clearCaches()
Clears any caches that may exist on ERXRoutes (probably only useful to JRebel, to clear the route parameter method cache).
|
void |
_putComponentsToSleepInContext(com.webobjects.appserver.WOContext wocontext) |
protected void |
addDeclaredRoutes(String entityName,
Class<? extends ERXRouteController> routeControllerClass,
boolean addDefaultRoutesIfNoDeclaredRoutesFound) |
void |
addDefaultRoutes(String entityName)
Adds default routes and maps them to a controller named "[plural entity name]Controller".
|
void |
addDefaultRoutes(String entityName,
boolean numericPKs,
Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity.
|
void |
addDefaultRoutes(String entityName,
Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity.
|
void |
addDefaultRoutes(String entityName,
String entityType,
boolean numericPKs,
Class<? extends ERXRouteController> controllerClass)
Adds list and view routes for the given entity.
|
void |
addRoute(ERXRoute route)
Adds a new route to this request handler.
|
void |
addRoutes(Class<? extends ERXRouteController> routeControllerClass)
This method looks for all methods annotated with @Path or @Paths annotations and adds the corresponding routes.
|
void |
addRoutes(String entityName)
Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the route controller for the given entity
name, giving it the opportunity to add routes for this entity.
|
void |
addRoutes(String entityName,
Class<? extends ERXRouteController> routeControllerClass)
Calls the static method 'addRoutes(entityName, routeRequetHandler)' on the given route controller class, giving
it the opportunity to add routes for the given entity.
|
<T extends ERXRouteController> |
controller(Class<T> controllerClass,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance (with no request specified).
|
<T extends ERXRouteController> |
controller(Class<T> controllerClass,
com.webobjects.appserver.WORequest request,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance.
|
<T extends ERXRouteController> |
controller(String entityName,
com.webobjects.appserver.WORequest request,
com.webobjects.appserver.WOContext context)
Returns the corresponding controller instance.
|
String |
controllerPathForEntityNamed(String entityName)
Return the controller path name for an entity name based on the entity name format.
|
com.webobjects.appserver.WOAction |
getActionInstance(Class class1,
Class[] aclass,
Object[] aobj) |
Object[] |
getRequestActionClassAndNameForPath(NSArray requestHandlerPath) |
NSArray<String> |
getRequestHandlerPathForRequest(com.webobjects.appserver.WORequest request) |
void |
insertRoute(ERXRoute route)
Inserts a route at the beginning of the route list.
|
static void |
register(ERXRouteRequestHandler requestHandler)
Registers an ERXRestRequestHandler with the WOApplication for the handler key "rest".
|
void |
removeRoute(ERXRoute route)
Removes the given route from this request handler.
|
Class<? extends ERXRouteController> |
routeControllerClassForEntityNamed(String entityName)
Returns the default route controller class for the given entity name.
|
ERXRoute |
routeForMethodAndPath(String method,
String path,
NSMutableDictionary<String,Object> userInfo)
Returns the route that matches the request method and path, storing metadata about the route in the given
userInfo dictionary.
|
protected ERXRoute |
routeForMethodAndPattern(ERXRoute.Method method,
String urlPattern) |
NSArray<ERXRoute> |
routes()
Returns the routes for this request handler.
|
NSArray<ERXRoute> |
routesForControllerClass(Class<? extends ERXRouteController> routeController)
Returns the routes for the given controller class.
|
ERXRoute |
setupRequestWithRouteForMethodAndPath(com.webobjects.appserver.WORequest request,
String method,
String path)
Sets up the request userInfo for the given request for a request of the given method and path.
|
void |
setupRouteControllerFromUserInfo(ERXRouteController controller,
NSDictionary<String,Object> userInfo)
Sets up a route controller based on a request userInfo that came from routeForMethodAndPath.
|
protected void |
verifyRoute(ERXRoute route)
Checks for an existing route that matches the
ERXRoute.Method and ERXRoute.routePattern() of route and
yet has a different controller or action mapping. |
allowsContentInputStream, defaultActionClassName, generateErrorResponse, generateRequestRefusal, handler, nullResponse, registerDidHandleActionRequestWithActionNamed, registerWillHandleActionRequest, setAllowsContentInputStream
public static ERXRouteRequestHandler.NameFormat RAILS
public static ERXRouteRequestHandler.NameFormat WO
public static ERXRouteRequestHandler.NameFormat WO_LOWER
public static ERXRouteRequestHandler.NameFormat EMBER
public static final String Key
public static final String TypeKey
public static final String ExtensionKey
public static final String PathKey
public static final String RouteKey
public static final String KeysKey
public ERXRouteRequestHandler()
public ERXRouteRequestHandler(ERXRouteRequestHandler.NameFormat entityNameFormat)
entityNameFormat
- the format to use for entity names in URLspublic void insertRoute(ERXRoute route)
route
- the route to insertpublic void addRoute(ERXRoute route)
route
- the route to addpublic void removeRoute(ERXRoute route)
route
- the route to removepublic void _clearCaches()
public NSArray<ERXRoute> routes()
public NSArray<ERXRoute> routesForControllerClass(Class<? extends ERXRouteController> routeController)
routeController
- the controller classpublic Class<? extends ERXRouteController> routeControllerClassForEntityNamed(String entityName)
entityName
- the name of the entitypublic void addRoutes(String entityName)
entityName
- the name of the entitypublic void addRoutes(String entityName, Class<? extends ERXRouteController> routeControllerClass)
entityName
- the name of the entityrouteControllerClass
- the name of the route controllerpublic void addRoutes(Class<? extends ERXRouteController> routeControllerClass)
routeControllerClass
- the name of the route controllerprotected void addDeclaredRoutes(String entityName, Class<? extends ERXRouteController> routeControllerClass, boolean addDefaultRoutesIfNoDeclaredRoutesFound)
public void addDefaultRoutes(String entityName)
entityName
- the name of the entity to create routes forpublic void addDefaultRoutes(String entityName, Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withcontrollerClass
- the controller classpublic String controllerPathForEntityNamed(String entityName)
entityName
- the entity namepublic void addDefaultRoutes(String entityName, boolean numericPKs, Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withnumericPKs
- if true, routes can assume numeric PK's and add some extra convenience routescontrollerClass
- the controller classpublic void addDefaultRoutes(String entityName, String entityType, boolean numericPKs, Class<? extends ERXRouteController> controllerClass)
/reminders /reminders/{action} /reminder/{reminder:Reminder} /reminder/{reminder:Reminder}/{action}
entityName
- the entity name to route withentityType
- the type of the enitynumericPKs
- if true, routes can assume numeric PK's and add some extra convenience routescontrollerClass
- the controller classpublic ERXRoute routeForMethodAndPath(String method, String path, NSMutableDictionary<String,Object> userInfo)
method
- the request methodpath
- the request pathuserInfo
- a mutable userInfoprotected ERXRoute routeForMethodAndPattern(ERXRoute.Method method, String urlPattern)
method
- the request methodurlPattern
- method
and pattern
.protected void verifyRoute(ERXRoute route)
ERXRoute.Method
and ERXRoute.routePattern()
of route
and
yet has a different controller or action mapping.route
- public ERXRoute setupRequestWithRouteForMethodAndPath(com.webobjects.appserver.WORequest request, String method, String path)
request
- the request to configure the userInfo onmethod
- the request methodpath
- the request pathpublic void setupRouteControllerFromUserInfo(ERXRouteController controller, NSDictionary<String,Object> userInfo)
controller
- the controller to setupuserInfo
- the request userInfopublic NSArray<String> getRequestHandlerPathForRequest(com.webobjects.appserver.WORequest request)
getRequestHandlerPathForRequest
in class com.webobjects.appserver._private.WODirectActionRequestHandler
public Object[] getRequestActionClassAndNameForPath(NSArray requestHandlerPath)
getRequestActionClassAndNameForPath
in class com.webobjects.appserver._private.WOActionRequestHandler
public com.webobjects.appserver.WOAction getActionInstance(Class class1, Class[] aclass, Object[] aobj)
getActionInstance
in class com.webobjects.appserver._private.WOActionRequestHandler
public <T extends ERXRouteController> T controller(String entityName, com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context)
T
- the type of controller to returnentityName
- the entity name of the controller to lookuprequest
- the current requestcontext
- the current contextpublic <T extends ERXRouteController> T controller(Class<T> controllerClass, com.webobjects.appserver.WOContext context)
T
- the type of controller to returncontrollerClass
- the controller class to lookupcontext
- the current contextpublic <T extends ERXRouteController> T controller(Class<T> controllerClass, com.webobjects.appserver.WORequest request, com.webobjects.appserver.WOContext context)
T
- the type of controller to returncontrollerClass
- the controller class to lookuprequest
- the current requestcontext
- the current contextpublic void _putComponentsToSleepInContext(com.webobjects.appserver.WOContext wocontext)
_putComponentsToSleepInContext
in class com.webobjects.appserver._private.WOActionRequestHandler
public static void register(ERXRouteRequestHandler requestHandler)
requestHandler
- the rest request handler to registerCopyright © 2002 – 2020 Project Wonder.