3434import com .tomtom .speedtools .tracer .Traceable ;
3535import com .tomtom .speedtools .tracer .TracerFactory ;
3636import com .tomtom .speedtools .utils .MathUtils ;
37+ import com .tomtom .speedtools .utils .StringUtils ;
3738import org .apache .commons .text .StringEscapeUtils ;
3839import org .joda .time .DateTime ;
3940import org .slf4j .Logger ;
@@ -105,9 +106,9 @@ public void convertLatLonToMapcode(
105106
106107 @ Override
107108 public void convertLatLonToMapcode (
108- final double paramLatDeg ,
109- final double paramLonDeg ,
110- final int paramPrecision ,
109+ @ Nullable final String paramLatDegAsString ,
110+ @ Nullable final String paramLonDegAsString ,
111+ @ Nullable final String paramPrecisionAsString ,
111112 @ Nullable final String paramTerritory ,
112113 @ Nullable final String paramCountry ,
113114 @ Nullable final String paramContextMustBeNull ,
@@ -116,17 +117,17 @@ public void convertLatLonToMapcode(
116117 @ Nonnull final String paramClient ,
117118 @ Nonnull final String paramAllowLog ,
118119 @ Nonnull final AsyncResponse response ) throws ApiInvalidFormatException {
119- convertLatLonToMapcode (paramLatDeg , paramLonDeg , null , paramPrecision , paramTerritory , paramCountry ,
120+ convertLatLonToMapcode (paramLatDegAsString , paramLonDegAsString , null , paramPrecisionAsString , paramTerritory , paramCountry ,
120121 paramContextMustBeNull , paramAlphabet , paramInclude , paramClient , paramAllowLog , response );
121122 }
122123
123124 @ SuppressWarnings ("NestedTryStatement" )
124125 @ Override
125126 public void convertLatLonToMapcode (
126- final double paramLatDeg ,
127- final double paramLonDeg ,
127+ @ Nullable final String paramLatDegAsString ,
128+ @ Nullable final String paramLonDegAsString ,
128129 @ Nullable final String paramType ,
129- final int paramPrecision ,
130+ @ Nullable final String paramPrecisionAsString ,
130131 @ Nullable final String paramTerritory ,
131132 @ Nullable final String paramCountry ,
132133 @ Nullable final String paramContextMustBeNull ,
@@ -142,7 +143,7 @@ public void convertLatLonToMapcode(
142143 final boolean allowLog = "true" .equalsIgnoreCase (paramAllowLog );
143144
144145 LOG .info ("convertLatLonToMapcode: lat={}, lon={}, precision={}, type={}, context={}, alphabet={}, include={}, client={}, allowLog={}" ,
145- paramLatDeg , paramLonDeg , paramPrecision , paramType , paramTerritory , paramAlphabet , paramInclude , paramClient , paramAllowLog );
146+ paramLatDegAsString , paramLonDegAsString , paramPrecisionAsString , paramType , paramTerritory , paramAlphabet , paramInclude , paramClient , paramAllowLog );
146147 metricsCollector .addOneLatLonToMapcodeRequest (paramClient );
147148
148149 // Prevent 'context' from inadvertently being specified.
@@ -151,19 +152,35 @@ public void convertLatLonToMapcode(
151152 }
152153
153154 // Check lat range.
154- final double latDeg = paramLatDeg ;
155- if (!MathUtils .isBetween (latDeg , ApiConstants .API_LAT_MIN , ApiConstants .API_LAT_MAX )) {
156- throw new ApiInvalidFormatException (PARAM_LAT_DEG , String .valueOf (paramLatDeg ),
155+ final double latDeg ;
156+ try {
157+ latDeg = Double .valueOf (StringUtils .nullToEmpty (paramLatDegAsString ));
158+ if (!MathUtils .isBetween (latDeg , ApiConstants .API_LAT_MIN , ApiConstants .API_LAT_MAX )) {
159+ throw new NumberFormatException (paramLatDegAsString );
160+ }
161+ } catch (final NumberFormatException e ) {
162+ throw new ApiInvalidFormatException (PARAM_LAT_DEG , paramLatDegAsString ,
157163 "[" + ApiConstants .API_LAT_MIN + ", " + ApiConstants .API_LAT_MAX + ']' );
158164 }
159165
166+
160167 // Check lon range.
161- final double lonDeg = Geo .mapToLon (paramLonDeg );
168+ final double lonDeg ;
169+ try {
170+ lonDeg = Geo .mapToLon (Double .valueOf (StringUtils .nullToEmpty (paramLonDegAsString )));
171+ } catch (final NumberFormatException e ) {
172+ throw new ApiInvalidFormatException (PARAM_LAT_DEG , paramLonDegAsString , "Double" );
173+ }
162174
163175 // Check precision.
164- final int precision = paramPrecision ;
165- if (!MathUtils .isBetween (precision , ApiConstants .API_PRECISION_MIN , ApiConstants .API_PRECISION_MAX )) {
166- throw new ApiInvalidFormatException (PARAM_PRECISION , String .valueOf (paramPrecision ), "[" + ApiConstants .API_PRECISION_MIN +
176+ final int precision ;
177+ try {
178+ precision = Integer .valueOf (StringUtils .nullToEmpty (paramPrecisionAsString ));
179+ if (!MathUtils .isBetween (precision , ApiConstants .API_PRECISION_MIN , ApiConstants .API_PRECISION_MAX )) {
180+ throw new NumberFormatException (paramPrecisionAsString );
181+ }
182+ } catch (final NumberFormatException e ) {
183+ throw new ApiInvalidFormatException (PARAM_PRECISION , paramPrecisionAsString , "[" + ApiConstants .API_PRECISION_MIN +
167184 ", " + ApiConstants .API_PRECISION_MAX + ']' );
168185 }
169186
0 commit comments