2018-10-22 12:56:04 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.datatransfer.resolver.services.exceptions;
|
|
|
|
|
|
|
|
|
2018-10-22 15:39:51 +02:00
|
|
|
import java.net.URI;
|
|
|
|
|
2018-10-22 12:56:04 +02:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response.Status;
|
|
|
|
|
2018-10-22 14:17:16 +02:00
|
|
|
import org.gcube.datatransfer.resolver.services.error.ErrorReport;
|
|
|
|
import org.gcube.datatransfer.resolver.services.error.ExceptionReport;
|
2018-11-06 14:43:47 +01:00
|
|
|
import org.gcube.datatransfer.resolver.util.Util;
|
2018-10-22 12:56:04 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class BadParameterException.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
* Oct 22, 2018
|
|
|
|
*/
|
|
|
|
public class BadRequestException extends WebApplicationException {
|
|
|
|
|
2018-10-23 14:32:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-22 12:56:04 +02:00
|
|
|
*
|
|
|
|
*/
|
2018-10-23 14:32:37 +02:00
|
|
|
private static final long serialVersionUID = -6095255435634429757L;
|
2018-10-22 12:56:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new bad parameter exception.
|
|
|
|
*
|
|
|
|
* @param request the request
|
|
|
|
* @param httpReturnStatus the http return status
|
|
|
|
* @param message the message
|
2018-10-23 11:33:00 +02:00
|
|
|
* @param thrownBySource the thrown by source
|
|
|
|
* @param help the help
|
2018-10-22 12:56:04 +02:00
|
|
|
*/
|
2018-10-23 11:33:00 +02:00
|
|
|
public BadRequestException(HttpServletRequest request, Status httpReturnStatus, String message, Class thrownBySource, URI help) {
|
2018-10-22 15:39:51 +02:00
|
|
|
super(Response.status(httpReturnStatus).entity(
|
|
|
|
ExceptionReport.builder().
|
|
|
|
request(Util.getFullURL(request)).
|
|
|
|
method(request.getMethod()).
|
|
|
|
success(false).
|
|
|
|
help(help).
|
|
|
|
error(
|
|
|
|
ErrorReport.builder().
|
|
|
|
httpErrorCode(Status.BAD_REQUEST.getStatusCode()).
|
|
|
|
name(Status.BAD_REQUEST.name())
|
|
|
|
.message(message).
|
2018-10-23 11:33:00 +02:00
|
|
|
thrownBy(thrownBySource.getName()).build())
|
2018-10-22 15:39:51 +02:00
|
|
|
.build())
|
|
|
|
.type(MediaType.APPLICATION_XML).build());
|
2018-10-22 12:56:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|