Skip to content

Commit

Permalink
Replace JAX-RS with servlet status code in PKIExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fmarco76 committed Aug 19, 2024
1 parent cd070b8 commit a90cae0
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.base;
import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class BadRequestException extends PKIException {

private static final long serialVersionUID = -4784839378360933483L;

public BadRequestException(String message) {
super(Response.Status.BAD_REQUEST, message);
super(HttpServletResponse.SC_BAD_REQUEST, message);
}

public BadRequestException(String message, Throwable cause) {
super(Response.Status.BAD_REQUEST, message, cause);
super(HttpServletResponse.SC_BAD_REQUEST, message, cause);
}

public BadRequestException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class ConflictingOperationException extends PKIException {

private static final long serialVersionUID = -5780172673428115193L;

public ConflictingOperationException(String message) {
super(Response.Status.CONFLICT, message);
super(HttpServletResponse.SC_CONFLICT, message);
}

public ConflictingOperationException(String message, Throwable cause) {
super(Response.Status.CONFLICT, message, cause);
super(HttpServletResponse.SC_CONFLICT, message, cause);
}

public ConflictingOperationException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class ForbiddenException extends PKIException {
private static final long serialVersionUID = 3199015969025638546L;

public ForbiddenException(String message) {
super(Response.Status.FORBIDDEN, message);
super(HttpServletResponse.SC_FORBIDDEN, message);
}

public ForbiddenException(String message, Throwable cause) {
super(Response.Status.FORBIDDEN, message, cause);
super(HttpServletResponse.SC_FORBIDDEN, message, cause);
}

public ForbiddenException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class HTTPGoneException extends PKIException {

private static final long serialVersionUID = 1256191208802745690L;

public HTTPGoneException(String message) {
super(Response.Status.GONE, message);
super(HttpServletResponse.SC_GONE, message);
}

public HTTPGoneException(String message, Throwable cause) {
super(Response.Status.GONE, message, cause);
super(HttpServletResponse.SC_GONE, message, cause);
}

public HTTPGoneException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.io.StringReader;
import java.io.StringWriter;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -52,32 +52,20 @@ public PKIException(int code, String message, Throwable cause) {
this.code = code;
}

public PKIException(Response.Status status) {
this(status, status.getReasonPhrase(), null);
}

public PKIException(String message) {
this(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message, null);
this(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message, null);
}

public PKIException(int code, String message) {
this(code, message, null);
}

public PKIException(Response.Status status, String message) {
this(status.getStatusCode(), message, null);
}

public PKIException(Throwable cause) {
this(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), cause.getMessage(), cause);
this(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, cause.getMessage(), cause);
}

public PKIException(String message, Throwable cause) {
this(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message, cause);
}

public PKIException(Response.Status status, String message, Throwable cause) {
this(status.getStatusCode(), message, cause);
this(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message, cause);
}

public PKIException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

/**
* @author Marco Fargetta {@literal <[email protected]>}
Expand All @@ -15,11 +15,11 @@ public class RequestNotAcceptable extends PKIException {
private static final long serialVersionUID = 1L;

public RequestNotAcceptable(String message) {
super(Response.Status.NOT_ACCEPTABLE, message);
super(HttpServletResponse.SC_NOT_ACCEPTABLE, message);
}

public RequestNotAcceptable(String message, Throwable cause) {
super(Response.Status.NOT_ACCEPTABLE, message, cause);
super(HttpServletResponse.SC_NOT_ACCEPTABLE, message, cause);
}

public RequestNotAcceptable(Data data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class ResourceNotFoundException extends PKIException {

private static final long serialVersionUID = 2283994502912462263L;

public ResourceNotFoundException(String message) {
super(Response.Status.NOT_FOUND, message);
super(HttpServletResponse.SC_NOT_FOUND, message);
}

public ResourceNotFoundException(String message, Throwable cause) {
super(Response.Status.NOT_FOUND, message, cause);
super(HttpServletResponse.SC_NOT_FOUND, message, cause);
}

public ResourceNotFoundException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

public class ServiceUnavailableException extends PKIException {

private static final long serialVersionUID = -9160776882517621347L;

public ServiceUnavailableException(String message) {
super(Response.Status.SERVICE_UNAVAILABLE, message);
super(HttpServletResponse.SC_SERVICE_UNAVAILABLE, message);
}

public ServiceUnavailableException(String message, Throwable cause) {
super(Response.Status.SERVICE_UNAVAILABLE, message, cause);
super(HttpServletResponse.SC_SERVICE_UNAVAILABLE, message, cause);
}

public ServiceUnavailableException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;


/**
Expand All @@ -29,11 +29,11 @@ public class UnauthorizedException extends PKIException {
private static final long serialVersionUID = -2025082875126996556L;

public UnauthorizedException(String message) {
super(Response.Status.UNAUTHORIZED, message);
super(HttpServletResponse.SC_UNAUTHORIZED, message);
}

public UnauthorizedException(String message, Throwable cause) {
super(Response.Status.UNAUTHORIZED, message, cause);
super(HttpServletResponse.SC_UNAUTHORIZED, message, cause);
}

public UnauthorizedException(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
package com.netscape.certsrv.base;

import javax.ws.rs.core.Response;
import javax.servlet.http.HttpServletResponse;

/**
* @author Marco Fargetta {@literal <[email protected]>}
Expand All @@ -15,11 +15,11 @@ public class UnsupportedMediaType extends PKIException {
private static final long serialVersionUID = 1L;

public UnsupportedMediaType(String message) {
super(Response.Status.UNSUPPORTED_MEDIA_TYPE, message);
super(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message);
}

public UnsupportedMediaType(String message, Throwable cause) {
super(Response.Status.UNSUPPORTED_MEDIA_TYPE, message, cause);
super(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, cause);
}

public UnsupportedMediaType(Data data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.Context;
Expand Down Expand Up @@ -161,7 +162,7 @@ public static MediaType getResponseFormat(HttpHeaders headers) {
}

if (responseFormat == null) {
throw new PKIException(Response.Status.NOT_ACCEPTABLE);
throw new PKIException(HttpServletResponse.SC_NOT_ACCEPTABLE, "Not Acceptable");
}

return responseFormat;
Expand Down

0 comments on commit a90cae0

Please sign in to comment.