[OLINGO-750] Fixes for critical issues from static code check

This commit is contained in:
Michael Bolz 2015-08-10 10:24:14 +02:00
parent 6d64cbd556
commit 1d88d9c986
21 changed files with 102 additions and 83 deletions

View File

@ -21,31 +21,30 @@ package org.apache.olingo.client.api;
/** /**
* Constant values related to the OData protocol. * Constant values related to the OData protocol.
*/ */
public class ODataBatchConstants { public interface ODataBatchConstants {
/** /**
* Batch item content type. * Batch item content type.
*/ */
public static final String ITEM_CONTENT_TYPE = "application/http"; String ITEM_CONTENT_TYPE = "application/http";
/** /**
* Boundary key. * Boundary key.
*/ */
public static final String BOUNDARY = "boundary"; String BOUNDARY = "boundary";
/** /**
* Item content type. * Item content type.
*/ */
public static String ITEM_CONTENT_TYPE_LINE = "Content-Type: application/http"; String ITEM_CONTENT_TYPE_LINE = "Content-Type: application/http";
/** /**
* Item transfer encoding. * Item transfer encoding.
*/ */
public static String ITEM_TRANSFER_ENCODING_LINE = "Content-Transfer-Encoding: binary"; String ITEM_TRANSFER_ENCODING_LINE = "Content-Transfer-Encoding: binary";
/** /**
* Content id header name. * Content id header name.
*/ */
public static String CHANGESET_CONTENT_ID_NAME = "Content-ID"; String CHANGESET_CONTENT_ID_NAME = "Content-ID";
} }

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.api;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import org.apache.olingo.commons.api.ODataRuntimeException;
import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ContentType;
@ -99,6 +100,9 @@ public final class ODataClientBuilder {
} }
} }
/** Empty private constructor for static helper class */
private ODataClientBuilder() {}
/** /**
* Create an new ODataClient based on via system property ODATA_CLIENT_IMPL_SYS_PROPERTY * Create an new ODataClient based on via system property ODATA_CLIENT_IMPL_SYS_PROPERTY
* class name or if not net the default ODATA_CLIENT_IMPL_CLASS set class. * class name or if not net the default ODATA_CLIENT_IMPL_CLASS set class.
@ -161,15 +165,19 @@ public final class ODataClientBuilder {
Constructor<?> ctor = clazz.getConstructor(ctorParameterClasses); Constructor<?> ctor = clazz.getConstructor(ctorParameterClasses);
return typeOfClass.cast(ctor.newInstance(ctorParameters)); return typeOfClass.cast(ctor.newInstance(ctorParameters));
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e); throw wrapException(className, e);
} catch (InstantiationException e) { } catch (InstantiationException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e); throw wrapException(className, e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e); throw wrapException(className, e);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e); throw wrapException(className, e);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
throw new RuntimeException("Requested class '" + className + "' could not be loaded.", e); throw wrapException(className, e);
} }
} }
private static ODataRuntimeException wrapException(String className, Exception e) {
return new ODataRuntimeException("Requested class '" + className + "' could not be loaded.", e);
}
} }

View File

@ -30,63 +30,63 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
/** /**
* Gets an invoke request instance for the function import with the given name and no parameters. * Gets an invoke request instance for the function import with the given name and no parameters.
* *
* @param <RES> OData domain object result, derived from return type defined in the function import * @param <T> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked * @param functionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionImportInvokeRequest(
String functionImportName); String functionImportName);
/** /**
* Gets an invoke request instance for the function import with the given name and matching parameter names. * Gets an invoke request instance for the function import with the given name and matching parameter names.
* *
* @param <RES> OData domain object result, derived from return type defined in the function import * @param <T> OData domain object result, derived from return type defined in the function import
* @param functionImportName operation to be invoked * @param functionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation * @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionImportInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionImportInvokeRequest(
String functionImportName, Map<String, ClientValue> parameters); String functionImportName, Map<String, ClientValue> parameters);
/** /**
* Gets an invoke request instance for the action import with the given name. * Gets an invoke request instance for the action import with the given name.
* *
* @param <RES> OData domain object result, derived from return type defined in the action import * @param <T> OData domain object result, derived from return type defined in the action import
* @param actionImportName operation to be invoked * @param actionImportName operation to be invoked
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getActionImportInvokeRequest(
String actionImportName); String actionImportName);
/** /**
* Gets an invoke request instance for the action import with the given name. * Gets an invoke request instance for the action import with the given name.
* *
* @param <RES> OData domain object result, derived from return type defined in the action import * @param <T> OData domain object result, derived from return type defined in the action import
* @param actionImportName operation to be invoked * @param actionImportName operation to be invoked
* @param parameters parameters to pass to operation import invocation * @param parameters parameters to pass to operation import invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionImportInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getActionImportInvokeRequest(
String actionImportName, Map<String, ClientValue> parameters); String actionImportName, Map<String, ClientValue> parameters);
/** /**
* Gets an invoke request instance for the function bound to given URI (no parameters). * Gets an invoke request instance for the function bound to given URI (no parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI * @param bindingParameterURI binding parameter URI
* @param functionName operation to be invoked * @param functionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name * @param bindingParameterTypeName binding parameter type full qualified name
* @param isBindingParameterCollection whether binding parameter is collection * @param isBindingParameterCollection whether binding parameter is collection
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundFunctionInvokeRequest(
URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName, URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection); Boolean isBindingParameterCollection);
/** /**
* Gets an invoke request instance for the function bound to given URI (with parameters). * Gets an invoke request instance for the function bound to given URI (with parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI * @param bindingParameterURI binding parameter URI
* @param functionName operation to be invoked * @param functionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name * @param bindingParameterTypeName binding parameter type full qualified name
@ -94,28 +94,28 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
* @param parameters parameters to pass to function invocation * @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundFunctionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundFunctionInvokeRequest(
URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName, URI bindingParameterURI, FullQualifiedName functionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection, Map<String, ClientValue> parameters); Boolean isBindingParameterCollection, Map<String, ClientValue> parameters);
/** /**
* Gets an invoke request instance for the action bound to given URI (no parameters). * Gets an invoke request instance for the action bound to given URI (no parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI * @param bindingParameterURI binding parameter URI
* @param actionName operation to be invoked * @param actionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name * @param bindingParameterTypeName binding parameter type full qualified name
* @param isBindingParameterCollection whether binding parameter is collection * @param isBindingParameterCollection whether binding parameter is collection
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundActionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundActionInvokeRequest(
URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName, URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection); Boolean isBindingParameterCollection);
/** /**
* Gets an invoke request instance for the action bound to given URI (with parameters). * Gets an invoke request instance for the action bound to given URI (with parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param bindingParameterURI binding parameter URI * @param bindingParameterURI binding parameter URI
* @param actionName operation to be invoked * @param actionName operation to be invoked
* @param bindingParameterTypeName binding parameter type full qualified name * @param bindingParameterTypeName binding parameter type full qualified name
@ -123,7 +123,7 @@ public interface EdmEnabledInvokeRequestFactory extends InvokeRequestFactory {
* @param parameters parameters to pass to function invocation * @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getBoundActionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getBoundActionInvokeRequest(
URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName, URI bindingParameterURI, FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
Boolean isBindingParameterCollection, Map<String, ClientValue> parameters); Boolean isBindingParameterCollection, Map<String, ClientValue> parameters);

View File

@ -36,57 +36,57 @@ public interface InvokeRequestFactory {
* This method is mainly meant for internal usage, but defined for generic calls from proxy; normally, one of other * This method is mainly meant for internal usage, but defined for generic calls from proxy; normally, one of other
* methods should be used instead. * methods should be used instead.
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param method HTTP invocation method * @param method HTTP invocation method
* @param uri invocation URI * @param uri invocation URI
* @param resultRef reference Class for result * @param resultRef reference Class for result
* @param parameters parameters to pass to function invocation * @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getInvokeRequest(
HttpMethod method, URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters); HttpMethod method, URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
/** /**
* Gets an invoke request instance for the function bound to given URI (no parameters). * Gets an invoke request instance for the function bound to given URI (no parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param uri invocation URI * @param uri invocation URI
* @param resultRef reference Class for result * @param resultRef reference Class for result
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionInvokeRequest(URI uri, Class<RES> resultRef); <T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionInvokeRequest(URI uri, Class<T> resultRef);
/** /**
* Gets an invoke request instance for the function bound to given URI (with parameters). * Gets an invoke request instance for the function bound to given URI (with parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param uri invocation URI * @param uri invocation URI
* @param resultRef reference Class for result * @param resultRef reference Class for result
* @param parameters parameters to pass to function invocation * @param parameters parameters to pass to function invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getFunctionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getFunctionInvokeRequest(
URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters); URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
/** /**
* Gets an invoke request instance for the action bound to given URI (no parameters). * Gets an invoke request instance for the action bound to given URI (no parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param uri invocation URI * @param uri invocation URI
* @param resultRef reference Class for result * @param resultRef reference Class for result
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionInvokeRequest(URI uri, Class<RES> resultRef); <T extends ClientInvokeResult> ODataInvokeRequest<T> getActionInvokeRequest(URI uri, Class<T> resultRef);
/** /**
* Gets an invoke request instance for the action bound to given URI (with parameters). * Gets an invoke request instance for the action bound to given URI (with parameters).
* *
* @param <RES> OData domain object result * @param <T> OData domain object result
* @param uri invocation URI * @param uri invocation URI
* @param resultRef reference Class for result * @param resultRef reference Class for result
* @param parameters parameters to pass to action invocation * @param parameters parameters to pass to action invocation
* @return new {@link ODataInvokeRequest} instance. * @return new {@link ODataInvokeRequest} instance.
*/ */
<RES extends ClientInvokeResult> ODataInvokeRequest<RES> getActionInvokeRequest( <T extends ClientInvokeResult> ODataInvokeRequest<T> getActionInvokeRequest(
URI uri, Class<RES> resultRef, Map<String, ClientValue> parameters); URI uri, Class<T> resultRef, Map<String, ClientValue> parameters);
} }

