Commits

tbrugz  committed 68c62c0

queryon: added BadRequestException (status 400)

  • Participants
  • Parent commits d103b5e

Comments (0)

Files changed (3)

File src/tbrugz/queryon/BadRequestException.java

+package tbrugz.queryon;
+
+public class BadRequestException extends RuntimeException {
+
+	public BadRequestException(String message) {
+		super(message);
+	}
+}

File src/tbrugz/queryon/QueryOn.java

 	@Override
 	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
 			throws ServletException, IOException {
+		try {
+			doService(req, resp);
+		}
+		catch(BadRequestException e) {
+			resp.setStatus(400);
+			resp.getWriter().write(e.getMessage());
+			//throw e;
+		}
+	}
+	
+	void doService(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
 		log.info(">> pathInfo: "+req.getPathInfo());
 		
 		RequestSpec reqspec = new RequestSpec(dsutils, req, prop);
 		else {
 			dbobj = SchemaModelUtils.getDBIdentifiableBySchemaAndName(model, reqspec);
 			if(dbobj==null) {
-				throw new ServletException("unknown object: "+reqspec.object);
+				throw new BadRequestException("unknown object: "+reqspec.object);
 			}
 			
 			if(dbobj instanceof Relation) {
 				atype = ActionType.EXECUTE;
 			}
 			else {
-				throw new ServletException("unknown object type: "+dbobj.getClass().getName()+" [obj="+reqspec.object+"]");
+				throw new BadRequestException("unknown object type: "+dbobj.getClass().getName()+" [obj="+reqspec.object+"]");
 			}
 		}
 		
 				doStatus(reqspec, resp);
 				break;
 			default:
-				throw new ServletException("Unknown action type: "+atype); 
+				throw new BadRequestException("Unknown action type: "+atype); 
 			}
 		}
 		catch(SQLException e) {
 			rs = new ResultSetListAdapter<FK>("status", statusUniqueColumns, list, FK.class);
 		}
 		else {
-			throw new ServletException("unknown object: "+reqspec.object);
+			throw new BadRequestException("unknown object: "+reqspec.object);
 		}
 		
 		if(reqspec.params!=null && reqspec.params.size()>0) {

File src/tbrugz/queryon/RequestSpec.java

 		String[] URIparts = varUrl.split("/");
 		List<String> URIpartz = new ArrayList<String>( Arrays.asList(URIparts) );
 		log.info("urlparts: "+URIpartz);
-		if(URIpartz.size()<2) { throw new ServletException("URL must have at least 1 part"); }
+		if(URIpartz.size()<2) { throw new BadRequestException("URL must have at least 1 part"); }
 
 		String lastURIPart = URIpartz.remove(URIpartz.size()-1);
 		int lastDotIndex = lastURIPart.lastIndexOf('.');
 		}
 		
 		DumpSyntax outputSyntaxTmp = null;
-		//accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
+		// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
+		// accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
 		String acceptHeader = req.getHeader("Accept");
 		log.info("accept: "+acceptHeader);
 		
 		if(outputTypeStr != null) {
 			outputSyntaxTmp = dsutils.getDumpSyntax(outputTypeStr, prop);
 			if(outputSyntaxTmp==null) {
-				throw new ServletException("Unknown output syntax: "+outputTypeStr);
+				throw new BadRequestException("Unknown output syntax: "+outputTypeStr);
 			}
 		}
 		else {