Menu
Amazon AppStream
Developer Guide

This documentation is for an older version of Amazon AppStream. For information about the latest version, see the Amazon AppStream 2.0 Developer Guide.

Returning an Entitlement URL to the Client

The following excerpt from /rs/JaxRsEntitlementService.java uses JAX-RS, a Java API for interacting with REST-ful web services. It processes incoming HTTP requests from clients to establish a connection to an application. If the client is entitled to access the application, this method returns an entitlement URL that the client can use to connect to the application. If the request is denied, it returns an error.

The logic exposed by this function is the entitlement service in a nutshell.

Copy
@POST @Path("/{applicationId}") @Produces(MediaType.TEXT_PLAIN) public Response requestEntitlement(@HeaderParam("Authorization") String authorization, @PathParam("applicationId") String applicationId, @FormParam("terminatePrevious") @DefaultValue("false") Boolean terminatePrevious) { try { User user = entitlementService.getUserFromAuthorization(authorization); Application application = entitlementService.getApplication(applicationId); if (!entitlementService.shouldAlwaysEntitle()) { entitlementService.checkIfEntitled(user, application); } if (checkPreviousSession) { entitlementService.checkForPreviousSession(user, application, terminatePrevious); } Session session = entitlementService.entitleSession(user, application); return response(Status.CREATED, session.getEntitlementUrl()); } catch (AuthorizationException e) { String authenticateHeader = e.getAuthenticateHeader(); if (authenticateHeader == null) { return response(Status.UNAUTHORIZED, e.getMessage()); } else { return response(Status.UNAUTHORIZED, e.getMessage(), Collections.singletonMap("WWW-Authenticate", authenticateHeader)); } } catch (UserNotEntitledException e) { return response(Status.FORBIDDEN, e.getMessage()); } catch (ApplicationNotFoundException e) { return response(Status.NOT_FOUND, e.getMessage()); } catch (SessionActiveException e) { return response(Status.CONFLICT, e.getMessage()); } }