This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream glassfish { | |
server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5; | |
} | |
server { | |
listen 80; | |
server_name servername.tdl; | |
return 301 https://$host$request_uri; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'java' | |
apply plugin: 'findbugs' | |
apply plugin: 'checkstyle' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("questions/") | |
public class QuestionResource { | |
@GET | |
@Path("{id}") | |
@Produces("application/json") | |
Response getQuestion(@PathParam("id") String questionId) { | |
QuestionDto question = questionService.getQuestionById(questionId); | |
if (question == null) | |
throw new ApiException(404, "Question not found", "Make sure the Id is valid and a question has been created"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("questions/") | |
public class QuestionResource { | |
@GET | |
@Path("{id}") | |
@Produces("application/json") | |
Response getQuestion(@PathParam("id") String questionId) { | |
QuestionDto question = questionService.getQuestionById(questionId); | |
if (question == null) { | |
return Response.status(NOT_FOUND).build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("questions/") | |
public class QuestionResource { | |
@GET | |
@Path("{id}") | |
@Produces("application/json") | |
Response getQuestion(@PathParam("id") String questionId) { | |
QuestionDto question = questionService.getQuestionById(questionId); | |
return Response.status(OK).entity(question).build(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// .... imports ommited for brevity | |
public class ErrorEntity implements Serializable { | |
int status; // contains the same HTTP Status code returned by the server | |
String message; // message describing the error | |
String developerMessage; // extra information that might useful for developers | |
public ErrorEntity(int status, Exception ex) { | |
StringWriter errorStackTrace = new StringWriter(); | |
ex.printStackTrace(new PrintWriter(errorStackTrace)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Provider | |
public class ApiExceptionMapper implements ExceptionMapper<ApiException> { | |
@Override | |
public Response toResponse(ApiException ex) { | |
ErrorEntity error = new ErrorEntity(); | |
error.setStatus(ex.getStatus()); | |
error.setMessage(ex.getMessage()); | |
error.setDeveloperMessage(ex.getMessage()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApiException extends RuntimeException { | |
private static final long serialVersionUID = 1L; | |
/** | |
* contains redundantly the HTTP status of the response sent back to the | |
* client in case of error, so that the developer does | |
* not have to look into the response headers. | |
*/ | |
private int status; | |
private String developerMessage; //detailed error description for developers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE module PUBLIC | |
"-//Puppy Crawl//DTD Check Configuration 1.3//EN" | |
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> | |
<!-- This is a checkstyle configuration file. For descriptions of | |
what the following rules do, please see the checkstyle configuration | |
page at http://checkstyle.sourceforge.net/config.html --> | |
<module name="Checker"> |