Java tutorial
/* * LICENSE * * "THE BEER-WARE LICENSE" (Revision 43): * "Sven Strittmatter" <weltraumschaf@googlemail.com> wrote this file. * As long as you retain this notice you can do whatever you want with * this stuff. If we meet some day, and you think this stuff is worth it, * you can buy me a non alcohol-free beer in return. * * Copyright (C) 2012 "Sven Strittmatter" <weltraumschaf@googlemail.com> */ package de.weltraumschaf.maconha.server.errorhandling; import java.lang.reflect.InvocationTargetException; import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import org.apache.commons.beanutils.BeanUtils; @XmlRootElement public class ErrorMessage { /** * contains the same HTTP Status code returned by the server */ @XmlElement(name = "status") int status; /** * application specific error code */ @XmlElement(name = "code") int code; /** * message describing the error */ @XmlElement(name = "message") String message; /** * link point to page where the error message is documented */ @XmlElement(name = "link") String link; /** * extra information that might useful for developers */ @XmlElement(name = "developerMessage") String developerMessage; public ErrorMessage(final AppException ex) { this(); try { BeanUtils.copyProperties(this, ex); } catch (final IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public ErrorMessage(final NotFoundException ex) { this(); this.status = Response.Status.NOT_FOUND.getStatusCode(); this.message = ex.getMessage(); this.link = "https://jersey.java.net/apidocs/2.8/jersey/javax/ws/rs/NotFoundException.html"; } public ErrorMessage() { super(); } public int getStatus() { return status; } public void setStatus(final int status) { this.status = status; } public int getCode() { return code; } public void setCode(final int code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getDeveloperMessage() { return developerMessage; } public void setDeveloperMessage(final String developerMessage) { this.developerMessage = developerMessage; } public String getLink() { return link; } public void setLink(final String link) { this.link = link; } }