Search in sources :

Example 1 with IMsn

use of de.janrufmonitor.framework.IMsn 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 2 with IMsn

use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.

the class GetCallListCount 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 3 with IMsn

use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.

the class Server method sendRequest.

private synchronized void sendRequest(IEvent event, IHttpRequest request) {
    List clients = ClientRegistry.getInstance().getAllClients();
    Client c = null;
    for (int i = 0; i < clients.size(); i++) {
        c = (Client) clients.get(i);
        Object call = event.getData();
        if (call != null && call instanceof ICall) {
            IMsn msn = ((ICall) call).getMSN();
            if (!SecurityManager.getInstance().isAllowedForMSN(c.getClientIP(), msn.getMSN()) || !SecurityManager.getInstance().isAllowedForMSN(c.getClientName(), msn.getMSN())) {
                this.m_logger.info("Client " + c + " is blocked for MSN " + msn.getMSN() + ".");
                continue;
            }
        }
        if (this.isEventClient(c.getEvents(), event.getType())) {
            this.m_logger.info("Sending event #" + event + " to client " + c + ".");
            try {
                if (request.getContent() != null)
                    c.setByteReceived(request.getContent().length);
                IRequester r = null;
                if (c.getClientName().trim().length() > 0)
                    r = RequesterFactory.getInstance().getRequester(c.getClientName(), c.getClientPort());
                else
                    r = RequesterFactory.getInstance().getRequester(c.getClientIP(), c.getClientPort());
                r.setRequest(request);
                Thread s = new Thread(new SenderThread(r));
                s.setName("JAM-" + SenderThread.class.getName() + "#" + i + "-Thread-(non-deamon)");
                s.start();
            } catch (Exception e) {
                this.m_logger.severe(e.getMessage());
            }
        }
    }
}
Also used : ICall(de.janrufmonitor.framework.ICall) List(java.util.List) IRequester(de.janrufmonitor.service.commons.http.IRequester) IMsn(de.janrufmonitor.framework.IMsn)

Example 4 with IMsn

use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.

the class Serializer method toCall.

/**
 * Deserializes a byte array stream into an call object.
 *
 * @param call call as a byte array representation.
 * @param runtime runtime to used
 * @return call object
 * @throws SerializerException
 */
public static ICall toCall(byte[] call, IRuntime runtime) throws SerializerException {
    if (runtime == null)
        throw new SerializerException("Runtime object is not set but required.");
    String callString = new String(call);
    if (callString.indexOf(m_ctoken) < 0)
        throw new SerializerException("Call format is invalid. Call is set <" + callString + ">");
    // tokenize the whole input
    StringTokenizer st = new StringTokenizer(callString, m_ctoken);
    if (st.countTokens() != 2)
        throw new SerializerException("Call format is invalid. Found " + st.countTokens() + " tokens, but required are exactly 2.");
    ICaller caller = toCaller(st.nextToken().getBytes(), runtime);
    if (!st.hasMoreTokens())
        throw new SerializerException("Call format is invalid. Second token is empty.");
    // tokenize to call data
    callString = st.nextToken();
    st = new StringTokenizer(callString, m_token);
    if (st.countTokens() < 7)
        throw new SerializerException("Call format is invalid. Token count < 7.");
    // build MSN
    IMsn msn = runtime.getCallFactory().createMsn(// token 1
    decode(st.nextToken().trim()), // token 2
    decode(st.nextToken().trim()));
    if (msn.getMSN().equalsIgnoreCase("*")) {
        msn.setMSN("0");
    }
    // build CIP
    ICip cip = runtime.getCallFactory().createCip(// token 3
    decode(st.nextToken().trim()), // token 4
    decode(st.nextToken().trim()));
    // token 5
    String uuid = decode(st.nextToken().trim());
    // token 6
    Date date = new Date(Long.parseLong(decode(st.nextToken().trim())));
    // build attributes
    String attString = decode(st.nextToken().trim());
    IAttributeMap attList = runtime.getCallFactory().createAttributeMap();
    if (attString.length() > 0) {
        StringTokenizer ast = new StringTokenizer(attString, m_atoken);
        String attrib = null;
        while (ast.hasMoreTokens()) {
            attrib = ast.nextToken().trim();
            if (attrib.indexOf(EQUAL) > -1) {
                IAttribute att = runtime.getCallFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
                attList.add(att);
            }
        }
    }
    return runtime.getCallFactory().createCall(uuid, caller, msn, cip, date, attList);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICip(de.janrufmonitor.framework.ICip) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date)

Example 5 with IMsn

use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.

the class XTapiCall method toCall.

public ICall toCall() {
    if (this.m_call == null) {
        IRuntime r = PIMRuntime.getInstance();
        IPhonenumber phone = PhonenumberAnalyzer.getInstance(r).toClirPhonenumber(this.m_number);
        if (phone == null)
            phone = PhonenumberAnalyzer.getInstance(r).toInternalPhonenumber(this.m_number, this.m_msn);
        if (phone == null)
            phone = PhonenumberAnalyzer.getInstance(r).toPhonenumber(this.m_number, this.m_msn);
        ICaller c = r.getCallerFactory().createCaller(phone);
        IMsn msn = null;
        if (this.m_msn == null) {
            msn = r.getCallFactory().createMsn(getFestnetzAlias(), "");
        } else {
            msn = r.getCallFactory().createMsn(this.m_msn, "");
        }
        msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
        if (this.m_name != null && this.m_name.length() > 0) {
            c.setName(r.getCallerFactory().createName("", this.m_name));
        }
        ICip cip = r.getCallFactory().createCip(getDefaultCip(), "");
        cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
        // create attributes
        IAttributeMap am = r.getCallFactory().createAttributeMap();
        am.add(r.getCallFactory().createAttribute("tapi.device", Integer.toString(this.m_device)));
        am.add(r.getCallFactory().createAttribute("tapi.instance", Integer.toString(this.m_instance)));
        am.add(r.getCallFactory().createAttribute("tapi.key", getKey(this.m_device, this.m_instance)));
        am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
        this.m_call = r.getCallFactory().createCall(c, msn, cip, new Date());
        this.m_call.setAttributes(am);
    }
    return this.m_call;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date) IRuntime(de.janrufmonitor.runtime.IRuntime) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IMsn (de.janrufmonitor.framework.IMsn)43 ICip (de.janrufmonitor.framework.ICip)17 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)17 ICaller (de.janrufmonitor.framework.ICaller)16 Date (java.util.Date)16 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)11 ICall (de.janrufmonitor.framework.ICall)9 IAttribute (de.janrufmonitor.framework.IAttribute)8 IName (de.janrufmonitor.framework.IName)6 StringTokenizer (java.util.StringTokenizer)6 SimpleDateFormat (java.text.SimpleDateFormat)5 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)4 IFilter (de.janrufmonitor.repository.filter.IFilter)4 ItemCountFilter (de.janrufmonitor.repository.filter.ItemCountFilter)4 MsnFilter (de.janrufmonitor.repository.filter.MsnFilter)4 IRuntime (de.janrufmonitor.runtime.IRuntime)4 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)4 ParseException (java.text.ParseException)4 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4