use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class S3DataRequest method readJson.
protected String readJson() throws GWException {
String ret = null;
try {
byte[] json = s3Parameter.getInputStream().readAllBytes();
s3Parameter.addRequestSize(json.length);
ret = new String(json);
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
logger.info(ret);
if (Strings.isNullOrEmpty(ret)) {
logger.warn(GWErrorCode.INVALID_ARGUMENT.getMessage());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
return ret;
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class MariaDB method execute.
private void execute(String query, List<Object> params, S3Parameter s3Parameter) throws GWException {
try (Connection conn = DriverManager.getConnection(GWConstants.JDBC_DRIVER);
PreparedStatement pstmt = conn.prepareStatement(query)) {
int index = 1;
if (params != null) {
for (Object p : params) {
pstmt.setObject(index, p);
index++;
}
}
logger.info(pstmt.toString());
pstmt.execute();
} catch (SQLException e) {
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
} catch (Exception e) {
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
}
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class MariaDB method select.
public List<HashMap<String, Object>> select(String query, List<Object> params, S3Parameter s3Parameter) throws GWException {
List<HashMap<String, Object>> rmap = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
try {
conn = DriverManager.getConnection(GWConstants.JDBC_DRIVER);
pstmt = conn.prepareStatement(query);
int index = 1;
if (params != null) {
for (Object p : params) {
pstmt.setObject(index, p);
index++;
}
}
logger.info(pstmt.toString());
rset = pstmt.executeQuery();
ResultSetMetaData md = rset.getMetaData();
int columns = md.getColumnCount();
int init = 0;
while (rset.next()) {
if (init == 0) {
rmap = new ArrayList<HashMap<String, Object>>();
init++;
}
HashMap<String, Object> map = null;
map = new HashMap<String, Object>(columns);
for (int i = 1; i <= columns; ++i) {
map.put(md.getColumnName(i), rset.getObject(i));
}
rmap.add(map);
}
} catch (SQLException e) {
logger.error(e.getMessage());
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
} catch (Exception e) {
logger.error(e.getMessage());
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
} finally {
if (rset != null)
try {
rset.close();
} catch (Exception e) {
logger.error(e.getMessage());
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
}
if (pstmt != null)
try {
pstmt.close();
} catch (Exception e) {
logger.error(e.getMessage());
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
}
if (conn != null)
try {
conn.close();
} catch (Exception e) {
logger.error(e.getMessage());
throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
}
}
return rmap;
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class GWHandler method doHandle.
public final void doHandle(Request baseRequest, HttpServletRequest request, HttpServletResponse response, InputStream is) throws GWException {
long requestSize = 0L;
String method = request.getMethod();
requestSize = method.length();
String uri = request.getRequestURI();
requestSize += uri.length();
long startTime = System.currentTimeMillis();
logger.info(GWConstants.LOG_GWHANDLER_PREURI, uri);
uri = removeDuplicateRoot(uri);
logger.info(GWConstants.LOG_GWHANDLER_URI, uri);
logger.info(GWConstants.LOG_GWHANDLER_CLIENT_ADDRESS, request.getRemoteAddr());
logger.info(GWConstants.LOG_GWHANDLER_CLIENT_HOST, request.getRemoteHost());
logger.info(GWConstants.LOG_GWHANDLER_METHOD, method);
for (String parameter : Collections.list(request.getParameterNames())) {
logger.info(GWConstants.LOG_GWHANDLER_PARAMETER, parameter, Strings.nullToEmpty(request.getParameter(parameter)));
requestSize += parameter.length();
if (!Strings.isNullOrEmpty(request.getParameter(parameter))) {
requestSize += request.getParameter(parameter).length();
}
}
for (String headerName : Collections.list(request.getHeaderNames())) {
for (String headerValue : Collections.list(request.getHeaders(headerName))) {
logger.info(GWConstants.LOG_GWHANDLER_HEADER, headerName, Strings.nullToEmpty(headerValue));
requestSize += headerName.length();
if (!Strings.isNullOrEmpty(headerValue)) {
requestSize += headerValue.length();
}
}
}
// make request id
String requestID = UUID.randomUUID().toString().substring(24).toUpperCase();
String[] path = uri.split(GWConstants.SLASH, 3);
try {
for (int i = 0; i < path.length; i++) {
path[i] = URLDecoder.decode(path[i], GWConstants.CHARSET_UTF_8);
logger.info(GWConstants.LOG_GWHANDLER_PATH, i, path[i]);
}
} catch (UnsupportedEncodingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.BAD_REQUEST, null);
}
String pathCategory = GWConstants.EMPTY_STRING;
if (uri.equals(GWConstants.SLASH)) {
pathCategory = GWConstants.CATEGORY_ROOT;
} else if (path.length <= 2 || path[2].isEmpty()) {
pathCategory = GWConstants.CATEGORY_BUCKET;
} else {
pathCategory = GWConstants.CATEGORY_OBJECT;
}
S3Parameter s3Parameter = new S3Parameter();
s3Parameter.setRequestSize(requestSize);
s3Parameter.setRequestID(requestID);
s3Parameter.setRequest(request);
s3Parameter.setResponse(response);
s3Parameter.setInputStream(is);
if (!Strings.isNullOrEmpty(path[1])) {
s3Parameter.setBucketName(path[1]);
}
if (path.length == 3 && !Strings.isNullOrEmpty(path[2])) {
s3Parameter.setObjectName(path[2]);
}
s3Parameter.setMethod(method);
s3Parameter.setStartTime(startTime);
s3Parameter.setPathCategory(pathCategory);
s3Parameter.setMaxFileSize(maxFileSize);
s3Parameter.setMaxTimeSkew(maxTimeSkew);
s3Parameter.setRemoteHost(request.getRemoteHost());
s3Parameter.setRequestURI(request.getRequestURI());
s3Parameter.setReferer(request.getHeader(HttpHeaders.REFERER));
s3Parameter.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));
s3Parameter.setAuthorization(request.getHeader(HttpHeaders.AUTHORIZATION));
s3Parameter.setxAmzAlgorithm(request.getParameter(GWConstants.X_AMZ_ALGORITHM));
s3Parameter.setHostName(request.getHeader(HttpHeaders.HOST));
s3Parameter.setHostID(request.getHeader(GWConstants.X_AMZ_ID_2));
s3Parameter.setRemoteAddr(!Strings.isNullOrEmpty(request.getHeader(GWConstants.X_FORWARDED_FOR)) ? request.getHeader(GWConstants.X_FORWARDED_FOR) : request.getRemoteAddr());
if (request.getHeader(HttpHeaders.AUTHORIZATION) == null && request.getParameter(GWConstants.X_AMZ_ALGORITHM) == null && request.getParameter(GWConstants.AWS_ACCESS_KEY_ID) == null) {
if (s3Parameter.getPathCategory().equals(GWConstants.CATEGORY_ROOT)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
S3Signing s3signing = new S3Signing(s3Parameter);
s3Parameter = s3signing.publicvalidation();
s3Parameter.setPublicAccess(true);
} else {
S3Signing s3signing = new S3Signing(s3Parameter);
s3Parameter = s3signing.validation();
s3Parameter.setPublicAccess(false);
}
logger.info(GWConstants.LOG_GWHANDLER_MOTHOD_CATEGORY, s3Parameter.getMethod(), s3Parameter.getPathCategory());
S3Request s3Request = s3RequestFactory.createS3Request(s3Parameter);
s3Request.process();
s3Parameter.setStatusCode(response.getStatus());
AsyncHandler.s3logging(s3Parameter);
}
use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.
the class S3Request method remove.
protected void remove(String bucket, String object, String versionId) throws GWException {
try {
setObjManager();
objManager.remove(bucket, object, versionId);
} catch (Exception e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} finally {
try {
releaseObjManager();
} catch (Exception e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
}
}
Aggregations