View File

@ -23,16 +23,16 @@ import java.util.Collection;
/** /**
* OData collection property value. * OData collection property value.
* *
* @param <OV> The actual ODataValue interface. * @param <T> The actual ODataValue interface.
*/ */
public interface ClientCollectionValue<OV extends ClientValue> extends ClientValue, Iterable<OV> { public interface ClientCollectionValue<T extends ClientValue> extends ClientValue, Iterable<T> {
/** /**
* Adds a value to the collection. * Adds a value to the collection.
* *
* @param value value to be added. * @param value value to be added.
*/ */
ClientCollectionValue<OV> add(ClientValue value); ClientCollectionValue<T> add(ClientValue value);
/** /**
* Checks if collection is empty. * Checks if collection is empty.

View File

@ -44,9 +44,9 @@ import org.slf4j.LoggerFactory;
* <b>Please don't forget to call the <tt>close()>/</tt> method when not needed any more.</b> * <b>Please don't forget to call the <tt>close()>/</tt> method when not needed any more.</b>
* *
* @param <E> concrete ODataEntity implementation * @param <E> concrete ODataEntity implementation
* @param <ES> concrete ODataEntitySet implementation * @param <T> concrete ODataEntitySet implementation
*/ */
public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends ClientEntity> public class ClientEntitySetIterator<T extends ClientEntitySet, E extends ClientEntity>
implements Iterator<E> { implements Iterator<E> {
/** /**
@ -62,7 +62,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
private final ContentType contentType; private final ContentType contentType;
private ES entitySet; private T entitySet;
private final ByteArrayOutputStream osEntitySet; private final ByteArrayOutputStream osEntitySet;
@ -118,7 +118,7 @@ public class ClientEntitySetIterator<ES extends ClientEntitySet, E extends Clien
if (cached == null) { if (cached == null) {
available = false; available = false;
try { try {
entitySet = (ES) odataClient.getReader(). entitySet = (T) odataClient.getReader().
readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), contentType); readEntitySet(new ByteArrayInputStream(osEntitySet.toByteArray()), contentType);
} catch (final ODataDeserializerException e) { } catch (final ODataDeserializerException e) {
available = false; available = false;

View File

@ -45,7 +45,7 @@ public abstract class ClientItem {
/** /**
* OData item self link. * OData item self link.
*/ */
protected URI link; private URI link;
/** /**
* Constructor. * Constructor.

View File

@ -31,11 +31,11 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
public static class Builder { public static class Builder {
protected URI uri; private URI uri;
protected ClientLinkType type; private ClientLinkType type;
protected String title; private String title;
public Builder setURI(final URI uri) { public Builder setURI(final URI uri) {
this.uri = uri; this.uri = uri;
@ -88,17 +88,17 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
/** /**
* Link type. * Link type.
*/ */
protected final ClientLinkType type; private final ClientLinkType type;
/** /**
* Link rel. * Link rel.
*/ */
protected final String rel; private final String rel;
/** /**
* ETag for media edit links. * ETag for media edit links.
*/ */
protected String mediaETag; private String mediaETag;
private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>(); private final List<ClientAnnotation> annotations = new ArrayList<ClientAnnotation>();
@ -112,8 +112,8 @@ public class ClientLink extends ClientItem implements ClientAnnotatable {
public ClientLink(final URI uri, final ClientLinkType type, final String title) { public ClientLink(final URI uri, final ClientLinkType type, final String title) {
super(title); super(title);
link = uri;
this.type = type; this.type = type;
setLink(uri);
switch (this.type) { switch (this.type) {
case ASSOCIATION: case ASSOCIATION:

View File

@ -55,10 +55,10 @@ public interface ClientValue {
/** /**
* Casts to collection value. * Casts to collection value.
* *
* @param <OV> The actual ODataValue interface. * @param <T> The actual ODataValue interface.
* @return collection value. * @return collection value.
*/ */
<OV extends ClientValue> ClientCollectionValue<OV> asCollection(); <T extends ClientValue> ClientCollectionValue<T> asCollection();
/** /**
* Casts to complex value. * Casts to complex value.

View File

@ -21,7 +21,7 @@ package org.apache.olingo.client.api.uri;
public interface FilterArgFactory { public interface FilterArgFactory {
FilterArg _null(); FilterArg nullValue();
FilterArg add(FilterArg first, FilterArg second); FilterArg add(FilterArg first, FilterArg second);

View File

@ -25,7 +25,7 @@ import org.apache.olingo.client.api.uri.URIFilter;
public class FilterArgFactoryImpl implements FilterArgFactory { public class FilterArgFactoryImpl implements FilterArgFactory {
@Override @Override
public FilterArg _null() { public FilterArg nullValue() {
return new FilterConst("null"); return new FilterConst("null");
} }

View File

@ -35,7 +35,7 @@ public enum ODataPreferenceNames {
private final String preferenceName; private final String preferenceName;
private ODataPreferenceNames(final String preferenceName) { ODataPreferenceNames(final String preferenceName) {
this.preferenceName = preferenceName; this.preferenceName = preferenceName;
} }

View File

@ -41,9 +41,9 @@ public abstract class ODataLibraryException extends ODataException {
protected static final String DEFAULT_SERVER_BUNDLE_NAME = "server-core-exceptions-i18n"; protected static final String DEFAULT_SERVER_BUNDLE_NAME = "server-core-exceptions-i18n";
/** Key for the exception text in the resource bundle. */ /** Key for the exception text in the resource bundle. */
public static interface MessageKey { public interface MessageKey {
/** Gets this key. */ /** Gets this key. */
public String getKey(); String getKey();
} }
private MessageKey messageKey; private MessageKey messageKey;
@ -137,9 +137,9 @@ public abstract class ODataLibraryException extends ODataException {
} }
/** Error message text and {@link Locale} used for it. */ /** Error message text and {@link Locale} used for it. */
public class ODataErrorMessage { public static class ODataErrorMessage {
String message; private String message;
Locale locale; private Locale locale;
public ODataErrorMessage(final String message, final Locale usedLocale) { public ODataErrorMessage(final String message, final Locale usedLocale) {
this.message = message; this.message = message;

View File

@ -24,7 +24,7 @@ package org.apache.olingo.server.api.deserializer.batch;
* {@link org.apache.olingo.server.api.deserializer.FixedFormatDeserializer * {@link org.apache.olingo.server.api.deserializer.FixedFormatDeserializer
* #parseBatchRequest(java.io.InputStream, String, BatchOptions)} * #parseBatchRequest(java.io.InputStream, String, BatchOptions)}
*/ */
public class BatchOptions { public final class BatchOptions {
private boolean isStrict = true; private boolean isStrict = true;
private String rawBaseUri = ""; private String rawBaseUri = "";
private String rawServiceResolutionUri = ""; private String rawServiceResolutionUri = "";

View File

@ -19,9 +19,11 @@
package org.apache.olingo.server.api.prefer; package org.apache.olingo.server.api.prefer;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.apache.olingo.commons.api.ODataPreferenceNames; import org.apache.olingo.commons.api.ODataPreferenceNames;
import org.apache.olingo.server.api.prefer.Preferences.Return; import org.apache.olingo.server.api.prefer.Preferences.Return;
@ -31,8 +33,9 @@ import org.apache.olingo.server.api.prefer.Preferences.Return;
* as described in <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>. * as described in <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
* There are named methods for preferences defined in the OData standard. * There are named methods for preferences defined in the OData standard.
*/ */
public class PreferencesApplied { public final class PreferencesApplied {
private static final Set<String> SAFE_PREFERENCE_NAMES = new HashSet<String>();
private Map<String, String> applied; private Map<String, String> applied;
private PreferencesApplied() { private PreferencesApplied() {
@ -57,14 +60,7 @@ public class PreferencesApplied {
final String key = entry.getKey(); final String key = entry.getKey();
result.append(key); result.append(key);
if (entry.getValue() != null) { if (entry.getValue() != null) {
final boolean safe = ODataPreferenceNames.ALLOW_ENTITY_REFERENCES.toString().equals(key) final boolean safe = isSafe(key);
|| ODataPreferenceNames.CALLBACK.toString().equals(key)
|| ODataPreferenceNames.CONTINUE_ON_ERROR.toString().equals(key)
|| ODataPreferenceNames.MAX_PAGE_SIZE.toString().equals(key)
|| ODataPreferenceNames.TRACK_CHANGES.toString().equals(key)
|| ODataPreferenceNames.RETURN.toString().equals(key)
|| ODataPreferenceNames.RESPOND_ASYNC.toString().equals(key)
|| ODataPreferenceNames.WAIT.toString().equals(key);
result.append('=') result.append('=')
.append(safe ? "" : '"') .append(safe ? "" : '"')
.append(entry.getValue().replaceAll("\\\\|\"", "\\\\$0")) .append(entry.getValue().replaceAll("\\\\|\"", "\\\\$0"))
@ -74,6 +70,20 @@ public class PreferencesApplied {
return result.toString(); return result.toString();
} }
private boolean isSafe(String key) {
if(SAFE_PREFERENCE_NAMES.isEmpty()) {
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.ALLOW_ENTITY_REFERENCES.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.CALLBACK.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.CONTINUE_ON_ERROR.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.MAX_PAGE_SIZE.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.TRACK_CHANGES.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.RETURN.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.RESPOND_ASYNC.toString());
SAFE_PREFERENCE_NAMES.add(ODataPreferenceNames.WAIT.toString());
}
return SAFE_PREFERENCE_NAMES.contains(key);
}
@Override @Override
public String toString() { public String toString() {
return toValueString(); return toValueString();

View File

@ -19,6 +19,8 @@
package org.apache.olingo.server.api.processor; package org.apache.olingo.server.api.processor;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.util.Locale;
import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpHeader; import org.apache.olingo.commons.api.http.HttpHeader;
@ -116,7 +118,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
// This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client. // This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
String responseContent = String responseContent =
"{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during error processing\"}}"; "{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred during error processing\"}}";
response.setContent(new ByteArrayInputStream(responseContent.getBytes())); response.setContent(new ByteArrayInputStream(responseContent.getBytes(Charset.forName("utf-8"))));
response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString()); response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
} }

View File

@ -36,6 +36,6 @@ public interface ErrorProcessor extends Processor {
* @param serverError the server error * @param serverError the server error
* @param responseFormat requested content type after content negotiation * @param responseFormat requested content type after content negotiation
*/ */
public void processError(ODataRequest request, ODataResponse response, ODataServerError serverError, void processError(ODataRequest request, ODataResponse response, ODataServerError serverError,
ContentType responseFormat); ContentType responseFormat);
} }

View File

@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.edm.EdmProperty;
/** Options for the OData serializer. */ /** Options for the OData serializer. */
public class PrimitiveSerializerOptions { public final class PrimitiveSerializerOptions {
private ContextURL contextURL; private ContextURL contextURL;
private Boolean isNullable; private Boolean isNullable;

View File

@ -22,7 +22,7 @@ import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.server.api.uri.queryoption.CountOption; import org.apache.olingo.server.api.uri.queryoption.CountOption;
/** Options for the OData serializer. */ /** Options for the OData serializer. */
public class ReferenceCollectionSerializerOptions { public final class ReferenceCollectionSerializerOptions {
private ContextURL contextURL; private ContextURL contextURL;
private CountOption count; private CountOption count;

View File

@ -20,7 +20,7 @@ package org.apache.olingo.server.api.serializer;
import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.ContextURL;
public class ReferenceSerializerOptions { public final class ReferenceSerializerOptions {
private ContextURL contextURL; private ContextURL contextURL;
/** Gets the {@link ContextURL}. */ /** Gets the {@link ContextURL}. */

View File

@ -84,9 +84,9 @@ public enum SystemQueryOptionKind {
*/ */
LEVELS("$level"); LEVELS("$level");
String syntax; private String syntax;
private SystemQueryOptionKind(final String syntax) { SystemQueryOptionKind(final String syntax) {
this.syntax = syntax; this.syntax = syntax;
} }