Skip to content

Commit

Permalink
Remove server classes from common library
Browse files Browse the repository at this point in the history
Status codes were retrieved from tomcat servlet.jar package but since
the common package should be used in the server as well as the client
this dependency has been removed. The codes are now handled in the the
common package.
  • Loading branch information
fmarco76 committed Aug 20, 2024
1 parent f92a844 commit e40d1f2
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion base/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ javac(pki-common-classes
src/main/java/*.java
CLASSPATH
${SLF4J_API_JAR}
${LDAPJDK_JAR} ${SERVLET_JAR}
${LDAPJDK_JAR}
${JSS_JAR}
${COMMONS_CODEC_JAR} ${COMMONS_IO_JAR}
${COMMONS_LANG3_JAR} ${COMMONS_CLI_JAR}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.base;
import javax.servlet.http.HttpServletResponse;

public class BadRequestException extends PKIException {

private static final long serialVersionUID = -4784839378360933483L;

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

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

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

import javax.servlet.http.HttpServletResponse;

public class ConflictingOperationException extends PKIException {

private static final long serialVersionUID = -5780172673428115193L;

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

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

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

import javax.servlet.http.HttpServletResponse;

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

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

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

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

import javax.servlet.http.HttpServletResponse;

public class HTTPGoneException extends PKIException {

private static final long serialVersionUID = 1256191208802745690L;

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

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

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

import javax.servlet.http.HttpServletResponse;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -45,27 +44,52 @@ public class PKIException extends RuntimeException {

private static final long serialVersionUID = 6000910362260369923L;

public int code;
//ERROR_CODES
public enum ERROR_CODE {
BAD_REQUEST(400), UNAUTHORIZED(401), FORBIDDEN(403),
NOT_FOUND(404), NOT_ACCEPTABLE(406), CONFLICT(409),
GONE(410), UNSUPPORTED_MEDIA_TYPE(415), INTERNAL_SERVER_ERROR(500),
SERVICE_UNAVAILABLE(503);

private final int code;

private ERROR_CODE(int code) {
this.code = code;
}
public int toInt() {
return code;
}
}

private int code;

public PKIException(int code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}
public PKIException(ERROR_CODE code, String message, Throwable cause) {
super(message, cause);
this.code = code.toInt();
}

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

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

public PKIException(ERROR_CODE code, String message) {
this(code.toInt(), message, null);
}

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

public PKIException(String message, Throwable cause) {
this(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message, cause);
this(ERROR_CODE.INTERNAL_SERVER_ERROR, message, cause);
}

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

import javax.servlet.http.HttpServletResponse;

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

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

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

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

import javax.servlet.http.HttpServletResponse;

public class ResourceNotFoundException extends PKIException {

private static final long serialVersionUID = 2283994502912462263L;

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

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

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

import javax.servlet.http.HttpServletResponse;

public class ServiceUnavailableException extends PKIException {

private static final long serialVersionUID = -9160776882517621347L;

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

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

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

package com.netscape.certsrv.base;

import javax.servlet.http.HttpServletResponse;


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

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

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

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

import javax.servlet.http.HttpServletResponse;

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

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

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

public UnsupportedMediaType(Data data) {
Expand Down

0 comments on commit e40d1f2

Please sign in to comment.