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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations