Search in sources :

Example 31 with HandlerException

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

the class GetCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    boolean isCompression = false;
    try {
        manager = req.getParameter(GetCallerList.PARAMETER_CALLERMANAGER);
        isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l = this.getRuntime().getCallerFactory().createCallerList();
    String filter = null;
    try {
        filter = req.getParameter(GetCallerList.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) {
        searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
    }
    if (filter == null || filter.length() == 0) {
        if (mgr.isSupported(ISearchableCallerRepository.class)) {
            l = ((ISearchableCallerRepository) mgr).getCallers(new IFilter[] {}, searchterms);
        } else
            l = ((IReadCallerRepository) mgr).getCallers((IFilter) null);
        this.m_logger.info("Filter parameter &filter= was not set.");
    } else {
        IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
        if (mgr.isSupported(ISearchableCallerRepository.class)) {
            l = ((ISearchableCallerRepository) mgr).getCallers(f, searchterms);
        } else
            l = ((IReadCallerRepository) mgr).getCallers(f);
    }
    try {
        String xml = XMLSerializer.toXML(l, false);
        if (isCompression && xml.length() > 1024) {
            this.m_logger.info("Compressing requested data.");
            this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
            xml = CompressBase64.compressBase64Encode(xml);
            this.m_logger.info("Compressed data size [bytes] : " + xml.length());
            resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
        } else {
            resp.setParameter("Content-Type", "text/xml");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
        }
        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 : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) IReadCallerRepository(de.janrufmonitor.repository.types.IReadCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 32 with HandlerException

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

the class RemoveCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(RemoveCallerList.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l;
    try {
        l = XMLSerializer.toCallerList(this.getPostData(req));
        if (l != null) {
            this.m_logger.info("Removing caller list with " + l.size() + " entries.");
            ((IWriteCallerRepository) mgr).removeCaller(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid caller list transfered from client.");
            throw new HandlerException("Invalid caller list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 33 with HandlerException

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

the class SetCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(SetCallerList.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l;
    try {
        l = XMLSerializer.toCallerList(this.getPostData(req));
        if (l != null) {
            this.m_logger.info("Setting caller list with " + l.size() + " entries.");
            ((IWriteCallerRepository) mgr).setCaller(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid caller list transfered from client.");
            throw new HandlerException("Invalid caller list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallerList(de.janrufmonitor.framework.ICallerList) IWriteCallerRepository(de.janrufmonitor.repository.types.IWriteCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) 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