Search in sources :

Example 1 with HandlerException

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);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICall(de.janrufmonitor.framework.ICall) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 2 with HandlerException

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 ...");
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) UnknownHostException(java.net.UnknownHostException) GenericHandler(de.janrufmonitor.service.commons.http.simple.handler.GenericHandler) Handler(de.janrufmonitor.service.commons.http.handler.Handler) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) UnknownHostException(java.net.UnknownHostException)

Example 3 with HandlerException

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);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 4 with HandlerException

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);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 5 with HandlerException

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);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICall(de.janrufmonitor.framework.ICall) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Aggregations

HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)33 OutputStream (java.io.OutputStream)11 ICall (de.janrufmonitor.framework.ICall)7 Date (java.util.Date)7 ICallerManager (de.janrufmonitor.repository.ICallerManager)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)5 ICallManager (de.janrufmonitor.repository.ICallManager)5 IFilter (de.janrufmonitor.repository.filter.IFilter)5 ICallList (de.janrufmonitor.framework.ICallList)4 ICaller (de.janrufmonitor.framework.ICaller)4 ICallerList (de.janrufmonitor.framework.ICallerList)4 IMsn (de.janrufmonitor.framework.IMsn)4 ISearchTerm (de.janrufmonitor.repository.search.ISearchTerm)3 SearchTermSeriarlizer (de.janrufmonitor.repository.search.SearchTermSeriarlizer)3 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)3 ICip (de.janrufmonitor.framework.ICip)2 IName (de.janrufmonitor.framework.IName)2 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)2 MsnFilter (de.janrufmonitor.repository.filter.MsnFilter)2 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)2