OLINGO-1107: Changing client encoding of URL to use %20 instead of using + for space. This is done by switching the Olingo supplied Encoder and Decoder rather than the JDK supplied URLEncoder and URLDecoder
This commit is contained in:
parent
004515aaee
commit
0cf76f51c5
|
@ -18,15 +18,14 @@
|
|||
*/
|
||||
package org.apache.olingo.fit.rest;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.cxf.interceptor.Fault;
|
||||
import org.apache.cxf.message.Message;
|
||||
import org.apache.cxf.phase.AbstractPhaseInterceptor;
|
||||
import org.apache.cxf.phase.Phase;
|
||||
import org.apache.olingo.commons.core.Decoder;
|
||||
|
||||
public class ResolvingReferencesInterceptor extends AbstractPhaseInterceptor<Message> {
|
||||
|
||||
|
@ -39,21 +38,17 @@ public class ResolvingReferencesInterceptor extends AbstractPhaseInterceptor<Mes
|
|||
final String path = (String) message.get(Message.PATH_INFO);
|
||||
final String query = (String) message.get(Message.QUERY_STRING);
|
||||
|
||||
try {
|
||||
if (path.endsWith("$entity") && StringUtils.isNotBlank(query)
|
||||
&& URLDecoder.decode(query, "UTF-8").contains("$id=")) {
|
||||
if (path.endsWith("$entity") && StringUtils.isNotBlank(query)
|
||||
&& Decoder.decode(query).contains("$id=")) {
|
||||
|
||||
final String id = URLDecoder.decode(query, "UTF-8");
|
||||
final String newURL = id.substring(id.indexOf("$id=") + 4);
|
||||
final String id = Decoder.decode(query);
|
||||
final String newURL = id.substring(id.indexOf("$id=") + 4);
|
||||
|
||||
final URI uri = URI.create(newURL);
|
||||
final URI uri = URI.create(newURL);
|
||||
|
||||
message.put(Message.REQUEST_URL, uri.toASCIIString());
|
||||
message.put(Message.REQUEST_URI, uri.getPath());
|
||||
message.put(Message.PATH_INFO, uri.getPath());
|
||||
}
|
||||
} catch (UnsupportedEncodingException ignore) {
|
||||
// ignore
|
||||
message.put(Message.REQUEST_URL, uri.toASCIIString());
|
||||
message.put(Message.REQUEST_URI, uri.getPath());
|
||||
message.put(Message.PATH_INFO, uri.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.uri;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
|
@ -37,8 +35,8 @@ import org.apache.olingo.client.api.uri.SegmentType;
|
|||
import org.apache.olingo.client.api.uri.URIBuilder;
|
||||
import org.apache.olingo.client.api.uri.URIFilter;
|
||||
import org.apache.olingo.client.api.uri.URISearch;
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.core.Decoder;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -230,12 +228,8 @@ public class URIBuilderImpl implements URIBuilder {
|
|||
@Override
|
||||
public URIBuilder filter(final URIFilter filter) {
|
||||
URIBuilder result;
|
||||
try {
|
||||
// decode in order to support @ in parameter aliases
|
||||
result = filter(URLDecoder.decode(filter.build(), Constants.UTF8));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
result = filter(filter.build());
|
||||
}
|
||||
// decode in order to support @ in parameter aliases
|
||||
result = filter(Decoder.decode(filter.build()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
|
@ -36,6 +35,7 @@ import java.util.regex.Pattern;
|
|||
import javax.xml.datatype.Duration;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -144,25 +144,23 @@ public final class URIUtils {
|
|||
private static String timestamp(final Timestamp timestamp)
|
||||
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
|
||||
|
||||
return URLEncoder.encode(EdmDateTimeOffset.getInstance().
|
||||
valueToString(timestamp, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8);
|
||||
return Encoder.encode(EdmDateTimeOffset.getInstance().
|
||||
valueToString(timestamp, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
|
||||
}
|
||||
|
||||
private static String calendar(final Calendar calendar)
|
||||
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
|
||||
|
||||
return URLEncoder.encode(EdmDateTimeOffset.getInstance().
|
||||
valueToString(calendar, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8);
|
||||
return Encoder.encode(EdmDateTimeOffset.getInstance().
|
||||
valueToString(calendar, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
|
||||
}
|
||||
|
||||
private static String duration(final Duration duration)
|
||||
throws UnsupportedEncodingException, EdmPrimitiveTypeException {
|
||||
|
||||
return EdmDuration.getInstance().toUriLiteral(URLEncoder.encode(EdmDuration.getInstance().
|
||||
return EdmDuration.getInstance().toUriLiteral(Encoder.encode(EdmDuration.getInstance().
|
||||
valueToString(duration, null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null), Constants.UTF8));
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)));
|
||||
}
|
||||
|
||||
private static String quoteString(final String string, final boolean singleQuoteEscape)
|
||||
|
@ -250,12 +248,11 @@ public final class URIUtils {
|
|||
? EdmInt64.getInstance().valueToString(obj, null, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)
|
||||
: (obj instanceof Geospatial)
|
||||
? URLEncoder.encode(EdmPrimitiveTypeFactory.getInstance(
|
||||
? Encoder.encode(EdmPrimitiveTypeFactory.getInstance(
|
||||
((Geospatial) obj).getEdmPrimitiveTypeKind()).
|
||||
valueToString(obj, null, null,
|
||||
Constants.DEFAULT_PRECISION,
|
||||
Constants.DEFAULT_SCALE, null),
|
||||
Constants.UTF8)
|
||||
Constants.DEFAULT_SCALE, null))
|
||||
: (obj instanceof String)
|
||||
? quoteString((String) obj, singleQuoteEscape)
|
||||
: obj.toString();
|
||||
|
@ -355,12 +352,7 @@ public final class URIUtils {
|
|||
inlineParams.deleteCharAt(inlineParams.length() - 1);
|
||||
}
|
||||
|
||||
try {
|
||||
return URI.create(baseURI + "(" + URLEncoder.encode(inlineParams.toString(), Constants.UTF8) + ")"
|
||||
+ (StringUtils.isNotBlank(rawQuery) ? "?" + rawQuery : StringUtils.EMPTY));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalArgumentException("While adding GET parameters", e);
|
||||
}
|
||||
|
||||
return URI.create(baseURI + "(" + Encoder.encode(inlineParams.toString()) + ")"
|
||||
+ (StringUtils.isNotBlank(rawQuery) ? "?" + rawQuery : StringUtils.EMPTY));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.olingo.commons.api.Constants;
|
|||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.apache.olingo.commons.core.edm.EdmEnumTypeImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class FilterFactoryTest extends AbstractTest {
|
|||
calendar.set(2011, 2, 8, 14, 21, 12);
|
||||
|
||||
final URIFilter filter = getFilterFactory().ge("OrderDate", calendar);
|
||||
assertEquals("(OrderDate ge " + URLEncoder.encode("2011-03-08T14:21:12-08:00", Constants.UTF8) + ")",
|
||||
assertEquals("(OrderDate ge " + Encoder.encode("2011-03-08T14:21:12-08:00") + ")",
|
||||
filter.build());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.apache.olingo.client.core.uri;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
@ -33,6 +32,7 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|||
import org.apache.olingo.commons.api.edm.geo.Geospatial;
|
||||
import org.apache.olingo.commons.api.edm.geo.Point;
|
||||
import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
|
||||
import org.apache.olingo.commons.core.Encoder;
|
||||
import org.apache.olingo.commons.core.edm.EdmEnumTypeImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class URIEscapeTest {
|
|||
calendar.clear();
|
||||
calendar.set(2014, 6, 11, 12, 30, 04);
|
||||
|
||||
assertEquals(URLEncoder.encode("2014-07-11T12:30:04+01:00", Constants.UTF8),
|
||||
assertEquals(Encoder.encode("2014-07-11T12:30:04+01:00"),
|
||||
URIUtils.escape( calendar));
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class URIEscapeTest {
|
|||
point.setX(142.1);
|
||||
point.setY(64.1);
|
||||
|
||||
assertEquals(URLEncoder.encode("geography'SRID=4326;Point(142.1 64.1)'", Constants.UTF8),
|
||||
assertEquals(Encoder.encode("geography'SRID=4326;Point(142.1 64.1)'"),
|
||||
URIUtils.escape( point));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue