Java Reference
In-Depth Information
the String in the URL to the data type of the parameter on the method. Only String
and primitive types are supported. A failure to convert or an invalid parameter type will
result in a DecodeException being thrown and passed to the method annotated with
the @OnError annotation.
To better understand this annotation, let's consider how it's used in ActionBazaar. Because
CSRs may access ActionBazaar from a multitude of clients, you need to know the type
of client when a connection is opened. ActionBazaar makes the distinction between the
following types of clients: desktop, mobile-web, and mobile-native. These client types are
specific to ActionBazaar and are used by the application code to provide specialized mes-
sages for the different clients. The code is shown in the following listing.
Listing 14.15. Using path variables
In this listing the variable clientType in the URI is mapped to a parameter in
the onOpen method . A native iPad ActionBazaar application, written in Objective-
C, will thus construct the following URL: http://<address>:<port>/chapter14/admin/bullet-
in/mobile-native . The mobile-native portion of the URL will be passed into the onOpen
method, where you can handle it and tailor subsequent responses.
@OnOpen
The @OnOpen annotation marks a method on the endpoint that will be called when the
connection is first opened. This annotation is defined as follows:
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.METHOD})
public @interface OnOpen {}
Search WWH ::




Custom Search