public enum AvailableDependencies extends Enum<AvailableDependencies>
Inject
annotation on a type's constructor.Enum Constant and Description |
---|
CONFIGURATION
Provides a
Configuration instance appropriate for the backing store
that the current request is targetted to. |
CONNECTION
Provides a
Connection connected to the appropriate database pool
and schema, inferred from mapping the request URL. |
IO
Provides
IOStreams service for manipulating input and output
streams. |
JSON
Provides access to the
JSONStreams service, which can be used to
parse character streams into JSON (using JSONReader ) and to
generate JSON using JSONWriter . |
JSON_OBJECTS
Provides access to the
JSONObjects service, which can be used to
build in memory representations of JSON object graphs. |
LOCALE
Provides the most preferred
Locale for a request |
LOCALE_PREFERENCE
Provides a
LocalePreference instance, which enumerates the
preferred Locale s for a request from most to least preferred. |
LOG
Provides access to the the JDK
Logger service. |
PATH_TEMPLATES
Provides methods for working with
PathTemplateMatch instances |
Modifier and Type | Method and Description |
---|---|
Annotation[] |
constraints()
The Annotations that may constrain the scope of the dependency
|
Class<?> |
type()
The type of the dependency
|
static AvailableDependencies |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static AvailableDependencies[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final AvailableDependencies CONFIGURATION
Provides a Configuration
instance appropriate for the backing store
that the current request is targetted to. If this service is called from an
ApplicationScoped
service, then the global configuration is used.
@Provides @Dispatches(@PathTemplate("/some/service")) class SomeService extends HttpServlet { @Inject SomeService(Configuration conf) { this.conf = conf; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String setting = conf.get(SOME_CONFIG_SETTING); response.getWriter().println("The value of the setting is: " + setting); } private final Configuration conf; private final static String SOME_CONFIG_SETTING = "my.really.important.setting"; }
The above example retrieves the value of the setting and displays it in the response.
N.B. Care must be exercised when working with Configuration
instances to ensure that a vector to reveal sensitive configuration data is
not created. For example if the value of
my.really.important.setting
is sensitive, then printing it's
value in the response to a GET request is entirely inappropriate and
dangerous. Similarly any code that allows an attacker to control over
displaying of configuration data in the delivered response is dangerous.
public static final AvailableDependencies CONNECTION
Provides a Connection
connected to the appropriate database pool
and schema, inferred from mapping the request URL.
@Provides @Dispatches(@PathTemplate("/some/service")) class SomeService extends HttpServlet { @Inject SomeService(Connection conn) { this.conn = conn; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PreparedStatement ps = conn .prepareStatement("select sys_context('USERENV','CURRENT_USER') from dual"); ResultSet rs = ps.execute(); rs.next(); String user = rs.getString(1); response.getWriter().println("mapped database user is: " + user); rs.close(); ps.close(); } private final Connection conn; }
A Connection
can only be injected for request URLs where the
runtime has been able to the map the URL to a database pool and schema. If
the runtime was not able to map the URL to a database/schema, then it will
not attempt to dispatch a service that depends on Connection
, even
if it's URL pattern matches the request URL.
For example attempting to access the above service at:
http://localhost:8080/ords/some/service
Will result in a 404 Not Found
status because the URL does not
contain enough information to identify a database/schema to map to.
By contrast, the following URL:
http://localhost:8080/ords/test_schema/some/service
Will execute correctly assuming a schema named test_schema
exists in the default database pool
public static final AvailableDependencies IO
IOStreams
service for manipulating input and output
streams.public static final AvailableDependencies JSON
JSONStreams
service, which can be used to
parse character streams into JSON (using JSONReader
) and to
generate JSON using JSONWriter
.public static final AvailableDependencies JSON_OBJECTS
JSONObjects
service, which can be used to
build in memory representations of JSON object graphs.public static final AvailableDependencies LOCALE
Locale
for a requestpublic static final AvailableDependencies LOCALE_PREFERENCE
LocalePreference
instance, which enumerates the
preferred Locale
s for a request from most to least preferred.public static final AvailableDependencies LOG
Provides access to the the JDK Logger
service. All Logging must be
done through this service.
@Provides class SomeService { @Inject SomeService(Logger log) { this.log = log; } public void someMethod() { log.info("doing something"); } private final Logger log; }
public static final AvailableDependencies PATH_TEMPLATES
Provides methods for working with PathTemplateMatch
instances
@Provides class SomeService { @Inject SomeService(PathTemplates pathTemplates) { this.pathTemplates = pathTemplates; } private final PathTemplates pathTemplates; }
public static AvailableDependencies[] values()
for (AvailableDependencies c : AvailableDependencies.values()) System.out.println(c);
public static AvailableDependencies valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic Annotation[] constraints()
public Class<?> type()
Oracle REST Data Services Plugin API version: 3.0.0.65.09.35 Copyright © 2015 Oracle Corp. All Rights Reserved.