/** * Creates a new session for the given user with the given password. * * @throws ApiException If database error occurs, password is incorrect, or some other known error * occurs. * @param username The username of the person logging in. This param is part of the URL but is * ignored. Actual username comes in via Json. * @param jsonBody The Json request. * @return 201 CREATED upon completion. */ @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public Response createSession(@PathParam("username") String username, String jsonBody) throws ApiException { CreateUserSessionRequest request = new CreateUserSessionRequest(); request.deserializeFrom(jsonBody); SQLConnection sql = SQLConnection.connectDefault(); UserSession session = null; try { session = UserSession.start(sql, request.user, request.pass); } finally { sql.close(); } URI newUri = uriInfo.getRequestUriBuilder().path(session.getSessionId().toString()).build(); UserSessionResponse response = session.toResponse(ApiStatus.CREATED); return Response.created(newUri).entity(response.serialize()).build(); }