Java tutorial
package org.openmrs.module.hl7query.web.controller; /** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ import org.openmrs.api.context.Context; import org.openmrs.module.hl7query.AuthenticationErrorObject; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.context.request.WebRequest; /** * Controller that lets a client check the status of their session, and log out. (Authenticating is handled through a filter, and may happen through this or * any other resource. */ @Controller @RequestMapping(value = "/module/hl7query/session") public class Hl7QuerySessionController extends BaseHL7QueryController { /** * Tells the user their sessionId, and whether or not they are authenticated. * * @param request * @return * @should return the session id if the user is authenticated * @should return the session id if the user is not authenticated */ @RequestMapping(method = RequestMethod.GET) @ResponseBody public Object get(WebRequest request) { return new AuthenticationErrorObject().add("sessionId", request.getSessionId()).add("authenticated", Context.isAuthenticated()); } /** * Logs the client out * @should log the client out */ @RequestMapping(method = RequestMethod.DELETE) @ResponseBody @ResponseStatus(value = HttpStatus.NO_CONTENT) public void delete() { Context.logout(); } }