[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi/impl AGIRequestImpl.java,1.4
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-07-23 08:27:35
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8632/src/java/net/sf/asterisk/fastagi/impl Modified Files: AGIRequestImpl.java Log Message: Changed use of deprecated encode/decode methods Index: AGIRequestImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/impl/AGIRequestImpl.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- AGIRequestImpl.java 15 Apr 2005 04:47:00 -0000 1.4 +++ AGIRequestImpl.java 23 Jul 2005 08:27:27 -0000 1.5 @@ -17,6 +17,7 @@ package net.sf.asterisk.fastagi.impl; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collection; @@ -29,6 +30,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import net.sf.asterisk.fastagi.AGIRequest; +import net.sf.asterisk.util.Log; +import net.sf.asterisk.util.LogFactory; /** * Default implementation of the AGIRequest interface. @@ -38,6 +41,7 @@ import net.sf.asterisk.fastagi.AGIReques */ public class AGIRequestImpl implements Serializable, AGIRequest { + private final Log logger = LogFactory.getLog(getClass()); private static final Pattern SCRIPT_PATTERN = Pattern .compile("^([^\\?]*)\\?(.*)$"); private static final Pattern PARAMETER_PATTERN = Pattern @@ -58,6 +62,11 @@ public class AGIRequestImpl implements S */ private Map parameterMap; + private String parameters; + private String script; + + private boolean callerIdCreated; + /** * Creates a new AGIRequestImpl. */ @@ -142,10 +151,13 @@ public class AGIRequestImpl implements S * * @return the name of the script to execute. */ - public String getScript() + public synchronized String getScript() { if (script != null) + { return script; + } + script = (String) request.get("network_script"); if (script != null) { @@ -156,6 +168,7 @@ public class AGIRequestImpl implements S parameters = scriptMatcher.group(2); } } + return script; } @@ -211,8 +224,6 @@ public class AGIRequestImpl implements S return (String) request.get("language"); } - private boolean callerIdCreated; - public String getCallerId() { int lbPosition; @@ -223,7 +234,7 @@ public class AGIRequestImpl implements S rawCallerId = (String) request.get("callerid"); callerIdCreated = true; } - + if (rawCallerId == null) { return null; @@ -250,7 +261,7 @@ public class AGIRequestImpl implements S rawCallerId = (String) request.get("callerid"); callerIdCreated = true; } - + if (rawCallerId == null) { return null; @@ -386,7 +397,7 @@ public class AGIRequestImpl implements S return (String[]) parameterMap.get(name); } - public Map getParameterMap() + public synchronized Map getParameterMap() { if (parameterMap == null) { @@ -395,10 +406,13 @@ public class AGIRequestImpl implements S return parameterMap; } - private String parameters; - private String script; - - private Map parseParameters(String s) + /** + * Parses the given parameter string and caches the result. + * + * @param s the parameter string to parse + * @return a Map made up of parameter names their values + */ + private synchronized Map parseParameters(String s) { Map parameterMap; Map result; @@ -424,13 +438,33 @@ public class AGIRequestImpl implements S parameterMatcher = PARAMETER_PATTERN.matcher(parameter); if (parameterMatcher.matches()) { - name = URLDecoder.decode(parameterMatcher.group(1)); - value = URLDecoder.decode(parameterMatcher.group(2)); + try + { + name = URLDecoder + .decode(parameterMatcher.group(1), "UTF-8"); + value = URLDecoder.decode(parameterMatcher.group(2), + "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + logger.error("Unable to decode parameter '" + parameter + + "'", e); + continue; + } } else { - name = URLDecoder.decode(parameter); - value = ""; + try + { + name = URLDecoder.decode(parameter, "UTF-8"); + value = ""; + } + catch (UnsupportedEncodingException e) + { + logger.error("Unable to decode parameter '" + parameter + + "'", e); + continue; + } } if (parameterMap.get(name) == null) |