Search in sources :

Example 26 with HandlerException

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

the class Dial method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    m_logger.info("Calling server Dial comamnd...");
    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_EXTENSION);
        String dial = req.getParameter(PARAMETER_NUMBER);
        m_logger.info("Dial comamnd parameter dial=" + dial + ", ext=" + ext);
        if (dial != null && dial.length() > 1) {
            dial = PhonenumberAnalyzer.getInstance(getRuntime()).toCallable(dial);
            IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(dial);
            try {
                Method m = o.getClass().getMethod("dial", new Class[] { IPhonenumber.class, String.class });
                if (ext != null) {
                    ext = URLDecoder.decode(ext, "UTF-8");
                }
                m.invoke(o, new Object[] { pn, ext });
            } catch (Exception ex) {
                throw new HandlerException("Could not dial number.", 500);
            }
        }
        resp.getContentStreamForWrite().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) Method(java.lang.reflect.Method) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 27 with HandlerException

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

the class GetCallList method getAllowedMsnFilter.

private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
    try {
        boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
        if (!allowedForAllMsns) {
            String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
            if (allowedMSNs == null)
                allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
            if (allowedMSNs != null) {
                IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
                IMsn msn = null;
                for (int i = 0; i < allowedMSNs.length; i++) {
                    msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
                    allowedMsnFilter[i] = new MsnFilter(msn);
                    m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
                }
                return allowedMsnFilter;
            }
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new HandlerException(e.getMessage(), 500);
    }
    return new IFilter[0];
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IFilter(de.janrufmonitor.repository.filter.IFilter) MsnFilter(de.janrufmonitor.repository.filter.MsnFilter) IMsn(de.janrufmonitor.framework.IMsn) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 28 with HandlerException

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

the class GetDialExtensions 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();
        StringBuffer plain = new StringBuffer();
        try {
            Method m = o.getClass().getMethod("getAllExtensions", new Class[] {});
            if (m != null) {
                Object retcode = m.invoke(o, new Object[] {});
                if (retcode != null && retcode instanceof String[]) {
                    for (int i = 0, j = ((String[]) retcode).length; i < j; i++) {
                        plain.append(StringUtils.replaceString(((String[]) retcode)[i], ",", "$ktoken$"));
                        plain.append(",");
                    }
                }
            }
        } catch (Exception ex) {
        }
        resp.setParameter("Content-Length", Long.toString(plain.length()));
        resp.setParameter("Content-Type", "text/plain");
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(plain.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) Method(java.lang.reflect.Method) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 29 with HandlerException

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

the class Register method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    String client = "";
    String clientip = "";
    try {
        client = req.getInetAddress().getHostName();
        clientip = req.getInetAddress().getHostAddress();
        if (clientip == null)
            throw new HandlerException("No valid IP address.", 403);
        if (client == null)
            client = "";
    } catch (Exception ex) {
        throw new HandlerException(ex.getMessage(), 500);
    }
    if (client.length() > 0 || clientip.length() > 0) {
        try {
            String s_port = req.getParameter(Register.PARAMETER_CLIENT_PORT);
            if (s_port == null)
                throw new HandlerException("No client call back port.", 403);
            int port = 0;
            if (s_port.length() > 0) {
                port = Integer.parseInt(s_port);
            }
            this.m_logger.info("Registering new client " + client + ":" + port);
            Client c = new Client(client, clientip, port);
            List events = this.getEvents(req.getParameter(Register.PARAMETER_CLIENT_EVENTS));
            c.setEvents(events);
            this.m_logger.info("Registered for events: " + events);
            ClientRegistry.getInstance().register(c);
            resp.getContentStreamForWrite().close();
        } catch (Exception e) {
            throw new HandlerException(e.getMessage(), 500);
        }
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) List(java.util.List) ArrayList(java.util.ArrayList) Client(de.janrufmonitor.service.server.Client) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 30 with HandlerException

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

the class RemoveCallList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    boolean isCompression = false;
    try {
        manager = req.getParameter(RemoveCallList.PARAMETER_CALLMANAGER);
        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().getCallManagerFactory().getDefaultCallManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallRepository.class)) {
        throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
    }
    ICallList l;
    try {
        byte[] data = this.getPostData(req).getBytes();
        if (isCompression) {
            data = CompressBase64.decompressBase64Decode(data);
        }
        l = XMLSerializer.toCallList(new String(data));
        if (l != null) {
            this.m_logger.info("Removing call list with " + l.size() + " entries.");
            ((IWriteCallRepository) mgr).removeCalls(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid call list transfered from client.");
            throw new HandlerException("Invalid call list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallList(de.janrufmonitor.framework.ICallList) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

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