super.addGeneralHeaders(headers);
}
@Override
protected void addRequestHeaders(Series<Parameter> headers) {
SipRequest sipRequest = null;
if (getMessage().getRequest() instanceof SipRequest) {
sipRequest = (SipRequest) getMessage().getRequest();
if (sipRequest.getCallId() != null) {
headers.add(SipConstants.HEADER_CALL_ID, sipRequest.getCallId());
}
if (sipRequest.getCommandSequence() != null) {
headers.add(SipConstants.HEADER_CALL_SEQ,
sipRequest.getCommandSequence());
}
if (sipRequest.getFrom() != null) {
headers.add(HeaderConstants.HEADER_FROM,
AddressWriter.write(sipRequest.getFrom()));
}
if (sipRequest.getTo() != null) {
headers.add(SipConstants.HEADER_TO,
AddressWriter.write(sipRequest.getTo()));
}
if (sipRequest.getAlertInfo() != null) {
headers.add(SipConstants.HEADER_ALERT_INFO,
AddressWriter.write(sipRequest.getAlertInfo()));
}
if (!sipRequest.getAllowedEventTypes().isEmpty()) {
headers.add(SipConstants.HEADER_ALLOW_EVENTS, EventTypeWriter
.write(sipRequest.getAllowedEventTypes()));
}
if (!sipRequest.getCallerInfo().isEmpty()) {
headers.add(SipConstants.HEADER_CALL_INFO,
AddressWriter.write(sipRequest.getCallerInfo()));
}
if (!sipRequest.getContacts().isEmpty()) {
headers.add(SipConstants.HEADER_CONTACT,
ContactInfoWriter.write(sipRequest.getContacts()));
}
if (sipRequest.getEvent() != null) {
headers.add(SipConstants.HEADER_EVENT,
EventWriter.write(sipRequest.getEvent()));
}
if (sipRequest.getMimeVersion() != null) {
headers.add(SipConstants.HEADER_MIME_VERSION,
sipRequest.getMimeVersion());
}
if (sipRequest.getOrganization() != null) {
headers.add(SipConstants.HEADER_ORGANIZATION,
sipRequest.getOrganization());
}
if (!sipRequest.getRecordedRoutes().isEmpty()) {
headers.add(SipConstants.HEADER_RECORD_ROUTE,
AddressWriter.write(sipRequest.getRecordedRoutes()));
}
if (sipRequest.getReplyTo() != null) {
headers.add(SipConstants.HEADER_REPLY_TO,
AddressWriter.write(sipRequest.getReplyTo()));
}
if (!sipRequest.getSupported().isEmpty()) {
headers.add(SipConstants.HEADER_SUPPORTED,
OptionTagWriter.write(sipRequest.getSupported()));
}
if (!sipRequest.getInReplyTo().isEmpty()) {
StringBuilder sb = new StringBuilder(sipRequest.getInReplyTo()
.get(0));
for (int i = 1; i < sipRequest.getInReplyTo().size(); i++) {
sb.append(",").append(sipRequest.getInReplyTo().get(i));
}
headers.add(SipConstants.HEADER_IN_REPLY_TO, sb.toString());
}
if (sipRequest.getPriority() != null) {
headers.add(SipConstants.HEADER_PRIORITY, sipRequest
.getPriority().getValue());
}
if (!sipRequest.getProxyRequires().isEmpty()) {
headers.add(SipConstants.HEADER_PROXY_REQUIRE,
OptionTagWriter.write(sipRequest.getProxyRequires()));
}
if (sipRequest.getReferTo() != null) {
headers.add(SipConstants.HEADER_REFER_TO,
AddressWriter.write(sipRequest.getReferTo()));
}
if (!sipRequest.getRequires().isEmpty()) {
headers.add(SipConstants.HEADER_REQUIRE,
OptionTagWriter.write(sipRequest.getProxyRequires()));
}
if (!sipRequest.getRoutes().isEmpty()) {
headers.add(SipConstants.HEADER_ROUTE,
AddressWriter.write(sipRequest.getRoutes()));
}
if (sipRequest.getSipIfMatch() != null) {
headers.add(HeaderConstants.HEADER_IF_MATCH,
TagWriter.write(sipRequest.getSipIfMatch()));
}
if (sipRequest.getSubject() != null) {
headers.add(SipConstants.HEADER_SUBJECT,
sipRequest.getSubject());
}
if (sipRequest.getSubscriptionState() != null) {
headers.add(SipConstants.HEADER_SUBSCRIPTION_STATE,
SubscriptionWriter.write(sipRequest
.getSubscriptionState()));
}
}
super.addRequestHeaders(headers);