use of javax.sip.address.SipURI in project camel by apache.
the class SipConfiguration method createContactHeader.
private void createContactHeader() throws ParseException {
SipURI contactURI = addressFactory.createSipURI(getFromUser(), getFromHost());
contactURI.setTransportParam(getTransport());
contactURI.setPort(Integer.valueOf(getFromPort()).intValue());
Address contactAddress = addressFactory.createAddress(contactURI);
// Add the contact address.
contactAddress.setDisplayName(getFromUser());
contactHeader = headerFactory.createContactHeader(contactAddress);
}
use of javax.sip.address.SipURI in project Openfire by igniterealtime.
the class SipCommRouter method getNextHops.
/**
* Return the default address to forward the request to. The list is
* organized in the following priority.
* <p/>
* If the outboung proxy has been specified, then it is used to construct
* the first element of the list.
* <p/>
* If the requestURI refers directly to a host, the host and port
* information are extracted from it and made the next hop on the list.
*
* @param sipRequest is the sip request to route.
*/
public ListIterator<Hop> getNextHops(Request sipRequest) {
URI requestURI = sipRequest.getRequestURI();
if (requestURI == null) {
throw new IllegalArgumentException("Bad message: Null requestURI");
}
LinkedList<Hop> hops = new LinkedList<Hop>();
if (outboundProxy != null) {
hops.add(outboundProxy);
}
ListIterator routes = sipRequest.getHeaders(RouteHeader.NAME);
if (routes != null && routes.hasNext()) {
while (routes.hasNext()) {
RouteHeader route = (RouteHeader) routes.next();
SipURI uri = (SipURI) route.getAddress().getURI();
int port = uri.getPort();
port = (port == -1) ? 5060 : port;
String host = uri.getHost();
Log.debug("getNextHops", host);
String transport = uri.getTransportParam();
if (transport == null) {
transport = "udp";
}
Hop hop = new SipCommHop(host + ':' + port + '/' + transport);
hops.add(hop);
}
} else if (requestURI instanceof SipURI && ((SipURI) requestURI).getMAddrParam() != null) {
SipURI sipURI = ((SipURI) requestURI);
String maddr = sipURI.getMAddrParam();
String transport = sipURI.getTransportParam();
if (transport == null) {
transport = "udp";
}
int port = 5060;
Hop hop = new SipCommHop(maddr, port, transport);
hops.add(hop);
} else if (requestURI instanceof SipURI) {
SipURI sipURI = ((SipURI) requestURI);
int port = sipURI.getPort();
if (port == -1) {
port = 5060;
}
String host = sipURI.getHost();
String transport = sipURI.getTransportParam();
if (transport == null) {
transport = "UDP";
}
Hop hop = new SipCommHop(host + ":" + port + "/" + transport);
hops.add(hop);
} else {
throw new IllegalArgumentException("Malformed requestURI");
}
return (hops.size() == 0) ? null : hops.listIterator();
}
use of javax.sip.address.SipURI in project Openfire by igniterealtime.
the class SipManager method getContactHeader.
/**
* Initialises SipManager's contactHeader field in accordance with
* javax.sip.IP_ADDRESS net.java.mais.sip.DISPLAY_NAME
* net.java.mais.sip.TRANSPORT net.java.mais.sip.PREFERRED_LOCAL_PORT and
* returns a reference to it.
*
* @param useLocalHostAddress specifies whether the SipURI in the contact header should
* contain the value of javax.sip.IP_ADDRESS (true) or that of
* net.java.mais.sip.PUBLIC_ADDRESS (false).
* @return a reference to SipManager's contactHeader field.
* @throws CommunicationsException if a ParseException occurs while initially composing the
* FromHeader.
*/
public ContactHeader getContactHeader(boolean useLocalHostAddress) throws CommunicationsException {
if (contactHeader != null) {
return contactHeader;
}
try {
SipURI contactURI;
if (useLocalHostAddress) {
contactURI = addressFactory.createSipURI(null, UserCredentials.getUserDisplay() + "@" + publicIpAddress.getAddress().getHostAddress());
} else {
contactURI = (SipURI) addressFactory.createURI(currentlyUsedURI);
}
contactURI.setPort(publicIpAddress.getPort());
Address contactAddress = addressFactory.createAddress(contactURI);
if (displayName != null && displayName.trim().length() > 0) {
contactAddress.setDisplayName(displayName);
}
contactHeader = headerFactory.createContactHeader(contactAddress);
} catch (ParseException ex) {
throw new CommunicationsException("A ParseException occurred while creating From Header!", ex);
}
return contactHeader;
}
use of javax.sip.address.SipURI 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.address.SipURI 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;
}
Aggregations