Java megazine : Writing was apps by Andrew Clarke & Suraj Sahu

Java megazine : Writing was apps by Andrew Clarke & Suraj Sahu

Author:Andrew Clarke & Suraj Sahu [Clarke , Andrew]
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2018-12-02T16:00:00+00:00

/airlines/coach /airlines/first /airlines/business

are all valid expansions of the URI template

/airlines/{service-class}

with variable service-class equal to coach, first, and business, respectively.

URI templates can be very useful in a WebSocket application, because the template variable values are available This would yield different levels of service, depending on which request URI a client connects with.

Accessing path information at runtime. An endpoint has full access to all of its path information at runtime. First, it can always obtain the path under which the WebSocket implementation has published it. Using the ServerEndpointConfig.getPath() call for the endpoint holds this information, which you can easily access wherever you can get hold of the ServerEndpointConfig instance, such as we see in Listing 2.

Listing 2. An endpoint accessing its own path mapping @ServerEndpoint("/travel/hotels/{stars}") public class HotelBookingService {

public void handleConnection{

Session s, EndpointConfig config) {

String myPath =

((ServerEndpointConfig) config).getPath(); // myPath is "/travel/hotels/{stars}" ...

}

} Two more methods on the Session object parse out further information from this request URI when the request URI includes a query string. So let’s take a look at query strings.

Query strings and request parameters. As we saw earlier, fol

lowing the URI path to a WebSocket endpoint is the optional query string <ws or wss>://<host:name>:<port:>/

<web-app-context-path>/<websocket-path>? <query-string>

This approach will work equally well for exact URImapped endpoints.

The second piece of information you may wish to access at runtime from within an endpoint is the URI with which the client to your endpoint connected. This information is available in a variety of forms, as we shall see later, but the workhorse method that contains all the information is the Query strings in URIs originally became popular in common gateway interface (CGI) applications. The path portion of a URI locates the CGI program (often /cgi-bin), and the query string appended after the URI path supplies a list of parameters to the CGI program to qualify the request. The query string is also commonly used when posting data using an HTML form. For example, in a web application, in the HTML code

Session.getRequestURI()

method. This gives you the URI path relative to the web server root of the WebSocket implementation. Notice that this includes the context root of the web application that the WebSocket is part of. So, in our hotel booking example, if it is deployed in a web application with context root /customer/services and a client has connected to the HotelBookingService endpoint with the URI

<form

name="input"

action="form-processor" method="get"> Your Username: <input type="text" name="user">

<input type="submit"

value="Submit">

</form>



Loading...
Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Web Analytics