Merge branch 'master' into Olingo-317_DeSerializerRefactoring

This commit is contained in:
Michael Bolz 2014-06-17 14:24:05 +02:00
commit 176bee4b02
4 changed files with 70 additions and 16 deletions

View File

@ -150,10 +150,12 @@ public class FilterImpl<T extends Serializable, EC extends AbstractEntityCollect
@Override
public EC getResult() {
final CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString()).
appendDerivedEntityTypeSegment(new FullQualifiedName(
ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString());
if(this.client.getConfiguration().isAddressingDerivedTypes()){
uriBuilder = uriBuilder.appendDerivedEntityTypeSegment(new FullQualifiedName(
ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
}
if (StringUtils.isNotBlank(filter)) {
uriBuilder.filter(filter);
}

View File

@ -195,6 +195,31 @@ public interface CommonConfiguration {
*/
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.
*

View File

@ -48,6 +48,8 @@ public class Configuration implements CommonConfiguration {
private static final String USE_XHTTP_METHOD = "useHTTPMethod";
private static final String KEY_AS_SEGMENT = "keyAsSegment";
private static final String ADDRESS_DERIVED_TYPE = "addressDerivedType";
private static final String GZIP_COMPRESSION = "gzipCompression";
@ -185,6 +187,16 @@ public class Configuration implements CommonConfiguration {
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
public ExecutorService getExecutor() {
return executor;

View File

@ -24,9 +24,14 @@ import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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.uri.CommonURIBuilder;
import org.apache.olingo.client.api.uri.QueryOption;
@ -269,7 +274,9 @@ public abstract class AbstractURIBuilder<UB extends CommonURIBuilder<?>> impleme
break;
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 {
final org.apache.http.client.utils.URIBuilder builder =
new org.apache.http.client.utils.URIBuilder(segmentsBuilder.toString());
StringBuilder sb = segmentsBuilder;
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()) {
builder.addParameter("$" + option.getKey(), option.getValue());
// don't use UriBuilder.build():
// 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()) {
builder.addParameter("@" + parameter.getKey(), parameter.getValue());
}
return builder.build().normalize();
} catch (URISyntaxException e) {
return URI.create(sb.toString());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Could not build valid URI", e);
}
}