Source:
private void addHeadersToMessage(SipServletRequest message, Map<String, ArrayList<String> > headers) { if(headers!=null) { for (Map.Entry<String, ArrayList<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); StringBuilder sb = new StringBuilder(); if(entry.getValue() instanceof ArrayList){ for(String pair : entry.getValue()){ sb.append(";").append(pair); } } if(logger.isDebugEnabled()) { logger.debug("headerName="+headerName+" headerVal="+message.getHeader(headerName)+" concatValue="+sb.toString()); } if(!headerName.equalsIgnoreCase("Request-URI")){ String headerVal = message.getHeader(headerName); if(headerVal!=null && !headerVal.isEmpty()) { message.setHeader(headerName , headerVal+sb.toString()); }else{ message.addHeader(headerName , sb.toString()); } }else{ javax.servlet.sip.URI reqURI = message.getRequestURI(); if(logger.isDebugEnabled()) { logger.debug("ReqURI="+reqURI.toString()+" msgReqURI="+message.getRequestURI()); } for(String keyValPair :entry.getValue()){ String parName = ""; String parVal = ""; int equalsPos = keyValPair.indexOf("="); parName = keyValPair.substring(0, equalsPos); parVal = keyValPair.substring(equalsPos+1); reqURI.setParameter(parName, parVal); if(logger.isDebugEnabled()) { logger.debug("ReqURI pars ="+parName+"="+parVal+" equalsPos="+equalsPos+" keyValPair="+keyValPair); } } message.setRequestURI(reqURI); if(logger.isDebugEnabled()) { logger.debug("ReqURI="+reqURI.toString()+" msgReqURI="+message.getRequestURI()); } } if(logger.isDebugEnabled()) { logger.debug("headerName="+headerName+" headerVal="+message.getHeader(headerName)); } } } }

Target:
private void addHeadersToMessage(SipServletRequest message, Map<String, ArrayList<String> > headers) { if(headers!=null) { for (Map.Entry<String, ArrayList<String>> entry : headers.entrySet()) { String headerName = entry.getKey(); StringBuilder sb = new StringBuilder(); if(entry.getValue() instanceof ArrayList){ for(String pair : entry.getValue()){ sb.append(";").append(pair); } } if(logger.isDebugEnabled()) { logger.debug("headerName="+headerName+" headerVal="+message.getHeader(headerName)+" concatValue="+sb.toString()); } if(!headerName.equalsIgnoreCase("Request-URI")){ try { String headerVal = message.getHeader(headerName); if(headerVal!=null && !headerVal.isEmpty()) { message.setHeader(headerName , headerVal+sb.toString()); }else{ message.addHeader(headerName , sb.toString()); } } catch (IllegalArgumentException iae) { if(logger.isErrorEnabled()) { logger.error("Exception while setting message header: "+iae.getMessage()); } } }else{ javax.servlet.sip.URI reqURI = message.getRequestURI(); if(logger.isDebugEnabled()) { logger.debug("ReqURI="+reqURI.toString()+" msgReqURI="+message.getRequestURI()); } for(String keyValPair :entry.getValue()){ String parName = ""; String parVal = ""; int equalsPos = keyValPair.indexOf("="); parName = keyValPair.substring(0, equalsPos); parVal = keyValPair.substring(equalsPos+1); reqURI.setParameter(parName, parVal); if(logger.isDebugEnabled()) { logger.debug("ReqURI pars ="+parName+"="+parVal+" equalsPos="+equalsPos+" keyValPair="+keyValPair); } } message.setRequestURI(reqURI); if(logger.isDebugEnabled()) { logger.debug("ReqURI="+reqURI.toString()+" msgReqURI="+message.getRequestURI()); } } if(logger.isDebugEnabled()) { logger.debug("headerName="+headerName+" headerVal="+message.getHeader(headerName)); } } } }