Merge branch 'master' into Olingo-317_DeSerializerRefactoring
This commit is contained in:
commit
176bee4b02
|
@ -150,10 +150,12 @@ public class FilterImpl<T extends Serializable, EC extends AbstractEntityCollect
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EC getResult() {
|
public EC getResult() {
|
||||||
final CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString()).
|
CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString());
|
||||||
appendDerivedEntityTypeSegment(new FullQualifiedName(
|
|
||||||
ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
|
if(this.client.getConfiguration().isAddressingDerivedTypes()){
|
||||||
|
uriBuilder = uriBuilder.appendDerivedEntityTypeSegment(new FullQualifiedName(
|
||||||
|
ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
|
||||||
|
}
|
||||||
if (StringUtils.isNotBlank(filter)) {
|
if (StringUtils.isNotBlank(filter)) {
|
||||||
uriBuilder.filter(filter);
|
uriBuilder.filter(filter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,6 +195,31 @@ public interface CommonConfiguration {
|
||||||
*/
|
*/
|
||||||
void setKeyAsSegment(boolean value);
|
void setKeyAsSegment(boolean value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether query URIs in request should contain fully qualified type name.
|
||||||
|
* - OData Intermediate Conformance Level:
|
||||||
|
* MUST support casting to a derived type according to [OData-URL] if derived types are present in the model.
|
||||||
|
* <br/>
|
||||||
|
* Example: http://host/service/Customers/Model.VipCustomer(102) or
|
||||||
|
* http://host/service/Customers/Model.VipCustomer
|
||||||
|
*
|
||||||
|
* @return whether query URIs in request should contain fully qualified type name.
|
||||||
|
* segment.
|
||||||
|
*/
|
||||||
|
boolean isAddressingDerivedTypes() ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether query URIs in request should contain fully qualified type name.
|
||||||
|
* - OData Intermediate Conformance Level:
|
||||||
|
* MUST support casting to a derived type according to [OData-URL] if derived types are present in the model.
|
||||||
|
* <br/>
|
||||||
|
* Example: http://host/service/Customers/Model.VipCustomer(102) or
|
||||||
|
* http://host/service/Customers/Model.VipCustomer
|
||||||
|
*
|
||||||
|
* @param value 'TRUE' to use this feature.
|
||||||
|
*/
|
||||||
|
void setAddressingDerivedTypes(final boolean value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves request executor service.
|
* Retrieves request executor service.
|
||||||
*
|
*
|
||||||
|
|
|
@ -48,6 +48,8 @@ public class Configuration implements CommonConfiguration {
|
||||||
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
|
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
|
||||||
|
|
||||||
private static final String KEY_AS_SEGMENT = "keyAsSegment";
|
private static final String KEY_AS_SEGMENT = "keyAsSegment";
|
||||||
|
|
||||||
|
private static final String ADDRESS_DERIVED_TYPE = "addressDerivedType";
|
||||||
|
|
||||||
private static final String GZIP_COMPRESSION = "gzipCompression";
|
private static final String GZIP_COMPRESSION = "gzipCompression";
|
||||||
|
|
||||||
|
@ -185,6 +187,16 @@ public class Configuration implements CommonConfiguration {
|
||||||
setProperty(KEY_AS_SEGMENT, value);
|
setProperty(KEY_AS_SEGMENT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAddressingDerivedTypes() {
|
||||||
|
return (Boolean) getProperty(ADDRESS_DERIVED_TYPE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAddressingDerivedTypes(final boolean value) {
|
||||||
|
setProperty(ADDRESS_DERIVED_TYPE, value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExecutorService getExecutor() {
|
public ExecutorService getExecutor() {
|
||||||
return executor;
|
return executor;
|
||||||
|
|
|
@ -24,9 +24,14 @@ import java.net.URISyntaxException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.olingo.client.api.CommonConfiguration;
|
import org.apache.olingo.client.api.CommonConfiguration;
|
||||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||||
import org.apache.olingo.client.api.uri.QueryOption;
|
import org.apache.olingo.client.api.uri.QueryOption;
|
||||||
|
@ -269,7 +274,9 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
segmentsBuilder.append('/');
|
if(segmentsBuilder.length() > 0 && segmentsBuilder.charAt(segmentsBuilder.length()-1) != '/') {
|
||||||
|
segmentsBuilder.append('/');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,19 +291,27 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final org.apache.http.client.utils.URIBuilder builder =
|
StringBuilder sb = segmentsBuilder;
|
||||||
new org.apache.http.client.utils.URIBuilder(segmentsBuilder.toString());
|
if((queryOptions.size() + parameters.size()) > 0){
|
||||||
|
sb.append("?");
|
||||||
|
List<NameValuePair> list1 = new LinkedList<NameValuePair>();
|
||||||
|
for (Map.Entry<String, String> option : queryOptions.entrySet()) {
|
||||||
|
list1.add(new BasicNameValuePair("$" + option.getKey(), option.getValue()));
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
|
||||||
|
list1.add(new BasicNameValuePair("@" + parameter.getKey(), parameter.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> option : queryOptions.entrySet()) {
|
// don't use UriBuilder.build():
|
||||||
builder.addParameter("$" + option.getKey(), option.getValue());
|
// it will try to call URLEncodedUtils.format(Iterable<>,Charset) method,
|
||||||
|
// which works in desktop java application, however, throws NoSuchMethodError in android OS,
|
||||||
|
// so here manually construct the URL by its overload URLEncodedUtils.format(List<>,String).
|
||||||
|
String queryStr = URLEncodedUtils.format(list1, "UTF-8");
|
||||||
|
sb.append(queryStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
|
return URI.create(sb.toString());
|
||||||
builder.addParameter("@" + parameter.getKey(), parameter.getValue());
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
|
||||||
|
|
||||||
return builder.build().normalize();
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new IllegalArgumentException("Could not build valid URI", e);
|
throw new IllegalArgumentException("Could not build valid URI", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue