Search in sources :

Example 81 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class RayoComponent method handleAnswerCommand.

private IQ handleAnswerCommand(AnswerCommand command, IQ iq) {
    Map<String, String> headers = command.getHeaders();
    IQ reply = IQ.createResultIQ(iq);
    // destination JID escaped
    String callId = iq.getTo().getNode();
    // source JID
    String callerId = headers.get("caller_id");
    Log.info("RayoComponent AnswerCommand " + callerId + " " + callId);
    if (callerId != null) {
        JID callJID = getJID(callId);
        CallHandler callHandler = null;
        CallHandler handsetHandler = null;
        if (// XMPP call
        callJID != null) {
            // remove xmpp: prefix
            callerId = callerId.substring(5);
            headers.put("call_protocol", "XMPP");
            headers.put("call_owner", callerId);
            headers.put("call_action", "join");
            try {
                callHandler = CallHandler.findCall(callId);
                handsetHandler = CallHandler.findCall(JID.escapeNode(callerId));
                if (handsetHandler != null) {
                    CallParticipant hp = handsetHandler.getCallParticipant();
                    //to caller
                    Presence presence1 = new Presence();
                    presence1.setFrom(iq.getTo());
                    presence1.setTo(callerId);
                    setAnsweredState(presence1, ConferenceManager.isTransferCall(hp.getConferenceId()), headers);
                    sendPacket(presence1);
                }
            } catch (Exception e) {
                reply.setError(PacketError.Condition.item_not_found);
                e.printStackTrace();
            }
        } else {
            // SIP call;
            callHandler = CallHandler.findCall(callId);
            handsetHandler = CallHandler.findCall(JID.escapeNode(iq.getFrom().toString()));
        }
        if (callHandler != null && handsetHandler != null) {
            CallParticipant cp = callHandler.getCallParticipant();
            CallParticipant hp = handsetHandler.getCallParticipant();
            Log.info("RayoComponent handleAnswerCommand found call handlers " + cp.getCallId() + " " + hp.getCallId());
            try {
                long start = System.currentTimeMillis();
                cp.setStartTimestamp(start);
                cp.setHandset(hp);
                hp.setFarParty(cp);
                hp.setStartTimestamp(start);
                cp.setHeaders(headers);
                String recording = cp.getConferenceId() + "-" + cp.getStartTimestamp() + ".au";
                ConferenceManager.recordConference(cp.getConferenceId(), true, recording, "au");
                String destination = iq.getFrom().getNode();
                String source = cp.getName();
                if (callJID != null) {
                    source = (new JID(callerId)).getNode();
                    Config.createCallRecord(source, recording, "xmpp:" + iq.getFrom(), cp.getStartTimestamp(), 0, "dialed");
                    Config.createCallRecord(destination, recording, "xmpp:" + callerId, cp.getStartTimestamp(), 0, "received");
                    sendMessage(new JID(callerId), iq.getFrom(), "Call started", recording, "chat");
                } else {
                    // incoming SIP
                    Config.createCallRecord(destination, recording, "sip:" + cp.getPhoneNumber(), cp.getStartTimestamp(), 0, "received");
                    sendMessage(iq.getFrom(), new JID(cp.getCallId() + "@" + getDomain()), "Call started", recording, "chat");
                }
            } catch (ParseException e1) {
                reply.setError(PacketError.Condition.internal_server_error);
            }
        } else
            reply.setError(PacketError.Condition.item_not_found);
    } else
        reply.setError(PacketError.Condition.item_not_found);
    return reply;
}
Also used : JID(org.xmpp.packet.JID) ParseException(java.text.ParseException) ComponentException(org.xmpp.component.ComponentException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) ParseException(java.text.ParseException)

Example 82 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class RayoComponent method handlePauseSayCommand.

