use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class Accept method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
try {
String phone = req.getParameter(Accept.PARAMETER_NUMBER);
String msn = req.getParameter(Accept.PARAMETER_MSN);
if (phone == null || phone.length() == 0)
phone = IJAMConst.CLIRED_CALL;
ICall call = ClientCallMap.getInstance().getCall(phone + "/" + msn);
this.m_logger.info("Key for ClientCallMap: " + phone + "/" + msn);
if (call != null) {
long end = new Date().getTime();
long start = this.getStartTime(call);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ENDRING, Long.toString(end)));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_RINGDURATION, Long.toString((end - start) / 1000)));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_ACCEPTED));
if (ClientCallMap.getInstance().removeCall(phone + "/" + msn))
this.m_logger.info("Successfully found call: " + phone + "/" + msn);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException 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.HandlerException in project janrufmonitor by tbrandt77.
the class ApplicationReady method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
try {
IEventBroker evb = this.getRuntime().getEventBroker();
evb.register(this);
evb.send(this, evb.createEvent(IEventConst.EVENT_TYPE_APPLICATION_READY));
this.m_logger.info("Send application ready event.");
evb.unregister(this);
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class IncomingCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
IPhonenumber pn = null;
try {
String phone = req.getParameter(IncomingCall.PARAMETER_NUMBER);
if (phone == null || phone.length() == 0)
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
else
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(IncomingCall.PARAMETER_CIP), "");
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(IncomingCall.PARAMETER_MSN), "");
Date date = new Date(Long.parseLong(req.getParameter(IncomingCall.PARAMETER_DATE)));
ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.
the class Clear method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
try {
String phone = req.getParameter(Clear.PARAMETER_NUMBER);
String msn = req.getParameter(Clear.PARAMETER_MSN);
if (phone == null || phone.length() == 0)
phone = IJAMConst.CLIRED_CALL;
ICall call = ClientCallMap.getInstance().getCall(phone + "/" + msn);
this.m_logger.info("Key for ClientCallMap: " + phone + "/" + msn);
if (call != null) {
long end = new Date().getTime();
long start = this.getStartTime(call);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ENDRING, Long.toString(end)));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_RINGDURATION, Long.toString((end - start) / 1000)));
if (ClientCallMap.getInstance().removeCall(phone + "/" + msn))
this.m_logger.info("Successfully found call: " + phone + "/" + msn);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations