Search in sources :

Example 21 with Request

use of javax.sip.message.Request in project Openfire by igniterealtime.

the class SimpleSession method sendNotify.

public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
    Request notifyRequest = prepareNotifyRequest(dialog);
    try {
        User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
        Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
        String presenceContent;
        SimplePresence simplePresence = new SimplePresence();
        simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
        simplePresence.setDmNote(myPresence.getStatus());
        if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
        else {
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
            if (myPresence.getShow() != null) {
                switch(myPresence.getShow()) {
                    case away:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    case dnd:
                        simplePresence.setRpid(SimplePresence.Rpid.BUSY);
                        break;
                    case xa:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    default:
                        break;
                }
            }
        }
        presenceContent = simplePresence.toXML();
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
        notifyRequest.setContent(presenceContent, contentTypeHeader);
    } catch (Exception e) {
        Log.debug("Unable to include presence details in the packet.", e);
    }
    sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
Also used : User(org.jivesoftware.openfire.user.User) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 22 with Request

use of javax.sip.message.Request in project Openfire by igniterealtime.

the class SimpleSession method prepareNotifyRequest.

private Request prepareNotifyRequest(Dialog dialog) throws ParseException {
    if (dialog == null) {
        return null;
    }
    printDialog(dialog);
    String fromTag = dialog.getRemoteTag();
    Address fromAddress = dialog.getRemoteParty();
    SipURI destUri = (SipURI) fromAddress.getURI();
    dialog.incrementLocalSequenceNumber();
    long seqNum = dialog.getLocalSeqNumber();
    String callId = dialog.getCallId().getCallId();
    SipURI fromReqUri = null;
    Log.debug("Getting request URI from dialog");
    Address fromReqAddr = dialog.getRemoteTarget();
    if (fromReqAddr != null && fromReqAddr.getURI() != null && fromReqAddr.getURI() instanceof SipURI)
        fromReqUri = (SipURI) fromReqAddr.getURI();
    if (fromReqUri == null) {
        Log.debug("Getting request URI from destination URI");
        fromReqUri = destUri;
    }
    // Instantiate request packet
    Request notifyRequest = prepareRequest(RequestType.NOTIFY, destUri, fromTag, fromReqUri, callId, seqNum);
    //		Request notifyRequest = dialog.createRequest(Request.NOTIFY);
    ((FromHeader) notifyRequest.getHeader(FromHeader.NAME)).setTag(dialog.getLocalTag());
    // Set "subscription state" header
    SubscriptionStateHeader subscriptionStateHeader = headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE.toLowerCase());
    //		if (expires > 0) subscriptionStateHeader.setExpires(expires);
    notifyRequest.setHeader(subscriptionStateHeader);
    // Set "event" header
    notifyRequest.setHeader(headerFactory.createEventHeader("presence"));
    return notifyRequest;
}
Also used : InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Example 23 with Request

use of javax.sip.message.Request in project Openfire by igniterealtime.

the class SimpleSession method cleanUp.

/**
     * @see net.sf.kraken.session.TransportSession#cleanUp()
     */
@Override
public void cleanUp() {
    Request registerRequest = prepareRegisterRequest();
    // Lots of logout work here...
    Log.debug("SimpleSession(" + getJID().getNode() + ").logout:  Preparing logout packet...");
    try {
        registerRequest.addHeader(headerFactory.createExpiresHeader(0));
        sendRequest(registerRequest, ListeningPoint.UDP);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + jid.getNode() + ").login:  Unable to logout.", e);
    }
//		List<Header> customHeaders = new ArrayList<Header>(1);
//		try { customHeaders.add(headerFactory.createExpiresHeader(0)); }
//		catch (Exception e) {
//			Log.debug("SimpleSession(" + getJID().getNode() + ").logout:  " +
//			          "Unable to set the expiry interval, which is essential for a logout.", e);
//			return;
//		}
//		String myUsername = registration.getUsername();
//		if (myUsername.indexOf("sip:") < 0) myUsername = "sip:" + myUsername;
//		if (myUsername.indexOf("@")    < 0) myUsername = myUsername + "@" + sipHost;
//
//		prepareRequest(RequestType.REGISTER, myUsername, null, this.sessionId, seqNum++, 70, customHeaders, null);
}
Also used : Request(javax.sip.message.Request) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 24 with Request

use of javax.sip.message.Request in project Openfire by igniterealtime.

the class SimpleSession method prepareMessageRequest.

private Request prepareMessageRequest(MessageContent content, String destination) throws InvalidArgumentException, ParseException {
    String destUsername = destination;
    String destHost = sipHost;
    if (destination.indexOf("@") == 0 || destination.indexOf("@") == destination.length() - 1) {
        throw new InvalidArgumentException("The address provided is invalid!");
    } else if (destination.indexOf("@") > 0) {
        destUsername = destination.substring(0, destination.indexOf("@"));
        destHost = destination.substring(destination.indexOf("@") + 1);
    }
    SipURI destUri = addressFactory.createSipURI(destUsername, destHost);
    Request messageRequest = prepareRequest(RequestType.MESSAGE, destUri, null, destUri, sessionId, seqNum++);
    messageRequest.setContent(content.content, content.contentTypeHeader);
    return messageRequest;
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Example 25 with Request

use of javax.sip.message.Request in project camel by apache.

the class SipPresenceAgentListener method sendNotification.

private void sendNotification(EventHeader eventHeader, boolean isInitial, Object body) throws SipException, ParseException {
    /*
         * NOTIFY requests MUST contain a "Subscription-State" header with a
         * value of "active", "pending", or "terminated". The "active" value
         * indicates that the subscription has been accepted and has been
         * authorized (in most cases; see section 5.2.). The "pending" value
         * indicates that the subscription has been received, but that
         * policy information is insufficient to accept or deny the
         * subscription at this time. The "terminated" value indicates that
         * the subscription is not active.
         */
    Request notifyRequest = dialog.createRequest("NOTIFY");
    // Mark the contact header, to check that the remote contact is updated
    ((SipURI) sipPresenceAgent.getConfiguration().getContactHeader().getAddress().getURI()).setParameter(sipPresenceAgent.getConfiguration().getFromUser(), sipPresenceAgent.getConfiguration().getFromHost());
    SubscriptionStateHeader sstate;
    if (isInitial) {
        // Initial state is pending, second time we assume terminated (Expires==0)
        sstate = sipPresenceAgent.getConfiguration().getHeaderFactory().createSubscriptionStateHeader(isInitial ? SubscriptionStateHeader.PENDING : SubscriptionStateHeader.TERMINATED);
        // Need a reason for terminated
        if (sstate.getState().equalsIgnoreCase("terminated")) {
            sstate.setReasonCode("deactivated");
        }
    } else {
        sstate = sipPresenceAgent.getConfiguration().getHeaderFactory().createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
    }
    notifyRequest.addHeader(sstate);
    notifyRequest.setHeader(eventHeader);
    notifyRequest.setHeader(sipPresenceAgent.getConfiguration().getContactHeader());
    notifyRequest.setContent(body, sipPresenceAgent.getConfiguration().getContentTypeHeader());
    LOG.debug("Sending the following NOTIFY request to Subscriber: {}", notifyRequest);
    ClientTransaction clientTransactionId = sipPresenceAgent.getProvider().getNewClientTransaction(notifyRequest);
    dialog.sendRequest(clientTransactionId);
}
Also used : SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Aggregations

Request (javax.sip.message.Request)38 ParseException (java.text.ParseException)21 SipException (javax.sip.SipException)21 InvalidArgumentException (javax.sip.InvalidArgumentException)13 ClientTransaction (javax.sip.ClientTransaction)9 SipURI (javax.sip.address.SipURI)9 Response (javax.sip.message.Response)9 NotFoundException (org.jivesoftware.util.NotFoundException)7 TooManyListenersException (java.util.TooManyListenersException)6 ServerTransaction (javax.sip.ServerTransaction)6 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 Address (javax.sip.address.Address)5 CSeqHeader (javax.sip.header.CSeqHeader)5 ViaHeader (javax.sip.header.ViaHeader)5 SIPRequest (gov.nist.javax.sip.message.SIPRequest)4 FromHeader (javax.sip.header.FromHeader)4 SubscriptionStateHeader (javax.sip.header.SubscriptionStateHeader)4 ToHeader (javax.sip.header.ToHeader)4 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 IOException (java.io.IOException)3