Skip to content
Snippets Groups Projects
Commit 61a22d4a authored by Robert Butora's avatar Robert Butora
Browse files

adds error handling to formatting-filter and makes doError if essential...

adds error handling to formatting-filter and makes doError if essential columns do not exist int the obscore-table
parent ef145d74
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,7 @@ public class DbPSearch
public String[] queryOverlapingPubdid(Coord coord)
throws Exception
{
LOGGER.fine("trace");
......@@ -110,8 +111,9 @@ public class DbPSearch
}
catch (SQLException se)
{
logSqlExInfo(se);
dbError(se);
// se.printStackTrace();
throw new Exception(se.toString());
}
String[] pubdidArr = pubdidList.toArray(new String[0]);
......@@ -152,6 +154,7 @@ public class DbPSearch
public FormatResponseFilter.ObsCore[] queryOutputData(String[] pubdidArr, Pos pos)
throws Exception
{
LOGGER.fine("trace");
......@@ -241,8 +244,9 @@ public class DbPSearch
}
catch (SQLException se)
{
logSqlExInfo(se);
dbError(se);
// se.printStackTrace();
throw new Exception(se.toString());
}
FormatResponseFilter.ObsCore[] cubes = obsCoreList.toArray(new FormatResponseFilter.ObsCore[0]);
......@@ -261,7 +265,7 @@ public class DbPSearch
}
catch(SQLException se)
{
logSqlExInfo(se);
dbError(se);
return null;
}
}
......@@ -275,7 +279,7 @@ public class DbPSearch
}
catch(SQLException se)
{
logSqlExInfo(se);
dbError(se);
return null;
}
}
......@@ -289,7 +293,7 @@ public class DbPSearch
}
catch(SQLException se)
{
logSqlExInfo(se);
dbError(se);
return null;
}
}
......@@ -303,7 +307,7 @@ public class DbPSearch
}
catch(SQLException se)
{
logSqlExInfo(se);
dbError(se);
return null;
}
}
......@@ -393,11 +397,11 @@ public class DbPSearch
}
private void logSqlExInfo(SQLException se)
private void dbError(SQLException se)
{
LOGGER.fine("SQLState : " + se.getSQLState());
LOGGER.fine("ErrorCode: " + se.getErrorCode());
LOGGER.warning("Message : " + se.getMessage());
LOGGER.warning("Message: " + se.getMessage());
Throwable t = se.getCause();
while(t != null) {
LOGGER.fine("Cause: " + t);
......
......@@ -61,12 +61,6 @@ public class FormatResponseFilter implements Filter
private String reqQueryString;
protected void doUsageError(String message, PrintWriter printWriter)
{
printWriter.println("UsageError : " + message);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
......@@ -77,78 +71,135 @@ public class FormatResponseFilter implements Filter
LOGGER.config("DB: " + settings.dbConn.toString());
}
// FIXME move error handling funcs to VOlib
protected void doMultiValuedParamNotSupported(String message, PrintWriter printWriter)
{
printWriter.println("MultiValuedParamNotSupported : " + message);
}
protected void doUsageError(String message, PrintWriter printWriter)
{
printWriter.println("UsageError : " + message);
}
protected void doError(String message, PrintWriter printWriter)
{
printWriter.println("Error : " + message);
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
LOGGER.fine("trace");
LOGGER.fine("REQUEST START =============================================================================================");
long startTime_msec = System.currentTimeMillis();
FormatResponseWrapper responseWrapper = new FormatResponseWrapper((HttpServletResponse) response);
chain.doFilter(request, responseWrapper);
try
{
long startTime_msec = System.currentTimeMillis();
String[] pubdidArr = responseWrapper.getPubdidArr();
if ((pubdidArr != null) && (pubdidArr.length > 0))
{
PrintWriter responseWriter = ((HttpServletResponse)response).getWriter();
// VLKB: reconstruct cutout/merge queryStrings and overlap code
Map<String, String[]> params = request.getParameterMap();
Pos pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM);
Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM);
String queryStringBase = toQueryString(pos, band);
// VLKB: calc overlap-code for sky
ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos);
// VLKB: calc overlap-code for velocity
// convert overlap-codes and adds access-urls for cutout, merge
Dataset[] datasetArr = convert(obsCoreArr, band,
settings.serviceUrls.cutoutUrl(),
queryStringBase);
String respFormat;
String respFormatReq[] = params.get("RESPONSEFORMAT");
if(respFormatReq != null && (respFormatReq.length > 0) && !respFormatReq[0].isEmpty())
chain.doFilter(request, responseWrapper);
String[] pubdidArr = responseWrapper.getPubdidArr();
if ((pubdidArr != null) && (pubdidArr.length > 0))
{
respFormat = respFormatReq[0];
LOGGER.finest("responseFormat(from request): " + respFormat);
PrintWriter responseWriter = ((HttpServletResponse)response).getWriter();
// VLKB: reconstruct cutout/merge queryStrings and overlap code
Map<String, String[]> params = request.getParameterMap();
Pos pos = Pos.parsePos(params, DEFAULT_SKY_SYSTEM);
Band band = Band.parseBand(params, DEFAULT_SPEC_SYSTEM);
String queryStringBase = toQueryString(pos, band);
// VLKB: calc overlap-code for sky
ObsCore[] obsCoreArr = queryObsCore(pubdidArr, pos);
// VLKB: calc overlap-code for velocity
// convert overlap-codes and adds access-urls for cutout, merge
Dataset[] datasetArr = convert(obsCoreArr, band,
settings.serviceUrls.cutoutUrl(),
queryStringBase);
String respFormat;
String respFormatReq[] = params.get("RESPONSEFORMAT");
if(respFormatReq != null && (respFormatReq.length > 0) && !respFormatReq[0].isEmpty())
{
respFormat = respFormatReq[0];
LOGGER.finest("responseFormat(from request): " + respFormat);
}
else
{
respFormat = settings.serviceUrls.responseFormat();
LOGGER.finest("responseFormat(from settings): " + respFormat);
}
response.setCharacterEncoding(RESPONSE_ENCODING);
if(respFormat.startsWith("application/x-votable+xml"))
{
response.setContentType("application/xml");
boolean showDuration = false;
XmlSerializer.serializeToVoTable(responseWriter, RESPONSE_ENCODING,
datasetArr,
settings.serviceUrls.cutoutUrl(),settings.serviceUrls.mergeUrl(),
showDuration,startTime_msec);
}
else
{
final String errMsg = "Illegal response format request: " + respFormat;
LOGGER.warning(errMsg);
response.setContentType("text/plain");
doUsageError(errMsg, responseWriter);
// FIXME set http err code
}
responseWriter.close();
}
else
{
respFormat = settings.serviceUrls.responseFormat();
LOGGER.finest("responseFormat(from settings): " + respFormat);
LOGGER.fine("SearchServlet returned no ID's.");
}
}
catch(MultiValuedParamNotSupported ex)
{
LOGGER.warning("MultiValuedParamNotSupported: " + ex.getMessage());
response.setCharacterEncoding(RESPONSE_ENCODING);
responseWrapper.setStatus(HttpServletResponse.SC_BAD_REQUEST);
responseWrapper.setContentType("text/plain");
if(respFormat.startsWith("application/x-votable+xml"))
{
response.setContentType("application/xml");
boolean showDuration = false;
PrintWriter writer = responseWrapper.getWriter();
doMultiValuedParamNotSupported(ex.getMessage(), writer);
writer.close();
}
catch(IllegalArgumentException ex)
{
LOGGER.warning("IllegalArgumentException: " + ex.getMessage());
XmlSerializer.serializeToVoTable(responseWriter, RESPONSE_ENCODING,
datasetArr,
settings.serviceUrls.cutoutUrl(),settings.serviceUrls.mergeUrl(),
showDuration,startTime_msec);
}
else
{
final String errMsg = "Illegal response format request: " + respFormat;
LOGGER.warning(errMsg);
response.setContentType("text/plain");
doUsageError(errMsg, responseWriter);
// FIXME set http err code
}
responseWrapper.setStatus(HttpServletResponse.SC_BAD_REQUEST);
responseWrapper.setContentType("text/plain");
responseWriter.close();
PrintWriter writer = responseWrapper.getWriter();
doUsageError(ex.getMessage(), writer);
writer.close();
}
else
catch(Exception ex)
{
LOGGER.fine("SearchServlet returned no ID's.");
LOGGER.warning("Exception: " + ex.getMessage());
// ex.printStackTrace();
responseWrapper.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
responseWrapper.setContentType("text/plain");
PrintWriter writer = responseWrapper.getWriter();
doError(ex.toString(), writer);
writer.close();
}
LOGGER.fine("REQUEST END =============================================================================================");
......@@ -216,6 +267,7 @@ public class FormatResponseFilter implements Filter
private FormatResponseFilter.ObsCore[] queryObsCore(String[] pubdidArr, Pos pos)//, String fitsRemotePath)
throws Exception
{
LOGGER.fine("trace");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment