Merge branch 'master' into OLINGO-406
This commit is contained in:
commit
badb9916b2
|
@ -26,7 +26,9 @@ public interface AbstractOpenType {
|
||||||
|
|
||||||
void removeAdditionalProperty(String name);
|
void removeAdditionalProperty(String name);
|
||||||
|
|
||||||
Object getAdditionalProperty(String name);
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
Object readAdditionalProperty(String name);
|
||||||
|
|
||||||
Collection<String> getAdditionalPropertyNames();
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
Collection<String> readAdditionalPropertyNames();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,10 @@ public interface Annotatable extends Serializable {
|
||||||
|
|
||||||
void removeAnnotation(Class<? extends AbstractTerm> term);
|
void removeAnnotation(Class<? extends AbstractTerm> term);
|
||||||
|
|
||||||
Object getAnnotation(Class<? extends AbstractTerm> term);
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
Object readAnnotation(Class<? extends AbstractTerm> term);
|
||||||
|
|
||||||
Collection<Class<? extends AbstractTerm>> getAnnotationTerms();
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
Collection<Class<? extends AbstractTerm>> readAnnotationTerms();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,5 +32,6 @@ public interface EntityType<T extends StructuredType<?>> extends StructuredType<
|
||||||
*
|
*
|
||||||
* @return entity reference ID.
|
* @return entity reference ID.
|
||||||
*/
|
*/
|
||||||
String getEntityReferenceID();
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
String readEntityReferenceID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,41 +158,13 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
||||||
if ("expand".equals(method.getName())
|
if (method.getName().startsWith("get")) {
|
||||||
|| "select".equals(method.getName())
|
// Here need check "get"/"set" first for better get-/set- performance because
|
||||||
|| "refs".equals(method.getName())) {
|
// the below if-statements are really time-consuming, even twice slower than "get" body.
|
||||||
invokeSelfMethod(method, args);
|
|
||||||
return proxy;
|
|
||||||
} else if (isSelfMethod(method, args)) {
|
|
||||||
return invokeSelfMethod(method, args);
|
|
||||||
} else if ("load".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
|
||||||
load();
|
|
||||||
return proxy;
|
|
||||||
} else if ("loadAsync".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
|
||||||
return service.getClient().getConfiguration().getExecutor().submit(new Callable<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object call() throws Exception {
|
|
||||||
load();
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
|
||||||
final Class<?> returnType = method.getReturnType();
|
|
||||||
|
|
||||||
return Proxy.newProxyInstance(
|
// Assumption: for each getter will always exist a setter and viceversa.
|
||||||
Thread.currentThread().getContextClassLoader(),
|
|
||||||
new Class<?>[] {returnType},
|
|
||||||
OperationInvocationHandler.getInstance(getEntityHandler()));
|
|
||||||
} else if ("annotations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
|
||||||
final Class<?> returnType = method.getReturnType();
|
|
||||||
|
|
||||||
return Proxy.newProxyInstance(
|
|
||||||
Thread.currentThread().getContextClassLoader(),
|
|
||||||
new Class<?>[] {returnType},
|
|
||||||
AnnotatationsInvocationHandler.getInstance(getEntityHandler(), this));
|
|
||||||
} else if (method.getName().startsWith("get")) {
|
|
||||||
// Assumption: for each getter will always exist a setter and viceversa.
|
|
||||||
// get method annotation and check if it exists as expected
|
// get method annotation and check if it exists as expected
|
||||||
|
|
||||||
final Object res;
|
final Object res;
|
||||||
final Method getter = typeRef.getMethod(method.getName());
|
final Method getter = typeRef.getMethod(method.getName());
|
||||||
|
|
||||||
|
@ -234,6 +206,38 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClassUtils.returnVoid();
|
return ClassUtils.returnVoid();
|
||||||
|
} else if ("expand".equals(method.getName())
|
||||||
|
|| "select".equals(method.getName())
|
||||||
|
|| "refs".equals(method.getName())) {
|
||||||
|
invokeSelfMethod(method, args);
|
||||||
|
return proxy;
|
||||||
|
} else if (isSelfMethod(method, args)) {
|
||||||
|
return invokeSelfMethod(method, args);
|
||||||
|
} else if ("load".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
||||||
|
load();
|
||||||
|
return proxy;
|
||||||
|
} else if ("loadAsync".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
||||||
|
return service.getClient().getConfiguration().getExecutor().submit(new Callable<Object>() {
|
||||||
|
@Override
|
||||||
|
public Object call() throws Exception {
|
||||||
|
load();
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if ("operations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
||||||
|
final Class<?> returnType = method.getReturnType();
|
||||||
|
|
||||||
|
return Proxy.newProxyInstance(
|
||||||
|
Thread.currentThread().getContextClassLoader(),
|
||||||
|
new Class<?>[] {returnType},
|
||||||
|
OperationInvocationHandler.getInstance(getEntityHandler()));
|
||||||
|
} else if ("annotations".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
|
||||||
|
final Class<?> returnType = method.getReturnType();
|
||||||
|
|
||||||
|
return Proxy.newProxyInstance(
|
||||||
|
Thread.currentThread().getContextClassLoader(),
|
||||||
|
new Class<?>[] {returnType},
|
||||||
|
AnnotatationsInvocationHandler.getInstance(getEntityHandler(), this));
|
||||||
} else {
|
} else {
|
||||||
throw new NoSuchMethodException(method.getName());
|
throw new NoSuchMethodException(method.getName());
|
||||||
}
|
}
|
||||||
|
@ -517,7 +521,8 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
|
||||||
return navPropValue;
|
return navPropValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getAdditionalProperty(final String name) {
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
public Object readAdditionalProperty(final String name) {
|
||||||
return getPropertyValue(name, null);
|
return getPropertyValue(name, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +530,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
|
||||||
return propertyChanges;
|
return propertyChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getAdditionalPropertyNames() {
|
public Collection<String> readAdditionalPropertyNames() {
|
||||||
final Set<String> res = new HashSet<String>(propertyChanges.keySet());
|
final Set<String> res = new HashSet<String>(propertyChanges.keySet());
|
||||||
final Set<String> propertyNames = new HashSet<String>();
|
final Set<String> propertyNames = new HashSet<String>();
|
||||||
for (Method method : typeRef.getMethods()) {
|
for (Method method : typeRef.getMethods()) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getAnnotation(final Class<? extends AbstractTerm> term) {
|
public Object readAnnotation(final Class<? extends AbstractTerm> term) {
|
||||||
Object res = null;
|
Object res = null;
|
||||||
|
|
||||||
if (annotations.containsKey(term)) {
|
if (annotations.containsKey(term)) {
|
||||||
|
@ -171,7 +171,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends AbstractTerm>> getAnnotationTerms() {
|
public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() {
|
||||||
return entityHandler.getEntity() instanceof ODataEntity
|
return entityHandler.getEntity() instanceof ODataEntity
|
||||||
? CoreUtils.getAnnotationTerms(service, internalAnnotations())
|
? CoreUtils.getAnnotationTerms(service, internalAnnotations())
|
||||||
: Collections.<Class<? extends AbstractTerm>>emptyList();
|
: Collections.<Class<? extends AbstractTerm>>emptyList();
|
||||||
|
|
|
@ -406,7 +406,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getAnnotation(final Class<? extends AbstractTerm> term) {
|
public Object readAnnotation(final Class<? extends AbstractTerm> term) {
|
||||||
Object res = null;
|
Object res = null;
|
||||||
|
|
||||||
if (annotations.containsKey(term)) {
|
if (annotations.containsKey(term)) {
|
||||||
|
@ -436,7 +436,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class<? extends AbstractTerm>> getAnnotationTerms() {
|
public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() {
|
||||||
return getEntity() instanceof ODataEntity
|
return getEntity() instanceof ODataEntity
|
||||||
? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations())
|
? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations())
|
||||||
: Collections.<Class<? extends AbstractTerm>>emptyList();
|
: Collections.<Class<? extends AbstractTerm>>emptyList();
|
||||||
|
@ -493,7 +493,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
|
||||||
return getEntity() == null ? null : getEntity().getProperty(name);
|
return getEntity() == null ? null : getEntity().getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEntityReferenceID() {
|
// use read- instead of get- for .invoke() to distinguish it from entity property getter.
|
||||||
|
public String readEntityReferenceID() {
|
||||||
URI id = getEntity() == null ? null
|
URI id = getEntity() == null ? null
|
||||||
: getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
|
: getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
|
||||||
? ((org.apache.olingo.commons.api.domain.v3.ODataEntity) getEntity()).getLink()
|
? ((org.apache.olingo.commons.api.domain.v3.ODataEntity) getEntity()).getLink()
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -49,6 +50,10 @@ public final class ClassUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type[] extractGenericType(final Class<?> paramType, final Class<?>... references) {
|
public static Type[] extractGenericType(final Class<?> paramType, final Class<?>... references) {
|
||||||
|
if (Proxy.class.isAssignableFrom(paramType)) {
|
||||||
|
return extractGenericType(Class.class.cast(paramType.getGenericInterfaces()[0]), references);
|
||||||
|
}
|
||||||
|
|
||||||
if (paramType.getGenericInterfaces().length > 0) {
|
if (paramType.getGenericInterfaces().length > 0) {
|
||||||
if (references == null || references.length == 0) {
|
if (references == null || references.length == 0) {
|
||||||
return ((ParameterizedType) paramType.getGenericInterfaces()[0]).getActualTypeArguments();
|
return ((ParameterizedType) paramType.getGenericInterfaces()[0]).getActualTypeArguments();
|
||||||
|
|
|
@ -72,11 +72,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||||
@Test
|
@Test
|
||||||
public void read() {
|
public void read() {
|
||||||
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
|
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
|
||||||
assertEquals(Double.class, row.getAdditionalProperty("Double").getClass());
|
assertEquals(Double.class, row.readAdditionalProperty("Double").getClass());
|
||||||
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
|
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
|
||||||
|
|
||||||
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
|
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
|
||||||
assertEquals(BigDecimal.class, row.getAdditionalProperty("Decimal").getClass());
|
assertEquals(BigDecimal.class, row.readAdditionalProperty("Decimal").getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -119,13 +119,13 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||||
otcontainer.flush();
|
otcontainer.flush();
|
||||||
|
|
||||||
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
|
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
|
||||||
assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
|
assertEquals(String.class, rowIndex.readAdditionalProperty("aString").getClass());
|
||||||
assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
|
assertEquals(Boolean.class, rowIndex.readAdditionalProperty("aBoolean").getClass());
|
||||||
assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
|
assertEquals(Double.class, rowIndex.readAdditionalProperty("aDouble").getClass());
|
||||||
assertEquals(Byte.class, rowIndex.getAdditionalProperty("aByte").getClass());
|
assertEquals(Byte.class, rowIndex.readAdditionalProperty("aByte").getClass());
|
||||||
assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte"));
|
assertEquals(Byte.MAX_VALUE, rowIndex.readAdditionalProperty("aByte"));
|
||||||
assertTrue(Timestamp.class.isAssignableFrom(rowIndex.getAdditionalProperty("aDate").getClass()));
|
assertTrue(Timestamp.class.isAssignableFrom(rowIndex.readAdditionalProperty("aDate").getClass()));
|
||||||
assertEquals(ContactDetails.class, rowIndex.getAdditionalProperty("aContact").getClass().getInterfaces()[0]);
|
assertEquals(ContactDetails.class, rowIndex.readAdditionalProperty("aContact").getClass().getInterfaces()[0]);
|
||||||
|
|
||||||
otservice.getContext().detachAll();
|
otservice.getContext().detachAll();
|
||||||
|
|
||||||
|
|
|
@ -100,11 +100,11 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase {
|
||||||
public void readWithReferences() {
|
public void readWithReferences() {
|
||||||
final Person person = container.getOrders().getByKey(8).getCustomerForOrder().refs().load();
|
final Person person = container.getOrders().getByKey(8).getCustomerForOrder().refs().load();
|
||||||
assertEquals("http://localhost:9080/stub/StaticService/V40/Static.svc/Customers(PersonID=1)",
|
assertEquals("http://localhost:9080/stub/StaticService/V40/Static.svc/Customers(PersonID=1)",
|
||||||
person.getEntityReferenceID());
|
person.readEntityReferenceID());
|
||||||
|
|
||||||
final OrderCollection orders = container.getCustomers().getByKey(1).getOrders().refs().execute();
|
final OrderCollection orders = container.getCustomers().getByKey(1).getOrders().refs().execute();
|
||||||
assertEquals("http://localhost:9080/stub/StaticService/V40/Static.svc/Orders(7)",
|
assertEquals("http://localhost:9080/stub/StaticService/V40/Static.svc/Orders(7)",
|
||||||
orders.iterator().next().getEntityReferenceID());
|
orders.iterator().next().readEntityReferenceID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -72,11 +72,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||||
@Test
|
@Test
|
||||||
public void read() {
|
public void read() {
|
||||||
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
|
Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load();
|
||||||
assertEquals(Double.class, row.getAdditionalProperty("Double").getClass());
|
assertEquals(Double.class, row.readAdditionalProperty("Double").getClass());
|
||||||
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
|
assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString());
|
||||||
|
|
||||||
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
|
row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load();
|
||||||
assertEquals(BigDecimal.class, row.getAdditionalProperty("Decimal").getClass());
|
assertEquals(BigDecimal.class, row.readAdditionalProperty("Decimal").getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,19 +126,19 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
|
||||||
otcontainer.flush();
|
otcontainer.flush();
|
||||||
|
|
||||||
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
|
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
|
||||||
assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
|
assertEquals(String.class, rowIndex.readAdditionalProperty("aString").getClass());
|
||||||
assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
|
assertEquals(Boolean.class, rowIndex.readAdditionalProperty("aBoolean").getClass());
|
||||||
assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
|
assertEquals(Double.class, rowIndex.readAdditionalProperty("aDouble").getClass());
|
||||||
assertEquals(Byte.class, rowIndex.getAdditionalProperty("aByte").getClass());
|
assertEquals(Byte.class, rowIndex.readAdditionalProperty("aByte").getClass());
|
||||||
assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte"));
|
assertEquals(Byte.MAX_VALUE, rowIndex.readAdditionalProperty("aByte"));
|
||||||
assertTrue(Calendar.class.isAssignableFrom(rowIndex.getAdditionalProperty("aDate").getClass()));
|
assertTrue(Calendar.class.isAssignableFrom(rowIndex.readAdditionalProperty("aDate").getClass()));
|
||||||
assertEquals(ContactDetails.class, rowIndex.getAdditionalProperty("aContact").getClass().getInterfaces()[0]);
|
assertEquals(ContactDetails.class, rowIndex.readAdditionalProperty("aContact").getClass().getInterfaces()[0]);
|
||||||
assertEquals(Color.class, rowIndex.getAdditionalProperty("aColor").getClass());
|
assertEquals(Color.class, rowIndex.readAdditionalProperty("aColor").getClass());
|
||||||
assertEquals(Color.Green, rowIndex.getAdditionalProperty("aColor"));
|
assertEquals(Color.Green, rowIndex.readAdditionalProperty("aColor"));
|
||||||
assertEquals("Fabio", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).getFirstName());
|
assertEquals("Fabio", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).getFirstName());
|
||||||
assertEquals("Martelli", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).getLastName());
|
assertEquals("Martelli", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).getLastName());
|
||||||
assertEquals("fabio.martelli@tirasa.net", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).
|
assertEquals("fabio.martelli@tirasa.net", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).
|
||||||
getAdditionalProperty("email"));
|
readAdditionalProperty("email"));
|
||||||
|
|
||||||
otservice.getContext().detachAll();
|
otservice.getContext().detachAll();
|
||||||
|
|
||||||
|
|
|
@ -51,26 +51,26 @@ public class SingletonTestITCase extends AbstractTestITCase {
|
||||||
@Test
|
@Test
|
||||||
public void readWithAnnotations() {
|
public void readWithAnnotations() {
|
||||||
final Company company = container.getCompany().load();
|
final Company company = container.getCompany().load();
|
||||||
assertTrue(company.getAnnotationTerms().isEmpty());
|
assertTrue(company.readAnnotationTerms().isEmpty());
|
||||||
|
|
||||||
final Person boss = container.getBoss().load();
|
final Person boss = container.getBoss().load();
|
||||||
assertEquals(2, boss.getPersonID(), 0);
|
assertEquals(2, boss.getPersonID(), 0);
|
||||||
|
|
||||||
assertEquals(1, boss.getAnnotationTerms().size());
|
assertEquals(1, boss.readAnnotationTerms().size());
|
||||||
Object isBoss = boss.getAnnotation(IsBoss.class);
|
Object isBoss = boss.readAnnotation(IsBoss.class);
|
||||||
assertTrue(isBoss instanceof Boolean);
|
assertTrue(isBoss instanceof Boolean);
|
||||||
assertTrue((Boolean) isBoss);
|
assertTrue((Boolean) isBoss);
|
||||||
|
|
||||||
Annotatable annotations = boss.annotations().getFirstNameAnnotations();
|
Annotatable annotations = boss.annotations().getFirstNameAnnotations();
|
||||||
assertTrue(annotations.getAnnotationTerms().isEmpty());
|
assertTrue(annotations.readAnnotationTerms().isEmpty());
|
||||||
|
|
||||||
annotations = boss.annotations().getLastNameAnnotations();
|
annotations = boss.annotations().getLastNameAnnotations();
|
||||||
isBoss = annotations.getAnnotation(IsBoss.class);
|
isBoss = annotations.readAnnotation(IsBoss.class);
|
||||||
assertTrue(isBoss instanceof Boolean);
|
assertTrue(isBoss instanceof Boolean);
|
||||||
assertFalse((Boolean) isBoss);
|
assertFalse((Boolean) isBoss);
|
||||||
|
|
||||||
annotations = boss.annotations().getParentAnnotations();
|
annotations = boss.annotations().getParentAnnotations();
|
||||||
isBoss = annotations.getAnnotation(IsBoss.class);
|
isBoss = annotations.readAnnotation(IsBoss.class);
|
||||||
assertTrue(isBoss instanceof Boolean);
|
assertTrue(isBoss instanceof Boolean);
|
||||||
assertFalse((Boolean) isBoss);
|
assertFalse((Boolean) isBoss);
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,11 +366,10 @@ public final class URIUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpEntity buildInputStreamEntity(final CommonODataClient<?> client, final InputStream input) {
|
public static HttpEntity buildInputStreamEntity(final CommonODataClient<?> client, final InputStream input) {
|
||||||
HttpEntity entity;
|
AbstractHttpEntity entity;
|
||||||
|
boolean useChunked = client.getConfiguration().isUseChuncked();
|
||||||
|
|
||||||
if (!shouldUseRepeatableHttpBodyEntry(client)) {
|
if (shouldUseRepeatableHttpBodyEntry(client) || !useChunked) {
|
||||||
entity = new InputStreamEntity(input, -1);
|
|
||||||
} else {
|
|
||||||
byte[] bytes = new byte[0];
|
byte[] bytes = new byte[0];
|
||||||
try {
|
try {
|
||||||
bytes = IOUtils.toByteArray(input);
|
bytes = IOUtils.toByteArray(input);
|
||||||
|
@ -380,10 +379,18 @@ public final class URIUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
entity = new ByteArrayEntity(bytes);
|
entity = new ByteArrayEntity(bytes);
|
||||||
|
} else {
|
||||||
|
entity = new InputStreamEntity(input, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!useChunked && entity.getContentLength() < 0) {
|
||||||
|
LOG.error("Could not determine length - request will be sent as chunked.");
|
||||||
|
useChunked = true;
|
||||||
|
}
|
||||||
// both entities can be sent in chunked way or not
|
// both entities can be sent in chunked way or not
|
||||||
((AbstractHttpEntity) entity).setChunked(client.getConfiguration().isUseChuncked());
|
entity.setChunked(useChunked);
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.olingo.server.core;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
|
||||||
import org.apache.olingo.server.api.ODataServerError;
|
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
|
||||||
|
|
||||||
public class ODataExceptionHandler {
|
|
||||||
|
|
||||||
public Locale requestedLocale;
|
|
||||||
public ODataFormat requestedFormat = ODataFormat.JSON;
|
|
||||||
|
|
||||||
public void handle(ODataResponse resp, Exception e) {
|
|
||||||
if (resp.getStatusCode() == 0) {
|
|
||||||
resp.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
||||||
}
|
|
||||||
ODataServerError error = new ODataServerError();
|
|
||||||
if (e instanceof ODataTranslatedException) {
|
|
||||||
error.setMessage(((ODataTranslatedException) e).getTranslatedMessage(requestedLocale).getMessage());
|
|
||||||
} else {
|
|
||||||
error.setMessage(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
ODataSerializer serializer = OData.newInstance().createSerializer(requestedFormat);
|
|
||||||
resp.setContent(serializer.error(error));
|
|
||||||
} catch (final ODataSerializerException e1) {}
|
|
||||||
// Set header
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,30 +20,75 @@ package org.apache.olingo.server.core;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
import org.apache.olingo.server.api.ODataApplicationException;
|
||||||
import org.apache.olingo.server.api.ODataServerError;
|
import org.apache.olingo.server.api.ODataServerError;
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
import org.apache.olingo.server.api.ODataTranslatedException;
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException.ODataErrorMessage;
|
import org.apache.olingo.server.api.ODataTranslatedException.ODataErrorMessage;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||||
|
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
||||||
|
|
||||||
public class ODataExceptionHelper {
|
public class ODataExceptionHelper {
|
||||||
|
|
||||||
public static ODataServerError createServerErrorObject(Exception e, int statusCode) {
|
public static ODataServerError createServerErrorObject(UriValidationException e, Locale requestedLocale) {
|
||||||
ODataServerError serverError = basicServerError(e);
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
serverError.setStatusCode(statusCode);
|
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||||
serverError.setLocale(Locale.ENGLISH);
|
return serverError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(UriParserSemanticException e, Locale requestedLocale) {
|
||||||
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
|
if(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND.equals(e.getMessageKey())
|
||||||
|
|| UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND.equals(e.getMessageKey())
|
||||||
|
|| UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE.equals(e.getMessageKey())){
|
||||||
|
serverError.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
|
||||||
|
}else{
|
||||||
|
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
return serverError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(UriParserSyntaxException e, Locale requestedLocale) {
|
||||||
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
|
if(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE.equals(e.getMessageKey())){
|
||||||
|
serverError.setStatusCode(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode());
|
||||||
|
}else{
|
||||||
|
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
return serverError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(UriParserException e, Locale requestedLocale) {
|
||||||
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
|
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||||
|
return serverError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(ContentNegotiatorException e, Locale requestedLocale) {
|
||||||
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
|
serverError.setStatusCode(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode());
|
||||||
return serverError;
|
return serverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ODataServerError createServerErrorObject(ODataTranslatedException e, int statusCode,
|
public static ODataServerError createServerErrorObject(ODataHandlerException e, Locale requestedLocale) {
|
||||||
Locale requestedLocale) {
|
ODataServerError serverError = basicTranslatedError(e, requestedLocale);
|
||||||
ODataServerError serverError = basicServerError(e);
|
if (ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED.equals(e.getMessageKey())
|
||||||
ODataErrorMessage translatedMessage = e.getTranslatedMessage(requestedLocale);
|
|| ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED.equals(e.getMessageKey())
|
||||||
serverError.setMessage(translatedMessage.getMessage());
|
|| ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED.equals(e.getMessageKey())) {
|
||||||
serverError.setLocale(translatedMessage.getLocale());
|
serverError.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
||||||
serverError.setStatusCode(statusCode);
|
} else if (ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED.equals(e.getMessageKey())) {
|
||||||
|
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
return serverError;
|
return serverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(ODataTranslatedException e, Locale requestedLocale) {
|
||||||
|
return basicTranslatedError(e, requestedLocale);
|
||||||
|
}
|
||||||
|
|
||||||
public static ODataServerError createServerErrorObject(ODataApplicationException e) {
|
public static ODataServerError createServerErrorObject(ODataApplicationException e) {
|
||||||
ODataServerError serverError = basicServerError(e);
|
ODataServerError serverError = basicServerError(e);
|
||||||
serverError.setStatusCode(e.getStatusCode());
|
serverError.setStatusCode(e.getStatusCode());
|
||||||
|
@ -51,9 +96,25 @@ public class ODataExceptionHelper {
|
||||||
serverError.setCode(e.getODataErrorCode());
|
serverError.setCode(e.getODataErrorCode());
|
||||||
return serverError;
|
return serverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ODataServerError createServerErrorObject(Exception e) {
|
||||||
|
ODataServerError serverError = basicServerError(e);
|
||||||
|
serverError.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
serverError.setLocale(Locale.ENGLISH);
|
||||||
|
return serverError;
|
||||||
|
}
|
||||||
|
|
||||||
private static ODataServerError basicServerError(Exception e) {
|
private static ODataServerError basicServerError(Exception e) {
|
||||||
ODataServerError serverError = new ODataServerError().setException(e).setMessage(e.getMessage());
|
ODataServerError serverError = new ODataServerError().setException(e).setMessage(e.getMessage());
|
||||||
return serverError;
|
return serverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ODataServerError basicTranslatedError(ODataTranslatedException e, Locale requestedLocale) {
|
||||||
|
ODataServerError serverError = basicServerError(e);
|
||||||
|
ODataErrorMessage translatedMessage = e.getTranslatedMessage(requestedLocale);
|
||||||
|
serverError.setMessage(translatedMessage.getMessage());
|
||||||
|
serverError.setLocale(translatedMessage.getLocale());
|
||||||
|
serverError.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
return serverError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.apache.olingo.server.core;
|
package org.apache.olingo.server.core;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
|
@ -28,15 +27,14 @@ import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
import org.apache.olingo.server.api.ODataApplicationException;
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
import org.apache.olingo.server.api.ODataRequest;
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
import org.apache.olingo.server.api.ODataServerError;
|
import org.apache.olingo.server.api.ODataServerError;
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
import org.apache.olingo.server.api.ODataTranslatedException;
|
||||||
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
|
||||||
import org.apache.olingo.server.api.processor.DefaultProcessor;
|
import org.apache.olingo.server.api.processor.DefaultProcessor;
|
||||||
|
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
||||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||||
import org.apache.olingo.server.api.processor.ExceptionProcessor;
|
import org.apache.olingo.server.api.processor.ExceptionProcessor;
|
||||||
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
||||||
|
@ -48,6 +46,8 @@ import org.apache.olingo.server.api.uri.UriResourceNavigation;
|
||||||
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
|
||||||
import org.apache.olingo.server.core.uri.parser.Parser;
|
import org.apache.olingo.server.core.uri.parser.Parser;
|
||||||
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
import org.apache.olingo.server.core.uri.parser.UriParserException;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
|
||||||
|
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
|
||||||
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
import org.apache.olingo.server.core.uri.validator.UriValidationException;
|
||||||
import org.apache.olingo.server.core.uri.validator.UriValidator;
|
import org.apache.olingo.server.core.uri.validator.UriValidator;
|
||||||
|
|
||||||
|
@ -73,30 +73,32 @@ public class ODataHandler {
|
||||||
|
|
||||||
processInternal(request, requestedContentType, response);
|
processInternal(request, requestedContentType, response);
|
||||||
|
|
||||||
} catch (final UriParserException e) {
|
|
||||||
handleException(request, response,
|
|
||||||
ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.BAD_REQUEST.getStatusCode(), null),
|
|
||||||
requestedContentType);
|
|
||||||
} catch (final UriValidationException e) {
|
} catch (final UriValidationException e) {
|
||||||
handleException(request, response,
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.BAD_REQUEST.getStatusCode(), null),
|
handleException(request, response, serverError, null);
|
||||||
requestedContentType);
|
} catch (final UriParserSemanticException e) {
|
||||||
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
|
handleException(request, response, serverError, null);
|
||||||
|
} catch (final UriParserSyntaxException e) {
|
||||||
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
|
handleException(request, response, serverError, null);
|
||||||
|
} catch (final UriParserException e) {
|
||||||
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
|
handleException(request, response, serverError, null);
|
||||||
} catch (ContentNegotiatorException e) {
|
} catch (ContentNegotiatorException e) {
|
||||||
Locale requestedLocale = null;
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
ODataServerError serverError =
|
handleException(request, response, serverError, null);
|
||||||
ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(),
|
} catch (ODataHandlerException e) {
|
||||||
requestedLocale);
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
handleException(request, response, serverError, requestedContentType);
|
handleException(request, response, serverError, null);
|
||||||
} catch (ODataTranslatedException e) {
|
} catch (ODataTranslatedException e) {
|
||||||
Locale requestedLocale = null;
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||||
ODataServerError serverError =
|
|
||||||
ODataExceptionHelper.createServerErrorObject(e, response.getStatusCode(), requestedLocale);
|
|
||||||
handleException(request, response, serverError, requestedContentType);
|
handleException(request, response, serverError, requestedContentType);
|
||||||
} catch (ODataApplicationException e) {
|
} catch (ODataApplicationException e) {
|
||||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||||
handleException(request, response, serverError, requestedContentType);
|
handleException(request, response, serverError, requestedContentType);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, response.getStatusCode());
|
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
|
||||||
handleException(request, response, serverError, requestedContentType);
|
handleException(request, response, serverError, requestedContentType);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
|
@ -118,7 +120,7 @@ public class ODataHandler {
|
||||||
|
|
||||||
switch (uriInfo.getKind()) {
|
switch (uriInfo.getKind()) {
|
||||||
case metadata:
|
case metadata:
|
||||||
MetadataProcessor mp = selectProcessor(MetadataProcessor.class, response);
|
MetadataProcessor mp = selectProcessor(MetadataProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
|
||||||
|
@ -127,10 +129,10 @@ public class ODataHandler {
|
||||||
break;
|
break;
|
||||||
case service:
|
case service:
|
||||||
if ("".equals(request.getRawODataPath())) {
|
if ("".equals(request.getRawODataPath())) {
|
||||||
RedirectProcessor rdp = selectProcessor(RedirectProcessor.class, response);
|
RedirectProcessor rdp = selectProcessor(RedirectProcessor.class);
|
||||||
rdp.redirect(request, response);
|
rdp.redirect(request, response);
|
||||||
} else {
|
} else {
|
||||||
ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class, response);
|
ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
|
||||||
|
@ -143,7 +145,6 @@ public class ODataHandler {
|
||||||
handleResourceDispatching(request, response, uriInfo);
|
handleResourceDispatching(request, response, uriInfo);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +154,7 @@ public class ODataHandler {
|
||||||
ContentType requestedContentType) {
|
ContentType requestedContentType) {
|
||||||
ExceptionProcessor exceptionProcessor;
|
ExceptionProcessor exceptionProcessor;
|
||||||
try {
|
try {
|
||||||
exceptionProcessor = selectProcessor(ExceptionProcessor.class, response);
|
exceptionProcessor = selectProcessor(ExceptionProcessor.class);
|
||||||
} catch (ODataTranslatedException e) {
|
} catch (ODataTranslatedException e) {
|
||||||
exceptionProcessor = new DefaultProcessor();
|
exceptionProcessor = new DefaultProcessor();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +174,7 @@ public class ODataHandler {
|
||||||
case entitySet:
|
case entitySet:
|
||||||
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
||||||
if (request.getMethod().equals(HttpMethod.GET)) {
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
||||||
EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class, response);
|
EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
|
||||||
|
@ -181,20 +182,18 @@ public class ODataHandler {
|
||||||
|
|
||||||
cp.readCollection(request, response, uriInfo, requestedContentType);
|
cp.readCollection(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (request.getMethod().equals(HttpMethod.GET)) {
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
||||||
EntityProcessor ep = selectProcessor(EntityProcessor.class, response);
|
EntityProcessor ep = selectProcessor(EntityProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||||
|
|
||||||
ep.readEntity(request, response, uriInfo, requestedContentType);
|
ep.readEntity(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +202,7 @@ public class ODataHandler {
|
||||||
case navigationProperty:
|
case navigationProperty:
|
||||||
if (((UriResourceNavigation) lastPathSegment).isCollection()) {
|
if (((UriResourceNavigation) lastPathSegment).isCollection()) {
|
||||||
if (request.getMethod().equals(HttpMethod.GET)) {
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
||||||
EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class, response);
|
EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
|
||||||
|
@ -211,27 +210,24 @@ public class ODataHandler {
|
||||||
|
|
||||||
cp.readCollection(request, response, uriInfo, requestedContentType);
|
cp.readCollection(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (request.getMethod().equals(HttpMethod.GET)) {
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
||||||
EntityProcessor ep = selectProcessor(EntityProcessor.class, response);
|
EntityProcessor ep = selectProcessor(EntityProcessor.class);
|
||||||
|
|
||||||
requestedContentType =
|
requestedContentType =
|
||||||
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
|
||||||
|
|
||||||
ep.readEntity(request, response, uriInfo, requestedContentType);
|
ep.readEntity(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
@ -244,20 +240,18 @@ public class ODataHandler {
|
||||||
|
|
||||||
if (maxVersion != null) {
|
if (maxVersion != null) {
|
||||||
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
|
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
|
||||||
response.setStatusCode(400);
|
|
||||||
throw new ODataHandlerException("ODataVersion not supported: " + maxVersion,
|
throw new ODataHandlerException("ODataVersion not supported: " + maxVersion,
|
||||||
ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
|
ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED, maxVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Processor> T selectProcessor(final Class<T> cls, ODataResponse response)
|
private <T extends Processor> T selectProcessor(final Class<T> cls)
|
||||||
throws ODataTranslatedException {
|
throws ODataTranslatedException {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
T p = (T) processors.get(cls);
|
T p = (T) processors.get(cls);
|
||||||
|
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
|
||||||
throw new ODataHandlerException("Processor: " + cls.getName() + " not registered.",
|
throw new ODataHandlerException("Processor: " + cls.getName() + " not registered.",
|
||||||
ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getName());
|
ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.olingo.server.core;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
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.ODataFormat;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
|
@ -27,8 +29,10 @@ import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.ODataHttpHandler;
|
import org.apache.olingo.server.api.ODataHttpHandler;
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
import org.apache.olingo.server.api.ODataRequest;
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
|
import org.apache.olingo.server.api.ODataServerError;
|
||||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
import org.apache.olingo.server.api.ODataTranslatedException;
|
||||||
import org.apache.olingo.server.api.processor.Processor;
|
import org.apache.olingo.server.api.processor.Processor;
|
||||||
|
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -36,12 +40,14 @@ import org.slf4j.LoggerFactory;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
|
@ -85,8 +91,27 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
||||||
resp.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
resp.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ODataExceptionHandler exceptionHandler = new ODataExceptionHandler();
|
|
||||||
exceptionHandler.handle(resp, e);
|
ODataServerError error = new ODataServerError();
|
||||||
|
if (e instanceof ODataTranslatedException) {
|
||||||
|
error.setMessage(((ODataTranslatedException) e).getTranslatedMessage(Locale.ENGLISH).getMessage());
|
||||||
|
} else {
|
||||||
|
error.setMessage(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ODataSerializer serializer = OData.newInstance().createSerializer(ODataFormat.JSON);
|
||||||
|
resp.setContent(serializer.error(error));
|
||||||
|
} catch (final ODataSerializerException e1) {
|
||||||
|
// This should never happen but to be sure we have this catch here to prevent sending a stacktrace to a client.
|
||||||
|
String responseContent =
|
||||||
|
"{\"error\":{\"code\":null,\"message\":\"An unexpected exception occurred in the ODataHttpHandler during " +
|
||||||
|
"error processing with message: " + e.getMessage() + "\"}}";
|
||||||
|
resp.setContent(new ByteArrayInputStream(responseContent.getBytes()));
|
||||||
|
resp.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
|
||||||
|
}
|
||||||
|
// Set header
|
||||||
|
resp.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class Parser {
|
||||||
formatOption.setFormat(option.value);
|
formatOption.setFormat(option.value);
|
||||||
} else {
|
} else {
|
||||||
throw new UriParserSyntaxException("Illegal value of $format option!",
|
throw new UriParserSyntaxException("Illegal value of $format option!",
|
||||||
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
|
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE,
|
||||||
option.name, option.value);
|
option.name, option.value);
|
||||||
}
|
}
|
||||||
context.contextUriInfo.setSystemQueryOption(formatOption);
|
context.contextUriInfo.setSystemQueryOption(formatOption);
|
||||||
|
|
|
@ -358,6 +358,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
|
|
||||||
if (lastResourcePart == null) {
|
if (lastResourcePart == null) {
|
||||||
if (context.contextTypes.size() == 0) {
|
if (context.contextTypes.size() == 0) {
|
||||||
|
if(checkFirst && ctx.vNS == null){
|
||||||
|
throw wrap(new UriParserSemanticException(
|
||||||
|
"Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name '" + odi + "'.",
|
||||||
|
UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND, odi));
|
||||||
|
}
|
||||||
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
|
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
|
||||||
+ "resource parts",
|
+ "resource parts",
|
||||||
UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS, odi));
|
UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS, odi));
|
||||||
|
@ -396,9 +401,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
EdmElement property = structType.getProperty(odi);
|
EdmElement property = structType.getProperty(odi);
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
|
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
|
||||||
+ structType.getNamespace() + "." + structType.getName() + "'",
|
+ structType.getNamespace() + "." + structType.getName() + "'",
|
||||||
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
|
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
|
||||||
structType.getFullQualifiedName().toString(), odi));
|
structType.getFullQualifiedName().toString(), odi));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property instanceof EdmProperty) {
|
if (property instanceof EdmProperty) {
|
||||||
|
@ -466,7 +471,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterEntityType) + "' behind '"
|
+ getName(filterEntityType) + "' behind '"
|
||||||
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
|
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterEntityType)));
|
getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterEntityType)));
|
||||||
}
|
}
|
||||||
lastPartWithKeys.setEntryTypeFilter(filterEntityType);
|
lastPartWithKeys.setEntryTypeFilter(filterEntityType);
|
||||||
return null;
|
return null;
|
||||||
|
@ -476,7 +481,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterEntityType) + "' behind '"
|
+ getName(filterEntityType) + "' behind '"
|
||||||
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
|
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterEntityType)));
|
getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterEntityType)));
|
||||||
}
|
}
|
||||||
lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
|
lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
|
||||||
return null;
|
return null;
|
||||||
|
@ -488,7 +493,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterEntityType) + "' behind '"
|
+ getName(filterEntityType) + "' behind '"
|
||||||
+ getName(lastPartTyped.getTypeFilter()) + "'",
|
+ getName(lastPartTyped.getTypeFilter()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartTyped.getTypeFilter()), getName(filterEntityType)));
|
getName(lastPartTyped.getTypeFilter()), getName(filterEntityType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPartTyped.setTypeFilter(filterEntityType);
|
lastPartTyped.setTypeFilter(filterEntityType);
|
||||||
|
@ -512,7 +517,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
throw wrap(new UriParserSemanticException(
|
throw wrap(new UriParserSemanticException(
|
||||||
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
|
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
|
||||||
+ getName(filterComplexType) + "'",
|
+ getName(filterComplexType) + "'",
|
||||||
UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, getName(source.type)));
|
UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, getName(source.type)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// is simple complex type cast
|
// is simple complex type cast
|
||||||
|
@ -540,7 +545,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterComplexType) + "' behind '"
|
+ getName(filterComplexType) + "' behind '"
|
||||||
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
|
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterComplexType)));
|
getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterComplexType)));
|
||||||
}
|
}
|
||||||
lastPartWithKeys.setEntryTypeFilter(filterComplexType);
|
lastPartWithKeys.setEntryTypeFilter(filterComplexType);
|
||||||
return null;
|
return null;
|
||||||
|
@ -550,7 +555,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterComplexType) + "' behind '"
|
+ getName(filterComplexType) + "' behind '"
|
||||||
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
|
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterComplexType)));
|
getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterComplexType)));
|
||||||
}
|
}
|
||||||
lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
|
lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
|
||||||
return null;
|
return null;
|
||||||
|
@ -563,7 +568,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
|
||||||
+ getName(filterComplexType) + "' behind '"
|
+ getName(filterComplexType) + "' behind '"
|
||||||
+ getName(lastPartTyped.getTypeFilter()) + "'",
|
+ getName(lastPartTyped.getTypeFilter()) + "'",
|
||||||
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
|
||||||
getName(lastPartTyped.getTypeFilter()), getName(filterComplexType)));
|
getName(lastPartTyped.getTypeFilter()), getName(filterComplexType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPartTyped.setTypeFilter(filterComplexType);
|
lastPartTyped.setTypeFilter(filterComplexType);
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class UriParserSemanticException extends UriParserException {
|
||||||
ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT,
|
ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT,
|
||||||
COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED,
|
COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED,
|
||||||
NOT_FOR_ENTITY_TYPE,
|
NOT_FOR_ENTITY_TYPE,
|
||||||
PREVIOUS_PART_TYPED;
|
PREVIOUS_PART_TYPED,
|
||||||
|
/** parameter: resource_name */RESOURCE_NOT_FOUND;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
|
@ -27,7 +27,8 @@ public class UriParserSyntaxException extends UriParserException {
|
||||||
/** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION,
|
/** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION,
|
||||||
/** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
|
/** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
|
||||||
SYNTAX,
|
SYNTAX,
|
||||||
SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE;
|
SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE,
|
||||||
|
/** parameter: query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
|
@ -26,6 +26,7 @@ ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not su
|
||||||
|
|
||||||
UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.
|
UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.
|
||||||
UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'.
|
UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'.
|
||||||
|
UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE=The system query option $value must be either json, xml, atom or a valid content-type. The value '%1$s' is neither.
|
||||||
UriParserSyntaxException.SYNTAX=The URI is malformed.
|
UriParserSyntaxException.SYNTAX=The URI is malformed.
|
||||||
UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
|
UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ UriParserSemanticException.ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT=Only sim
|
||||||
UriParserSemanticException.COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED=A complex property of an entity type is expected.
|
UriParserSemanticException.COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED=A complex property of an entity type is expected.
|
||||||
UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
|
UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
|
||||||
UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
|
UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
|
||||||
|
UriParserSemanticException.RESOURCE_NOT_FOUND=Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name '%1$s'.
|
||||||
|
|
||||||
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
|
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
|
||||||
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
|
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.olingo.server.core;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.olingo.commons.api.ODataException;
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||||
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
|
import org.apache.olingo.server.api.OData;
|
||||||
|
import org.apache.olingo.server.api.ODataApplicationException;
|
||||||
|
import org.apache.olingo.server.api.ODataRequest;
|
||||||
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
|
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||||
|
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
||||||
|
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
||||||
|
import org.apache.olingo.server.api.uri.UriInfo;
|
||||||
|
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ODataHandlerExceptionHandlingTest {
|
||||||
|
private ODataHandler handler;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void before() {
|
||||||
|
OData odata = OData.newInstance();
|
||||||
|
Edm edm = odata.createEdm(new EdmTechProvider());
|
||||||
|
|
||||||
|
handler = new ODataHandler(odata, edm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUriParserExceptionResultsInRightResponseNotFound() throws Exception {
|
||||||
|
ODataRequest request = new ODataRequest();
|
||||||
|
|
||||||
|
request.setMethod(HttpMethod.GET);
|
||||||
|
request.setRawODataPath("NotFound");
|
||||||
|
|
||||||
|
ODataResponse response = handler.process(request);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUriParserExceptionResultsInRightResponseBadRequest() throws Exception {
|
||||||
|
ODataRequest request = new ODataRequest();
|
||||||
|
|
||||||
|
request.setMethod(HttpMethod.GET);
|
||||||
|
request.setRawODataPath("ESAllPrim('122')");
|
||||||
|
|
||||||
|
ODataResponse response = handler.process(request);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUriParserExceptionResultsInRightResponseEdmCause() throws Exception {
|
||||||
|
ODataRequest request = new ODataRequest();
|
||||||
|
|
||||||
|
request.setMethod(HttpMethod.GET);
|
||||||
|
request.setRawODataPath("EdmException");
|
||||||
|
|
||||||
|
OData odata = OData.newInstance();
|
||||||
|
Edm edm = odata.createEdm(new EdmProvider() {
|
||||||
|
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
|
||||||
|
throws ODataException {
|
||||||
|
throw new ODataException("msg");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ODataHandler localHandler = new ODataHandler(odata, edm);
|
||||||
|
|
||||||
|
ODataResponse response = localHandler.process(request);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
|
||||||
|
// TODO: Check for message in case of EdmException
|
||||||
|
System.out.println(IOUtils.toString(response.getContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithApplicationExceptionInProcessor() throws Exception {
|
||||||
|
ODataRequest request = new ODataRequest();
|
||||||
|
|
||||||
|
request.setMethod(HttpMethod.GET);
|
||||||
|
request.setRawODataPath("$metadata");
|
||||||
|
|
||||||
|
MetadataProcessor metadataProcessor = mock(MetadataProcessor.class);
|
||||||
|
doThrow(new ODataApplicationException("msg", 425, Locale.ENGLISH)).when(metadataProcessor).readMetadata(
|
||||||
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
handler.register(metadataProcessor);
|
||||||
|
|
||||||
|
ODataResponse response = handler.process(request);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals(425, response.getStatusCode());
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,35 +21,24 @@ package org.apache.olingo.server.core;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.doThrow;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.olingo.commons.api.ODataException;
|
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|
||||||
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpContentType;
|
import org.apache.olingo.commons.api.http.HttpContentType;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.ODataApplicationException;
|
|
||||||
import org.apache.olingo.server.api.ODataRequest;
|
import org.apache.olingo.server.api.ODataRequest;
|
||||||
import org.apache.olingo.server.api.ODataResponse;
|
import org.apache.olingo.server.api.ODataResponse;
|
||||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
|
||||||
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
|
||||||
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
||||||
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
|
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
|
||||||
import org.apache.olingo.server.api.uri.UriInfo;
|
|
||||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ODataHandlerTest {
|
public class ODataHandlerTest {
|
||||||
|
@ -223,6 +212,19 @@ public class ODataHandlerTest {
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
|
assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContentNegotiationNotSupported2() {
|
||||||
|
ODataRequest request = new ODataRequest();
|
||||||
|
|
||||||
|
request.setMethod(HttpMethod.GET);
|
||||||
|
request.setRawODataPath("$metadata");
|
||||||
|
request.setRawQueryPath("$format=notSupported");
|
||||||
|
|
||||||
|
ODataResponse response = handler.process(request);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnregisteredProcessor() {
|
public void testUnregisteredProcessor() {
|
||||||
|
@ -236,73 +238,4 @@ public class ODataHandlerTest {
|
||||||
assertEquals(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), response.getStatusCode());
|
assertEquals(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWithApplicationExceptionInProcessor() throws Exception {
|
|
||||||
ODataRequest request = new ODataRequest();
|
|
||||||
|
|
||||||
request.setMethod(HttpMethod.GET);
|
|
||||||
request.setRawODataPath("$metadata");
|
|
||||||
|
|
||||||
MetadataProcessor metadataProcessor = mock(MetadataProcessor.class);
|
|
||||||
doThrow(new ODataApplicationException("msg", 425, Locale.ENGLISH)).when(metadataProcessor).readMetadata(
|
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
|
||||||
|
|
||||||
handler.register(metadataProcessor);
|
|
||||||
|
|
||||||
ODataResponse response = handler.process(request);
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(425, response.getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Use this test
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testUriParserExceptionResultsInRightResponseNotFound() throws Exception {
|
|
||||||
ODataRequest request = new ODataRequest();
|
|
||||||
|
|
||||||
request.setMethod(HttpMethod.GET);
|
|
||||||
request.setRawODataPath("NotFound");
|
|
||||||
|
|
||||||
ODataResponse response = handler.process(request);
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Use this test
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testUriParserExceptionResultsInRightResponseBadRequest() throws Exception {
|
|
||||||
ODataRequest request = new ODataRequest();
|
|
||||||
|
|
||||||
request.setMethod(HttpMethod.GET);
|
|
||||||
request.setRawODataPath("ESAllPrim()");
|
|
||||||
|
|
||||||
ODataResponse response = handler.process(request);
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUriParserExceptionResultsInRightResponseEdmCause() throws Exception {
|
|
||||||
ODataRequest request = new ODataRequest();
|
|
||||||
|
|
||||||
request.setMethod(HttpMethod.GET);
|
|
||||||
request.setRawODataPath("EdmException");
|
|
||||||
|
|
||||||
OData odata = OData.newInstance();
|
|
||||||
Edm edm = odata.createEdm(new EdmProvider() {
|
|
||||||
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
|
|
||||||
throws ODataException {
|
|
||||||
throw new ODataException("msg");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ODataHandler localHandler = new ODataHandler(odata, edm);
|
|
||||||
|
|
||||||
ODataResponse response = localHandler.process(request);
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
|
|
||||||
// TODO: Check for message in case of EdmException
|
|
||||||
// System.out.println(IOUtils.toString(response.getContent()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -968,33 +968,33 @@ public class TestFullResourcePath {
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
||||||
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
|
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETAllKey")
|
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETAllKey")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim('1')/com.sap.odata.test1.ETAllKey")
|
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim('1')/com.sap.odata.test1.ETAllKey")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
||||||
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
|
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
|
||||||
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)")
|
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETAllKey")
|
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETAllKey")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ETBaseTwoKeyTwoPrim()")
|
testUri.runEx("ETBaseTwoKeyTwoPrim()")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
|
|
||||||
testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
|
testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
|
||||||
|
|
||||||
testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value")
|
testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value")
|
||||||
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
|
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -2553,15 +2553,15 @@ public class TestFullResourcePath {
|
||||||
.isKind(UriInfoKind.resource).goPath()
|
.isKind(UriInfoKind.resource).goPath()
|
||||||
.isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
|
.isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
|
||||||
testUri.runEx("ESKeyNav(1)?$format=noSlash")
|
testUri.runEx("ESKeyNav(1)?$format=noSlash")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
|
||||||
testUri.runEx("ESKeyNav(1)?$format=slashAtEnd/")
|
testUri.runEx("ESKeyNav(1)?$format=slashAtEnd/")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
|
||||||
testUri.runEx("ESKeyNav(1)?$format=/startsWithSlash")
|
testUri.runEx("ESKeyNav(1)?$format=/startsWithSlash")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
|
||||||
testUri.runEx("ESKeyNav(1)?$format=two/Slashes/tooMuch")
|
testUri.runEx("ESKeyNav(1)?$format=two/Slashes/tooMuch")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
|
||||||
testUri.runEx("ESKeyNav(1)?$format=")
|
testUri.runEx("ESKeyNav(1)?$format=")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue