Search in sources :

Example 21 with HandlerException

use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.

the class IdentifiedOutgoingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    try {
        ICall call = XMLSerializer.toCall(this.getPostData(req));
        if (call != null) {
            ClientCallMap.getInstance().setCall((call.getCaller().getPhoneNumber().isClired() ? IJAMConst.CLIRED_CALL : call.getCaller().getPhoneNumber().getTelephoneNumber()) + "/" + call.getMSN().getMSN(), call);
            Thread sender = new Thread(new HandlerThread(call, this));
            sender.start();
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid call transfered from server.");
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICall(de.janrufmonitor.framework.ICall) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 22 with HandlerException

use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.

the class OutgoingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    IPhonenumber pn = null;
    try {
        String phone = req.getParameter(OutgoingCall.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(OutgoingCall.PARAMETER_CIP), "");
        IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(OutgoingCall.PARAMETER_MSN), "");
        Date date = new Date(Long.parseLong(req.getParameter(OutgoingCall.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())));
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
        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 23 with HandlerException

use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.

the class Configuration method handleFile.

private void handleFile(String path, IMutableHttpResponse resp) throws Exception {
    String root = PathResolver.getInstance(getRuntime()).getInstallDirectory();
    File rootf = new File(root);
    File requestedFile = new File(rootf, path);
    if (!requestedFile.exists())
        throw new HandlerException(404);
    if (requestedFile.getName().toLowerCase().endsWith(".css")) {
        resp.setParameter("Content-Type", "text/css");
        resp.setParameter("Content-Length", Long.toString(requestedFile.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        Stream.copy(new FileInputStream(requestedFile), ps, true);
        return;
    }
    if (requestedFile.getName().toLowerCase().endsWith(".jpg")) {
        resp.setParameter("Content-Type", "image/jpeg");
        resp.setParameter("Content-Length", Long.toString(requestedFile.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        Stream.copy(new FileInputStream(requestedFile), ps, true);
        return;
    }
    throw new HandlerException(404);
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 24 with HandlerException

use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.

the class GetCallListCount method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(GetCallListCount.PARAMETER_CALLMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
        throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
    }
    String filter = null;
    try {
        filter = req.getParameter(GetCallListCount.PARAMETER_FILTER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    String s = null;
    ISearchTerm[] searchterms = null;
    try {
        s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (s != null && s.length() > 0) {
        this.m_logger.info("SearchTerms: " + s);
        searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
    }
    int count = 0;
    if (filter == null || filter.length() == 0) {
        this.m_logger.info("Filter parameter &filter= was not set.");
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            count = ((ISearchableCallRepository) mgr).getCallCount(getAllowedMsnFilter(req), searchterms);
        } else
            count = ((IReadCallRepository) mgr).getCallCount(getAllowedMsnFilter(req));
    } else {
        IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
        f = mergeFilters(f, getAllowedMsnFilter(req));
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            count = ((ISearchableCallRepository) mgr).getCallCount(f, searchterms);
        } else
            count = ((IReadCallRepository) mgr).getCallCount(f);
    }
    try {
        String xml = Integer.toString(count);
        resp.setParameter("Content-Type", "text/plain");
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallManager(de.janrufmonitor.repository.ICallManager) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) IFilter(de.janrufmonitor.repository.filter.IFilter) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 25 with HandlerException

use of de.janrufmonitor.service.commons.http.handler.HandlerException in project janrufmonitor by tbrandt77.

the class Callto method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    String calltoclass = null;
    if (PIMRuntime.getInstance().getMonitorListener().getMonitor("FritzBoxMonitor") != null) {
        calltoclass = "de.janrufmonitor.fritzbox.QuickDialer";
    } else if (PIMRuntime.getInstance().getMonitorListener().getMonitor("XTapiMonitor") != null) {
        calltoclass = "de.janrufmonitor.xtapi.QuickDialer";
    } else {
        throw new HandlerException("No FritzBoxMonitor or XTapiMonitor available.", 404);
    }
    try {
        Class handler = Thread.currentThread().getContextClassLoader().loadClass(calltoclass);
        Object o = handler.newInstance();
        String ext = req.getParameter(PARAMETER_CALLTO_EXTENSION);
        String getext = req.getParameter(PARAMETER_CALLTO_GET_EXTENSION);
        String type = req.getParameter(PARAMETER_CALLTO_RETURNTYPE);
        String dial = req.getParameter(PARAMETER_CALLTO_ACTION);
        StringBuffer xhtml = null;
        if (getext != null && getext.equalsIgnoreCase("true")) {
            xhtml = generateXmlAllExtension(o, dial, ext);
            resp.setParameter("Content-Type", "text/xml");
        } else if (type != null && type.equalsIgnoreCase("html")) {
            xhtml = generateHtml(o, dial, ext);
            resp.setParameter("Content-Type", "text/html");
        } else {
            xhtml = generateXml(o, dial, ext);
            resp.setParameter("Content-Type", "text/xml");
        }
        resp.setParameter("Content-Length", Long.toString(xhtml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xhtml.toString().getBytes());
        ps.flush();
        ps.close();
    } catch (HandlerException e) {
        throw e;
    } catch (ClassNotFoundException ex) {
        throw new HandlerException("Class not found: " + calltoclass, 500);
    } catch (InstantiationException e) {
        throw new HandlerException("Cannot instantiate class: " + calltoclass, 500);
    } catch (IllegalAccessException e) {
        throw new HandlerException("Illegal access for class: " + calltoclass, 500);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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