use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method getMessageAsEncodedStrings.
/**
* Get the headers as a linked list of encoded Strings
*
* @return a linked list with each element of the list containing a string encoded header in
* canonical form.
*/
public LinkedList<String> getMessageAsEncodedStrings() {
LinkedList<String> retval = new LinkedList<String>();
Iterator<SIPHeader> li = headers.iterator();
while (li.hasNext()) {
SIPHeader sipHeader = (SIPHeader) li.next();
if (sipHeader instanceof SIPHeaderList) {
SIPHeaderList<?> shl = (SIPHeaderList<?>) sipHeader;
retval.addAll(shl.getHeadersAsEncodedStrings());
} else {
retval.add(sipHeader.encode());
}
}
return retval;
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method setHeader.
/**
* Attach a header (replacing the original header).
*
* @param sipHeader SIPHeader that replaces a header of the same type.
*/
public void setHeader(Header sipHeader) {
SIPHeader header = (SIPHeader) sipHeader;
if (header == null)
throw new IllegalArgumentException("null header!");
try {
if (header instanceof SIPHeaderList) {
SIPHeaderList<?> hl = (SIPHeaderList<?>) header;
// Ignore empty lists.
if (hl.isEmpty())
return;
}
this.removeHeader(header.getHeaderName());
attachHeader(header, true, false);
} catch (SIPDuplicateHeaderException ex) {
InternalErrorHandler.handleException(ex);
}
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method merge.
/**
* Merge a request with a template
*
* @param template -- template to merge with.
*
*/
public void merge(Object template) {
if (!template.getClass().equals(this.getClass()))
throw new IllegalArgumentException("Bad class " + template.getClass());
SIPMessage templateMessage = (SIPMessage) template;
Object[] templateHeaders = templateMessage.headers.toArray();
for (int i = 0; i < templateHeaders.length; i++) {
SIPHeader hdr = (SIPHeader) templateHeaders[i];
String hdrName = hdr.getHeaderName();
List<SIPHeader> myHdrs = this.getHeaderList(hdrName);
if (myHdrs == null) {
this.attachHeader(hdr);
} else {
ListIterator<SIPHeader> it = myHdrs.listIterator();
while (it.hasNext()) {
SIPHeader sipHdr = (SIPHeader) it.next();
sipHdr.merge(hdr);
}
}
}
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method match.
/**
* Template match for SIP messages. The matchObj is a SIPMessage template to match against.
* This method allows you to do pattern matching with incoming SIP messages. Null matches wild
* card.
*
* @param other is the match template to match against.
* @return true if a match occured and false otherwise.
*/
public boolean match(Object other) {
if (other == null)
return true;
if (!other.getClass().equals(this.getClass()))
return false;
SIPMessage matchObj = (SIPMessage) other;
Iterator<SIPHeader> li = matchObj.getHeaders();
while (li.hasNext()) {
SIPHeader hisHeaders = (SIPHeader) li.next();
List<SIPHeader> myHeaders = this.getHeaderList(hisHeaders.getHeaderName());
// Could not find a header to match his header.
if (myHeaders == null || myHeaders.size() == 0)
return false;
if (hisHeaders instanceof SIPHeaderList) {
ListIterator<?> outerIterator = ((SIPHeaderList<?>) hisHeaders).listIterator();
while (outerIterator.hasNext()) {
SIPHeader hisHeader = (SIPHeader) outerIterator.next();
if (hisHeader instanceof ContentLength)
continue;
ListIterator<?> innerIterator = myHeaders.listIterator();
boolean found = false;
while (innerIterator.hasNext()) {
SIPHeader myHeader = (SIPHeader) innerIterator.next();
if (myHeader.match(hisHeader)) {
found = true;
break;
}
}
if (!found)
return false;
}
} else {
SIPHeader hisHeader = hisHeaders;
ListIterator<SIPHeader> innerIterator = myHeaders.listIterator();
boolean found = false;
while (innerIterator.hasNext()) {
SIPHeader myHeader = (SIPHeader) innerIterator.next();
if (myHeader.match(hisHeader)) {
found = true;
break;
}
}
if (!found)
return false;
}
}
return true;
}
use of gov.nist.javax.sip.header.SIPHeader in project load-balancer by RestComm.
the class WorstCaseUdpTestAffinityAlgorithm method processExternalResponse.
public void processExternalResponse(Response response, Boolean isIpV6) {
Via via = (Via) response.getHeader(Via.NAME);
String transport = via.getTransport().toLowerCase();
String host = via.getHost();
boolean found = false;
// for(Node node : invocationContext.nodes) {
for (Node node : invocationContext.sipNodeMap(isIpV6).values()) {
if (node.getIp().equals(host))
found = true;
}
if (!found) {
String callId = ((SIPHeader) response.getHeader(headerName)).getValue();
Node node = callIdMap.get(callId);
// if(node == null || !invocationContext.nodes.contains(node)) {
if (node == null || !invocationContext.sipNodeMap(isIpV6).containsValue(node)) {
node = selectNewNode(node, callId);
try {
via.setHost(node.getIp());
String transportProperty = transport.toLowerCase() + "Port";
Integer port = Integer.parseInt(node.getProperties().get(transportProperty));
if (port == null)
throw new RuntimeException("No transport found for node " + node + " " + transportProperty);
via.setPort(port);
} catch (Exception e) {
throw new RuntimeException("Error", e);
}
if (!ListeningPoint.UDP.equalsIgnoreCase(transport)) {
via.setRPort();
}
}
} else {
if (earlyDialogWorstCase && response.getStatusCode() > 100) {
String callId = ((SIPHeader) response.getHeader(headerName)).getValue();
Node node = callIdMap.get(callId);
for (int q = 0; q < 3; q++) {
Node other = selectNewNode(node, callId);
if (other != null && !other.equals(node)) {
node = other;
break;
}
}
try {
via.setHost(node.getIp());
String transportProperty = transport.toLowerCase() + "Port";
Integer port = Integer.parseInt(node.getProperties().get(transportProperty));
if (port == null)
throw new RuntimeException("No transport found for node " + node + " " + transportProperty);
via.setPort(port);
} catch (Exception e) {
throw new RuntimeException("Error", e);
}
if (!ListeningPoint.UDP.equalsIgnoreCase(transport)) {
via.setRPort();
}
}
}
}
Aggregations