Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 52 web apps 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 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 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 ws fun org customer services travel hotels 3 then the request URI the endpoint receives by calling getRequestURI is customer services travel hotels 3 Two more methods on the Session object parse out further information from this request URI when the request URI includes a query string So lets take a look at query strings Query strings and request parameters As we saw earlier following 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 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 form name input action form processor method get Your Username input type text name user input type submit value Submit form clicking the Submit button produces an HTTP request to the URI form processor user Jared relative to the page holding the HTML code and where the input field contains the text Jared Depending on the nature of the web resource located at the URI path form processor the query string user Jared can be used to determine what kind of response should be made
You must have JavaScript enabled to view digital editions.