use of de.janrufmonitor.service.commons.http.handler.Handler in project janrufmonitor by tbrandt77.
the class ClientHandler method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
this.m_logger.info("Processing incoming server request ...");
try {
resp.setParameter("Server", "jAnrufmonitor-Client-" + InetAddress.getLocalHost().getHostName() + "/2.0");
} catch (UnknownHostException e) {
throw new HandlerException(e.getMessage(), 500);
}
resp.setParameter("Date", Long.toString(System.currentTimeMillis()));
String actionHandler = null;
try {
actionHandler = this.getActionHandler(req);
} catch (Exception e) {
throw new HandlerException("IOException in retrieving action handler", 500);
}
if (actionHandler == null)
throw new HandlerException("No valid action parameter found", 404);
if (actionHandler.length() > 0) {
try {
Class handler = Thread.currentThread().getContextClassLoader().loadClass(actionHandler);
Object o = handler.newInstance();
if (o instanceof Handler) {
((Handler) o).handleWithException(req, resp);
}
} catch (ClassNotFoundException ex) {
throw new HandlerException("Class not found: " + actionHandler, 500);
} catch (InstantiationException e) {
throw new HandlerException("Cannot instantiate class: " + actionHandler, 500);
} catch (IllegalAccessException e) {
throw new HandlerException("Illegal access for class: " + actionHandler, 500);
} catch (HandlerException e) {
throw e;
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
super.handleWithException(req, resp);
this.m_logger.info("Finishing incoming server request ...");
}
use of de.janrufmonitor.service.commons.http.handler.Handler in project janrufmonitor by tbrandt77.
the class ServerHandler method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
resp.setParameter("Server", "jAnrufmonitor/5.0");
resp.setParameter("Date", Long.toString(System.currentTimeMillis()));
try {
// do security checks
if (!this.isAllowed(req))
throw new HandlerException("Access denied by IP address", 403);
} catch (Exception e) {
if (e instanceof HandlerException)
throw (HandlerException) e;
throw new HandlerException("Exception in security check.", 500);
}
String actionHandler = null;
try {
actionHandler = this.getActionHandler(req);
} catch (Exception e) {
throw new HandlerException("Exception in retrieving action handler", 500);
}
if (actionHandler == null)
throw new HandlerException("No valid action parameter found", 404);
if (actionHandler.length() > 0) {
try {
Class handler = Thread.currentThread().getContextClassLoader().loadClass(actionHandler);
Object o = handler.newInstance();
if (o instanceof Handler) {
this.setHistoryEvent(req);
this.setTransferedBytes(req);
this.m_logger.info("Handle request " + req.getURI());
((Handler) o).handleWithException(req, resp);
}
} catch (ClassNotFoundException ex) {
throw new HandlerException("Class not found: " + actionHandler, 500);
} catch (InstantiationException e) {
throw new HandlerException("Cannot instantiate class: " + actionHandler, 500);
} catch (IllegalAccessException e) {
throw new HandlerException("Illegal access for class: " + actionHandler, 500);
} catch (HandlerException e) {
throw e;
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
super.handleWithException(req, resp);
}
Aggregations