Skip to content

Commit

Permalink
RESTCOMM-884: Move rcmlHeaders instantiation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulazizali77 committed Jun 12, 2017
1 parent 764f12f commit 1eecc8d
Showing 1 changed file with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ public void execute(Object message) throws Exception {
// custom headers parsing for SIP Out
// https://bitbucket.org/telestax/telscale-restcomm/issue/132/implement-twilio-sip-out
rcmlHeaders = new HashMap<String, String>();
addCustomHeadersToMap(rcmlHeaders);
addHeadersToMessage(invite, rcmlHeaders, "X-");

// we keep only the to URI without the headers
to = (SipURI) factory.createURI(toHeaderString.substring(0, toHeaderString.lastIndexOf('?')));
String headersString = toHeaderString.substring(toHeaderString.lastIndexOf('?') + 1);
Expand Down Expand Up @@ -906,6 +909,24 @@ public void execute(Object message) throws Exception {
}
}
}

/**
* addCustomHeadersToMap
*/
private void addCustomHeadersToMap(Map<String, String> headers) {
if (apiVersion != null)
headers.put("RestComm-ApiVersion", apiVersion);
if (accountId != null)
headers.put("RestComm-AccountSid", accountId.toString());
headers.put("RestComm-CallSid", instanceId+"-"+id.toString());
}

private void addHeadersToMessage(SipServletRequest message, Map<String, String> headers, String keyPrepend) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
String headerName = keyPrepend + entry.getKey();
message.addHeader(headerName , entry.getValue());
}
}
}

private final class Dialing extends AbstractAction {
Expand Down Expand Up @@ -964,11 +985,6 @@ public void execute(Object message) throws Exception {
invite.setHeader("User-Agent", userAgent);
}

addCustomHeadersToMap(rcmlHeaders);
// adding custom headers for SIP Out
// https://bitbucket.org/telestax/telscale-restcomm/issue/132/implement-twilio-sip-out
addHeadersToMessage(invite, rcmlHeaders, "X-");

//the extension headers will override any headers
addHeadersToMessage(invite, extensionHeaders);

Expand Down Expand Up @@ -1002,26 +1018,6 @@ public void execute(Object message) throws Exception {
executeStatusCallback(CallbackState.INITIATED);
}

//FIXME: duplicate code
private void addHeadersToMessage(SipServletRequest message, Map<String, String> rcmlHeaders, String keyPrepend) {

for (Map.Entry<String, String> entry : rcmlHeaders.entrySet()) {
String headerName = keyPrepend + entry.getKey();
message.addHeader(headerName , entry.getValue());
}
}

/**
* addCustomHeadersToMap
*/
private void addCustomHeadersToMap(Map<String, String> headers) {
if (apiVersion != null)
headers.put("RestComm-ApiVersion", apiVersion);
if (accountId != null)
headers.put("RestComm-AccountSid", accountId.toString());
headers.put("RestComm-CallSid", instanceId+"-"+id.toString());
}

/**
* Replace headers
* @param SipServletRequest message
Expand Down

0 comments on commit 1eecc8d

Please sign in to comment.