private IQ handlePauseSayCommand(boolean flag, IQ iq) {
    Log.info("RayoComponent handlePauseSayCommand " + iq.getFrom() + " " + iq.getTo());
    IQ reply = IQ.createResultIQ(iq);
    final JID entityId = getJID(iq.getTo().getNode());
    if (entityId != null) {
        final String treatmentId = entityId.getResource();
        final String callId = entityId.getNode();
        CallHandler callHandler = CallHandler.findCall(callId);
        if (callHandler != null) {
            callHandler.getMember().pauseTreatment(treatmentId, flag);
        } else {
            try {
                ConferenceManager conferenceManager = ConferenceManager.findConferenceManager(callId);
                conferenceManager.getWGManager().pauseConferenceTreatment(treatmentId, flag);
            } catch (ParseException e1) {
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else {
        reply.setError(PacketError.Condition.item_not_found);
    }
    return reply;
}
Also used : JID(org.xmpp.packet.JID) ParseException(java.text.ParseException)

Example 83 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class CallHandler method setRemoteMediaInfo.

public static void setRemoteMediaInfo(String callId, String sdp) throws ParseException {
    synchronized (activeCalls) {
        for (int i = 0; i < activeCalls.size(); i++) {
            CallHandler call = (CallHandler) activeCalls.elementAt(i);
            CallParticipant cp = call.getCallParticipant();
            if (match(cp, callId)) {
                call.setRemoteMediaInfo(sdp);
                return;
            }
        }
    }
    throw new ParseException("Invalid callId: " + callId, 0);
}
Also used : CallParticipant(com.sun.voip.CallParticipant) ParseException(java.text.ParseException)

Example 84 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class NodeSubscription method configure.

void configure(DataForm options) {
    List<String> values;
    String booleanValue;
    boolean wasUsingPresence = !presenceStates.isEmpty();
    // Remove this field from the form
    options.removeField("FORM_TYPE");
    // Process and remove specific collection node fields
    FormField collectionField = options.getField("pubsub#subscription_type");
    if (collectionField != null) {
        values = collectionField.getValues();
        if (values.size() > 0) {
            type = Type.valueOf(values.get(0));
        }
        options.removeField("pubsub#subscription_type");
    }
    collectionField = options.getField("pubsub#subscription_depth");
    if (collectionField != null) {
        values = collectionField.getValues();
        depth = "all".equals(values.get(0)) ? 0 : 1;
        options.removeField("pubsub#subscription_depth");
    }
    // the subscription has been configured
    for (FormField field : options.getFields()) {
        boolean fieldExists = true;
        if ("pubsub#deliver".equals(field.getVariable())) {
            values = field.getValues();
            booleanValue = (values.size() > 0 ? values.get(0) : "1");
            deliverNotifications = "1".equals(booleanValue);
        } else if ("pubsub#digest".equals(field.getVariable())) {
            values = field.getValues();
            booleanValue = (values.size() > 0 ? values.get(0) : "1");
            usingDigest = "1".equals(booleanValue);
        } else if ("pubsub#digest_frequency".equals(field.getVariable())) {
            values = field.getValues();
            digestFrequency = values.size() > 0 ? Integer.parseInt(values.get(0)) : 86400000;
        } else if ("pubsub#expire".equals(field.getVariable())) {
            values = field.getValues();
            try {
                expire = xmppDateTime.parseString(values.get(0));
            } catch (ParseException e) {
                Log.error("Error parsing date", e);
            }
        } else if ("pubsub#include_body".equals(field.getVariable())) {
            values = field.getValues();
            booleanValue = (values.size() > 0 ? values.get(0) : "1");
            includingBody = "1".equals(booleanValue);
        } else if ("pubsub#show-values".equals(field.getVariable())) {
            // Get the new list of presence states for which an entity wants to
            // receive notifications
            presenceStates = new ArrayList<>();
            for (String value : field.getValues()) {
                try {
                    presenceStates.add(value);
                } catch (Exception e) {
                // Do nothing
                }
            }
        } else if ("x-pubsub#keywords".equals(field.getVariable())) {
            values = field.getValues();
            keyword = values.isEmpty() ? null : values.get(0);
        } else {
            fieldExists = false;
        }
        if (fieldExists) {
            // Subscription has been configured so set the next state
            if (node.getAccessModel().isAuthorizationRequired() && !node.isAdmin(owner)) {
                state = State.pending;
            } else {
                state = State.subscribed;
            }
        }
    }
    if (savedToDB) {
        // Update the subscription in the backend store
        PubSubPersistenceManager.saveSubscription(node, this, false);
    }
    // Check if the service needs to subscribe or unsubscribe from the owner presence
    if (!node.isPresenceBasedDelivery() && wasUsingPresence != !presenceStates.isEmpty()) {
        if (presenceStates.isEmpty()) {
            node.getService().presenceSubscriptionNotRequired(node, owner);
        } else {
            node.getService().presenceSubscriptionRequired(node, owner);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) FormField(org.xmpp.forms.FormField) ParseException(java.text.ParseException)

Example 85 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class ChatTranscriptManager method getTextTranscriptFromSessionID.

/**
     * Return the plain text version of a chat transcript.
     *
     * @param sessionID the sessionID of the <code>ChatSession</code>
     * @return the plain text version of a chat transcript.
     */
public static String getTextTranscriptFromSessionID(String sessionID) {
    String transcript = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GET_SESSION_TRANSCRIPT);
        pstmt.setString(1, sessionID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            transcript = DbConnectionManager.getLargeTextField(rs, 1);
        }
    } catch (Exception ex) {
        Log.error(ex.getMessage(), ex);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    if (transcript == null || "".equals(transcript)) {
        return "";
    }
    // Define time zone used in the transcript.
    SimpleDateFormat UTC_FORMAT = new SimpleDateFormat(XMPPDateTimeFormat.XMPP_DELAY_DATETIME_FORMAT);
    UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
    final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
    Document element = null;
    try {
        element = DocumentHelper.parseText(transcript);
    } catch (DocumentException e) {
        Log.error(e.getMessage(), e);
    }
    StringBuilder buf = new StringBuilder();
    // Add the Messages and Presences contained in the retrieved transcript element
    for (Iterator<Element> it = element.getRootElement().elementIterator(); it.hasNext(); ) {
        Element packet = it.next();
        String name = packet.getName();
        String message = "";
        String from = "";
        if ("presence".equals(name)) {
            String type = packet.attributeValue("type");
            from = new JID(packet.attributeValue("from")).getResource();
            if (type == null) {
                message = from + " has joined the room";
            } else {
                message = from + " has left the room";
            }
        } else if ("message".equals(name)) {
            from = new JID(packet.attributeValue("from")).getResource();
            message = packet.elementText("body");
            message = StringUtils.escapeHTMLTags(message);
        }
        List<Element> el = packet.elements("x");
        for (Element ele : el) {
            if ("jabber:x:delay".equals(ele.getNamespaceURI())) {
                String stamp = ele.attributeValue("stamp");
                try {
                    String formattedDate;
                    synchronized (UTC_FORMAT) {
                        Date d = UTC_FORMAT.parse(stamp);
                        formattedDate = formatter.format(d);
                    }
                    if ("presence".equals(name)) {
                        buf.append("[").append(formattedDate).append("] ").append(message).append("\n");
                    } else {
                        buf.append("[").append(formattedDate).append("] ").append(from).append(": ").append(message).append("\n");
                    }
                } catch (ParseException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
    }
    return buf.toString();
}
Also used : JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) ParseException(java.text.ParseException) Date(java.util.Date) DocumentException(org.dom4j.DocumentException) ResultSet(java.sql.ResultSet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ParseException (java.text.ParseException)1141 Date (java.util.Date)435 SimpleDateFormat (java.text.SimpleDateFormat)387 IOException (java.io.IOException)118 DateFormat (java.text.DateFormat)117 Calendar (java.util.Calendar)104 ArrayList (java.util.ArrayList)98 Test (org.junit.Test)58 HashMap (java.util.HashMap)45 Matcher (java.util.regex.Matcher)39 File (java.io.File)38 GregorianCalendar (java.util.GregorianCalendar)34 Map (java.util.Map)28 BigDecimal (java.math.BigDecimal)23 Timestamp (java.sql.Timestamp)21 List (java.util.List)21 Locale (java.util.Locale)20 SipException (javax.sip.SipException)20 InputStream (java.io.InputStream)19 TimeZone (java.util.TimeZone)19