use of javax.sip.header.ContactHeader in project Openfire by igniterealtime.
the class SimpleSession method prepareRequest.
/**
* @param requestType Type of request
* @param destUri The SipURI for the destination. Leave <code>null</code> if a loopback request (e.g. REGISTER) is being made.
* @param toTag The tag for to header. Can leave null.
* @param requestUri The Request URI to set in the message. Leave null if the default destination SipURI should be used.
* @param callId ID of call
* @param seqNum Sequence number
* @return Prepared request
*/
private Request prepareRequest(RequestType requestType, SipURI destUri, String toTag, SipURI requestUri, String callId, long seqNum) {
Request request = null;
String myXMPPUsername = this.jid.getNode();
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing request packet of type '" + requestType + "'");
try {
// Prepare request packet first
request = messageFactory.createRequest(null);
request.setMethod(requestType.toString());
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing request.", e);
}
// Prepare "From" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"From\" header...");
String mySipUsername = registration.getUsername();
try {
SipURI fromUri = addressFactory.createSipURI(mySipUsername, sipHost);
Address fromNameAddress = addressFactory.createAddress(fromUri);
fromNameAddress.setDisplayName(mySipUsername);
FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, getTag());
// Use "set" because this header is mandatory.
request.setHeader(fromHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing FromHeader.", e);
return null;
}
// Prepare "To" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"To\" header...");
try {
if (destUri == null)
destUri = addressFactory.createSipURI(mySipUsername, sipHost);
Address toNameAddress = addressFactory.createAddress(destUri);
ToHeader toHeader = headerFactory.createToHeader(toNameAddress, toTag);
// Use "set" because this header is mandatory.
request.setHeader(toHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing ToHeader.", e);
return null;
}
// Prepare "Via" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"Via\" header...");
try {
ViaHeader viaHeader = headerFactory.createViaHeader(InetAddress.getLocalHost().getHostAddress(), sipPort, ListeningPoint.UDP, null);
// Use "set" because this header is mandatory.
request.setHeader(viaHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing ViaHeader.", e);
return null;
}
// Prepare "CallId" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"CallId\" header...");
CallIdHeader callIdHeader;
try {
if (callId != null)
callIdHeader = headerFactory.createCallIdHeader(callId);
else
callIdHeader = udpSipProvider.getNewCallId();
// Use "set" because this header is mandatory.
request.setHeader(callIdHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing CallIdHeader.", e);
return null;
}
// Prepare "CSeq" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"CSeq\" header...");
try {
CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(seqNum, requestType.toString());
// Use "set" because this header is mandatory.
request.setHeader(cSeqHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing CSeqHeader.", e);
return null;
}
// Prepare "MaxForwards" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"MaxForwards\" header...");
try {
MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
// Use "set" because this header is mandatory.
request.setHeader(maxForwardsHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when preparing MaxForwardsHeader.", e);
return null;
}
// Setting Request URI
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: setting request URI...");
try {
if (requestUri == null) {
requestUri = (SipURI) destUri.clone();
requestUri.setTransportParam(ListeningPoint.UDP);
}
request.setRequestURI(requestUri);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when setting request URI.", e);
return null;
}
// Add "Contact" header
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Preparing \"Contact\" header...");
try {
SipURI contactURI = addressFactory.createSipURI(mySipUsername, InetAddress.getLocalHost().getHostAddress());
contactURI.setPort(sipPort);
Address contactAddress = addressFactory.createAddress(contactURI);
contactAddress.setDisplayName(mySipUsername);
ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
request.setHeader(contactHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest: Exception occured when adding ContactHeader.", e);
return null;
}
return request;
}
use of javax.sip.header.ContactHeader in project Openfire by igniterealtime.
the class SimpleSession method sendResponse.
public ServerTransaction sendResponse(int status, Request request, ServerTransaction serverTransaction) {
try {
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: Starting response sending process.");
if (serverTransaction == null)
serverTransaction = udpSipProvider.getNewServerTransaction(request);
Response response = messageFactory.createResponse(status, request);
// Set "Exprires" header
if (request.getHeader(ExpiresHeader.NAME) != null)
response.setHeader(request.getHeader(ExpiresHeader.NAME));
// Add "Contact" header
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: Preparing \"Contact\" header...");
try {
SipURI contactURI = addressFactory.createSipURI(null, InetAddress.getLocalHost().getHostAddress());
contactURI.setPort(sipPort);
Address contactAddress = addressFactory.createAddress(contactURI);
// contactAddress.setDisplayName(mySipUsername);
ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
response.addHeader(contactHeader);
} catch (Exception e) {
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: Exception occured when adding ContactHeader.", e);
// return false; // We can continue with this though.
}
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: Sending response: " + response.toString());
serverTransaction.sendResponse(response);
// udpSipProvider.sendResponse(response);
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: Response sent!");
return serverTransaction;
} catch (Exception ex) {
Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse: ", ex);
}
return null;
}
use of javax.sip.header.ContactHeader in project XobotOS by xamarin.
the class SipHelper method createWildcardContactHeader.
private ContactHeader createWildcardContactHeader() {
ContactHeader contactHeader = mHeaderFactory.createContactHeader();
contactHeader.setWildCard();
return contactHeader;
}
use of javax.sip.header.ContactHeader in project jain-sip.ha by RestComm.
the class SIPDialogCacheData method updateDialogMetaData.
/**
* Update the haSipDialog passed in param with the dialogMetaData and app meta data
* @param dialogMetaData
* @param dialogAppData
* @param haSipDialog
* @throws ParseException
* @throws PeerUnavailableException
*/
private void updateDialogMetaData(Map<String, Object> dialogMetaData, Object dialogAppData, HASipDialog haSipDialog, boolean recreation) throws ParseException, PeerUnavailableException {
haSipDialog.setMetaDataToReplicate(dialogMetaData, recreation);
haSipDialog.setApplicationDataToReplicate(dialogAppData);
final String contactStringified = (String) dialogMetaData.get(AbstractHASipDialog.CONTACT_HEADER);
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("contactStringified " + contactStringified);
}
if (contactStringified != null) {
Address contactAddress = SipFactory.getInstance().createAddressFactory().createAddress(contactStringified);
ContactHeader contactHeader = SipFactory.getInstance().createHeaderFactory().createContactHeader(contactAddress);
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("contactHeader " + contactHeader);
clusteredlogger.logDebug("contactURI " + contactHeader.getAddress().getURI());
}
haSipDialog.setContactHeader(contactHeader);
}
}
use of javax.sip.header.ContactHeader in project jain-sip.ha by RestComm.
the class SIPDialogCacheData method updateDialogMetaData.
/**
* Update the haSipDialog passed in param with the dialogMetaData and app meta data
* @param dialogMetaData
* @param dialogAppData
* @param haSipDialog
* @throws ParseException
* @throws PeerUnavailableException
*/
private void updateDialogMetaData(Map<String, Object> dialogMetaData, Object dialogAppData, HASipDialog haSipDialog, boolean recreation) throws ParseException, PeerUnavailableException {
haSipDialog.setMetaDataToReplicate(dialogMetaData, recreation);
haSipDialog.setApplicationDataToReplicate(dialogAppData);
final String contactStringified = (String) dialogMetaData.get(AbstractHASipDialog.CONTACT_HEADER);
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("contactStringified " + contactStringified);
}
if (contactStringified != null) {
Address contactAddress = SipFactory.getInstance().createAddressFactory().createAddress(contactStringified);
ContactHeader contactHeader = SipFactory.getInstance().createHeaderFactory().createContactHeader(contactAddress);
if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
clusteredlogger.logDebug("contactHeader " + contactHeader);
clusteredlogger.logDebug("contactURI " + contactHeader.getAddress().getURI());
}
haSipDialog.setContactHeader(contactHeader);
}
}
Aggregations