001/** 002 * Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/ 003 * 004 * This file is part of Dicoogle/dicoogle. 005 * 006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Dicoogle/dicoogle is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Dicoogle. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020package pt.ua.dicoogle.server.web.rest; 021 022import org.restlet.data.Parameter; 023import org.restlet.data.Status; 024import org.restlet.resource.Delete; 025import org.restlet.resource.Get; 026import org.restlet.resource.Post; 027import org.restlet.resource.Put; 028import org.restlet.resource.ResourceException; 029import org.restlet.resource.ServerResource; 030 031/** 032 * 033 * @author Eduardo Pinho <eduardopinho@ua.pt> 034 */ 035public class TestResource extends ServerResource { 036 private String something; 037 private boolean really; 038 039 protected boolean getQSBoolean(String name) { 040 Parameter param = getRequest().getResourceRef().getQueryAsForm().getFirst(name); 041 return param != null && (param.getValue() == null || param.getValue().equalsIgnoreCase("true")); 042 } 043 044 @Override 045 public void doInit() { 046 super.doInit(); 047 something = (String) getRequest().getAttributes().get("something"); 048 really = getQSBoolean("really"); 049 } 050 051 @Get("txt") 052 public String testGet() { 053 return (really ? "REALLY " : "") + something + " GET"; 054 } 055 056 @Post("txt:txt") 057 public String testPost(String data) { 058 if (something == null || something.isEmpty()) { 059 throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); 060 } 061 return (really ? "REALLY " : "") + something + " POST: " + data; 062 } 063 064 @Put("txt") 065 public String testPut() { 066 return (really ? "REALLY " : "") + something + " PUT"; 067 } 068 069 @Delete("txt") 070 public String testDelete() { 071 return (really ? "REALLY " : "") + something + " DELETE"; 072 } 073 074}