|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AbstractRequestHandler | Line # 38 | 6 | 0% | 2 | 3 | 57.1% |
0.5714286
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (5) | |||
| Result | |||
|
0.5714286
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
|
1 PASS | |
|
0.5714286
|
net.sf.arestc.core.OverallDesignTest.testRepositoryCreate
net.sf.arestc.core.OverallDesignTest.testRepositoryCreate
|
1 PASS | |
|
0.5714286
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
|
1 PASS | |
|
0.5714286
|
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
|
1 PASS | |
|
0.5714286
|
net.sf.arestc.core.OverallDesignTest.testRepositoryMultiPost
net.sf.arestc.core.OverallDesignTest.testRepositoryMultiPost
|
1 PASS | |
| 1 | /* | |
| 2 | * | |
| 3 | * (C)opyright 2010, Nikolaos Georgosopoulos | |
| 4 | * | |
| 5 | * This file is part of ARESTC. | |
| 6 | * | |
| 7 | * ARESTC is free software: you can redistribute it and/or modify it under the | |
| 8 | * terms of the Lesser General Public License as published by the Free Software | |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later | |
| 10 | * version. | |
| 11 | * | |
| 12 | * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | |
| 14 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the Lesser General Public License along | |
| 17 | * with ARESTC. If not, see <http://www.gnu.org/licenses/>. | |
| 18 | */ | |
| 19 | package net.sf.arestc.testserver; | |
| 20 | ||
| 21 | import java.io.IOException; | |
| 22 | import java.io.InputStream; | |
| 23 | ||
| 24 | import org.apache.commons.io.IOUtils; | |
| 25 | import org.apache.http.HttpException; | |
| 26 | import org.apache.http.HttpRequest; | |
| 27 | import org.apache.http.HttpResponse; | |
| 28 | import org.apache.http.HttpStatus; | |
| 29 | import org.apache.http.entity.StringEntity; | |
| 30 | import org.apache.http.protocol.HttpContext; | |
| 31 | import org.apache.http.protocol.HttpRequestHandler; | |
| 32 | import org.apache.log4j.Logger; | |
| 33 | ||
| 34 | // TODO: Auto-generated Javadoc | |
| 35 | /** | |
| 36 | * The Class AbstractRequestHandler. | |
| 37 | */ | |
| 38 | public abstract class AbstractRequestHandler implements HttpRequestHandler { | |
| 39 | ||
| 40 | /** The Constant LOGGER. */ | |
| 41 | private static final Logger LOGGER = Logger.getLogger(AbstractRequestHandler.class | |
| 42 | .getName()); | |
| 43 | ||
| 44 | /** | |
| 45 | * Adds the file as body. | |
| 46 | * | |
| 47 | * @param response the response | |
| 48 | * @param file the file | |
| 49 | */ | |
| 50 | 7 |
protected void addFileAsBody(final HttpResponse response, final String file) { |
| 51 | 7 | try { |
| 52 | 7 | final InputStream is = this.getClass().getClassLoader() |
| 53 | .getResourceAsStream(file); | |
| 54 | 7 | response.setEntity(new StringEntity(IOUtils.toString(is))); |
| 55 | } catch (final Exception e) { | |
| 56 | 0 | LOGGER.debug(e); |
| 57 | 0 | response.setStatusCode(HttpStatus.SC_NOT_FOUND); |
| 58 | 0 | throw new RuntimeException(e); |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | /* (non-Javadoc) | |
| 63 | * @see org.apache.http.protocol.HttpRequestHandler#handle(org.apache.http.HttpRequest, org.apache.http.HttpResponse, org.apache.http.protocol.HttpContext) | |
| 64 | */ | |
| 65 | public abstract void handle(HttpRequest arg0, HttpResponse arg1, | |
| 66 | HttpContext arg2) throws HttpException, IOException; | |
| 67 | } | |
|
||||||||||||