You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/09/01 08:34:32 UTC
[1/7] git commit: [OLINGO-405] Set content length for not chunked
content
Repository: olingo-odata4
Updated Branches:
refs/heads/OLINGO-406 b81a2ee4f -> badb9916b
[OLINGO-405] Set content length for not chunked content
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/853bad6a
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/853bad6a
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/853bad6a
Branch: refs/heads/OLINGO-406
Commit: 853bad6aa9530aaeff1376d9f9df39fd7e97bd63
Parents: 931f132
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Aug 15 08:22:08 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Aug 15 15:14:07 2014 +0200
----------------------------------------------------------------------
.../apache/olingo/client/core/uri/URIUtils.java | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/853bad6a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
index 0fa78d2..fa36095 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIUtils.java
@@ -366,11 +366,10 @@ public final class URIUtils {
}
public static HttpEntity buildInputStreamEntity(final CommonODataClient<?> client, final InputStream input) {
- HttpEntity entity;
+ AbstractHttpEntity entity;
+ boolean useChunked = client.getConfiguration().isUseChuncked();
- if (!shouldUseRepeatableHttpBodyEntry(client)) {
- entity = new InputStreamEntity(input, -1);
- } else {
+ if (shouldUseRepeatableHttpBodyEntry(client) || !useChunked) {
byte[] bytes = new byte[0];
try {
bytes = IOUtils.toByteArray(input);
@@ -380,10 +379,18 @@ public final class URIUtils {
}
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
- ((AbstractHttpEntity) entity).setChunked(client.getConfiguration().isUseChuncked());
+ entity.setChunked(useChunked);
+
return entity;
}
[6/7] git commit: [OLINGO-406] Omit odata.type information for none
metadata
Posted by mi...@apache.org.
[OLINGO-406] Omit odata.type information for none metadata
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/deec7aa8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/deec7aa8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/deec7aa8
Branch: refs/heads/OLINGO-406
Commit: deec7aa854cd3b00d161ea63f5c5151fdaeb3054
Parents: b81a2ee
Author: mibo <mi...@apache.org>
Authored: Mon Sep 1 08:27:07 2014 +0200
Committer: mibo <mi...@apache.org>
Committed: Mon Sep 1 08:27:07 2014 +0200
----------------------------------------------------------------------
.../olingo/commons/core/serialization/JsonEntitySerializer.java | 2 +-
.../apache/olingo/commons/core/serialization/JsonSerializer.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/deec7aa8/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
index b7c2f13..5576e19 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonEntitySerializer.java
@@ -74,7 +74,7 @@ public class JsonEntitySerializer extends JsonSerializer {
}
}
- if (StringUtils.isNotBlank(entity.getType()) && format == ODataFormat.JSON_FULL_METADATA) {
+ if (StringUtils.isNotBlank(entity.getType()) && format != ODataFormat.JSON_NO_METADATA) {
jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE),
new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external(version));
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/deec7aa8/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
index b6f857f..6955b11 100755
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonSerializer.java
@@ -314,7 +314,7 @@ public class JsonSerializer implements ODataSerializer {
throws IOException, EdmPrimitiveTypeException {
jgen.writeStartObject();
- if (typeInfo != null && format == ODataFormat.JSON_FULL_METADATA) {
+ if (typeInfo != null && format != ODataFormat.JSON_NO_METADATA) {
jgen.writeStringField(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), typeInfo.external(version));
}
@@ -361,7 +361,7 @@ public class JsonSerializer implements ODataSerializer {
if (StringUtils.isBlank(type) && valuable.isPrimitive() || valuable.isNull()) {
type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString();
}
- if (StringUtils.isNotBlank(type) && format == ODataFormat.JSON_FULL_METADATA) {
+ if (StringUtils.isNotBlank(type) && format != ODataFormat.JSON_NO_METADATA) {
jgen.writeFieldName(
name + StringUtils.prependIfMissing(version.getJsonName(ODataServiceVersion.JsonKey.TYPE), "@"));
jgen.writeString(new EdmTypeInfo.Builder().setTypeExpression(type).build().external(version));
[5/7] git commit: [OLINGO-350] Delete printStackTrace in test
Posted by mi...@apache.org.
[OLINGO-350] Delete printStackTrace in test
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a30d2f82
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a30d2f82
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a30d2f82
Branch: refs/heads/OLINGO-406
Commit: a30d2f8214a2ed9cb7523d335b7bf31a3bd38c19
Parents: a0f8f35
Author: Christian Amend <ch...@apache.org>
Authored: Fri Aug 29 15:11:35 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Aug 29 15:11:35 2014 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/olingo/server/core/ODataHandler.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a30d2f82/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index 2a8f6f5..0893d09 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -98,7 +98,6 @@ public class ODataHandler {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
handleException(request, response, serverError, requestedContentType);
} catch (Exception e) {
- e.printStackTrace();
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
handleException(request, response, serverError, requestedContentType);
}
[3/7] git commit: [OLINGO-415] Java client-proxy code getter method
has performane issue: invoke() checks get- before isSelfMethods().
Posted by mi...@apache.org.
[OLINGO-415] Java client-proxy code getter method has performane issue: invoke() checks get- before isSelfMethods().
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9c78784d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9c78784d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9c78784d
Branch: refs/heads/OLINGO-406
Commit: 9c78784deea668e2e2999141569fa1450bd498a2
Parents: 58619c9
Author: challenh <ch...@microsoft.com>
Authored: Mon Aug 25 00:10:52 2014 +0800
Committer: challenh <ch...@microsoft.com>
Committed: Mon Aug 25 00:10:52 2014 +0800
----------------------------------------------------------------------
.../olingo/ext/proxy/api/AbstractOpenType.java | 6 +-
.../olingo/ext/proxy/api/Annotatable.java | 6 +-
.../apache/olingo/ext/proxy/api/EntityType.java | 3 +-
.../AbstractStructuredInvocationHandler.java | 75 +++++++++++---------
.../commons/AnnotatableInvocationHandler.java | 4 +-
.../proxy/commons/EntityInvocationHandler.java | 7 +-
.../olingo/fit/proxy/v3/OpenTypeTestITCase.java | 18 ++---
.../fit/proxy/v4/APIBasicDesignTestITCase.java | 4 +-
.../olingo/fit/proxy/v4/OpenTypeTestITCase.java | 30 ++++----
.../fit/proxy/v4/SingletonTestITCase.java | 12 ++--
10 files changed, 88 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java
index a4d9bf2..b28ced9 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java
@@ -26,7 +26,9 @@ public interface AbstractOpenType {
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();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Annotatable.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Annotatable.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Annotatable.java
index 08af72b..70048ba 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Annotatable.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Annotatable.java
@@ -27,8 +27,10 @@ public interface Annotatable extends Serializable {
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();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/EntityType.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/EntityType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/EntityType.java
index 891b2db..e68eab9 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/EntityType.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/EntityType.java
@@ -32,5 +32,6 @@ public interface EntityType<T extends StructuredType<?>> extends StructuredType<
*
* @return entity reference ID.
*/
- String getEntityReferenceID();
+ // use read- instead of get- for .invoke() to distinguish it from entity property getter.
+ String readEntityReferenceID();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
index 43c161f..aaae42c 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
@@ -158,41 +158,13 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- 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();
+ if (method.getName().startsWith("get")) {
+ // Here need check "get"/"set" first for better get-/set- performance because
+ // the below if-statements are really time-consuming, even twice slower than "get" body.
- 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 if (method.getName().startsWith("get")) {
- // Assumption: for each getter will always exist a setter and viceversa.
+ // Assumption: for each getter will always exist a setter and viceversa.
// get method annotation and check if it exists as expected
+
final Object res;
final Method getter = typeRef.getMethod(method.getName());
@@ -234,6 +206,38 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
}
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 {
throw new NoSuchMethodException(method.getName());
}
@@ -517,7 +521,8 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
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);
}
@@ -525,7 +530,7 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
return propertyChanges;
}
- public Collection<String> getAdditionalPropertyNames() {
+ public Collection<String> readAdditionalPropertyNames() {
final Set<String> res = new HashSet<String>(propertyChanges.keySet());
final Set<String> propertyNames = new HashSet<String>();
for (Method method : typeRef.getMethods()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java
index 6409d24..a219cdc 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AnnotatableInvocationHandler.java
@@ -141,7 +141,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
}
@Override
- public Object getAnnotation(final Class<? extends AbstractTerm> term) {
+ public Object readAnnotation(final Class<? extends AbstractTerm> term) {
Object res = null;
if (annotations.containsKey(term)) {
@@ -171,7 +171,7 @@ public class AnnotatableInvocationHandler extends AbstractInvocationHandler impl
}
@Override
- public Collection<Class<? extends AbstractTerm>> getAnnotationTerms() {
+ public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() {
return entityHandler.getEntity() instanceof ODataEntity
? CoreUtils.getAnnotationTerms(service, internalAnnotations())
: Collections.<Class<? extends AbstractTerm>>emptyList();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
index 32d3b26..2a23b11 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
@@ -406,7 +406,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
}
@Override
- public Object getAnnotation(final Class<? extends AbstractTerm> term) {
+ public Object readAnnotation(final Class<? extends AbstractTerm> term) {
Object res = null;
if (annotations.containsKey(term)) {
@@ -436,7 +436,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
}
@Override
- public Collection<Class<? extends AbstractTerm>> getAnnotationTerms() {
+ public Collection<Class<? extends AbstractTerm>> readAnnotationTerms() {
return getEntity() instanceof ODataEntity
? CoreUtils.getAnnotationTerms(service, ((ODataEntity) getEntity()).getAnnotations())
: Collections.<Class<? extends AbstractTerm>>emptyList();
@@ -493,7 +493,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
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
: getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0
? ((org.apache.olingo.commons.api.domain.v3.ODataEntity) getEntity()).getLink()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java
index a0e8b99..5e51ad6 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java
@@ -72,11 +72,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
@Test
public void read() {
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());
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
@@ -119,13 +119,13 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
- assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
- assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
- assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
- assertEquals(Byte.class, rowIndex.getAdditionalProperty("aByte").getClass());
- assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte"));
- assertTrue(Timestamp.class.isAssignableFrom(rowIndex.getAdditionalProperty("aDate").getClass()));
- assertEquals(ContactDetails.class, rowIndex.getAdditionalProperty("aContact").getClass().getInterfaces()[0]);
+ assertEquals(String.class, rowIndex.readAdditionalProperty("aString").getClass());
+ assertEquals(Boolean.class, rowIndex.readAdditionalProperty("aBoolean").getClass());
+ assertEquals(Double.class, rowIndex.readAdditionalProperty("aDouble").getClass());
+ assertEquals(Byte.class, rowIndex.readAdditionalProperty("aByte").getClass());
+ assertEquals(Byte.MAX_VALUE, rowIndex.readAdditionalProperty("aByte"));
+ assertTrue(Timestamp.class.isAssignableFrom(rowIndex.readAdditionalProperty("aDate").getClass()));
+ assertEquals(ContactDetails.class, rowIndex.readAdditionalProperty("aContact").getClass().getInterfaces()[0]);
otservice.getContext().detachAll();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
index 2a7d612..2f91916 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
@@ -100,11 +100,11 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase {
public void readWithReferences() {
final Person person = container.getOrders().getByKey(8).getCustomerForOrder().refs().load();
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();
assertEquals("http://localhost:9080/stub/StaticService/V40/Static.svc/Orders(7)",
- orders.iterator().next().getEntityReferenceID());
+ orders.iterator().next().readEntityReferenceID());
}
@Test
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java
index 2cbd7bd..082331e 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/OpenTypeTestITCase.java
@@ -72,11 +72,11 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
@Test
public void read() {
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());
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
@@ -126,19 +126,19 @@ public class OpenTypeTestITCase extends AbstractTestITCase {
otcontainer.flush();
rowIndex = otcontainer.getRowIndex().getByKey(id).load();
- assertEquals(String.class, rowIndex.getAdditionalProperty("aString").getClass());
- assertEquals(Boolean.class, rowIndex.getAdditionalProperty("aBoolean").getClass());
- assertEquals(Double.class, rowIndex.getAdditionalProperty("aDouble").getClass());
- assertEquals(Byte.class, rowIndex.getAdditionalProperty("aByte").getClass());
- assertEquals(Byte.MAX_VALUE, rowIndex.getAdditionalProperty("aByte"));
- assertTrue(Calendar.class.isAssignableFrom(rowIndex.getAdditionalProperty("aDate").getClass()));
- assertEquals(ContactDetails.class, rowIndex.getAdditionalProperty("aContact").getClass().getInterfaces()[0]);
- assertEquals(Color.class, rowIndex.getAdditionalProperty("aColor").getClass());
- assertEquals(Color.Green, rowIndex.getAdditionalProperty("aColor"));
- assertEquals("Fabio", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).getFirstName());
- assertEquals("Martelli", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).getLastName());
- assertEquals("fabio.martelli@tirasa.net", AccountInfo.class.cast(rowIndex.getAdditionalProperty("info")).
- getAdditionalProperty("email"));
+ assertEquals(String.class, rowIndex.readAdditionalProperty("aString").getClass());
+ assertEquals(Boolean.class, rowIndex.readAdditionalProperty("aBoolean").getClass());
+ assertEquals(Double.class, rowIndex.readAdditionalProperty("aDouble").getClass());
+ assertEquals(Byte.class, rowIndex.readAdditionalProperty("aByte").getClass());
+ assertEquals(Byte.MAX_VALUE, rowIndex.readAdditionalProperty("aByte"));
+ assertTrue(Calendar.class.isAssignableFrom(rowIndex.readAdditionalProperty("aDate").getClass()));
+ assertEquals(ContactDetails.class, rowIndex.readAdditionalProperty("aContact").getClass().getInterfaces()[0]);
+ assertEquals(Color.class, rowIndex.readAdditionalProperty("aColor").getClass());
+ assertEquals(Color.Green, rowIndex.readAdditionalProperty("aColor"));
+ assertEquals("Fabio", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).getFirstName());
+ assertEquals("Martelli", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).getLastName());
+ assertEquals("fabio.martelli@tirasa.net", AccountInfo.class.cast(rowIndex.readAdditionalProperty("info")).
+ readAdditionalProperty("email"));
otservice.getContext().detachAll();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c78784d/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
index 5c0b8c6..f3ab08f 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/SingletonTestITCase.java
@@ -51,26 +51,26 @@ public class SingletonTestITCase extends AbstractTestITCase {
@Test
public void readWithAnnotations() {
final Company company = container.getCompany().load();
- assertTrue(company.getAnnotationTerms().isEmpty());
+ assertTrue(company.readAnnotationTerms().isEmpty());
final Person boss = container.getBoss().load();
assertEquals(2, boss.getPersonID(), 0);
- assertEquals(1, boss.getAnnotationTerms().size());
- Object isBoss = boss.getAnnotation(IsBoss.class);
+ assertEquals(1, boss.readAnnotationTerms().size());
+ Object isBoss = boss.readAnnotation(IsBoss.class);
assertTrue(isBoss instanceof Boolean);
assertTrue((Boolean) isBoss);
Annotatable annotations = boss.annotations().getFirstNameAnnotations();
- assertTrue(annotations.getAnnotationTerms().isEmpty());
+ assertTrue(annotations.readAnnotationTerms().isEmpty());
annotations = boss.annotations().getLastNameAnnotations();
- isBoss = annotations.getAnnotation(IsBoss.class);
+ isBoss = annotations.readAnnotation(IsBoss.class);
assertTrue(isBoss instanceof Boolean);
assertFalse((Boolean) isBoss);
annotations = boss.annotations().getParentAnnotations();
- isBoss = annotations.getAnnotation(IsBoss.class);
+ isBoss = annotations.readAnnotation(IsBoss.class);
assertTrue(isBoss instanceof Boolean);
assertFalse((Boolean) isBoss);
}
[2/7] git commit: [OLINGO-403] fixed
Posted by mi...@apache.org.
[OLINGO-403] fixed
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/58619c96
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/58619c96
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/58619c96
Branch: refs/heads/OLINGO-406
Commit: 58619c966898c346018d2a4449e794b12df158eb
Parents: 853bad6
Author: fmartelli <fa...@gmail.com>
Authored: Mon Aug 18 15:04:55 2014 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Mon Aug 18 15:04:55 2014 +0200
----------------------------------------------------------------------
.../main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/58619c96/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java
index 8d5c08c..d22eb28 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/utils/ClassUtils.java
@@ -32,6 +32,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.HashSet;
@@ -49,6 +50,10 @@ public final class ClassUtils {
}
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 (references == null || references.length == 0) {
return ((ParameterizedType) paramType.getGenericInterfaces()[0]).getActualTypeArguments();
[7/7] git commit: Merge branch 'master' into OLINGO-406
Posted by mi...@apache.org.
Merge branch 'master' into OLINGO-406
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/badb9916
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/badb9916
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/badb9916
Branch: refs/heads/OLINGO-406
Commit: badb9916b238769e9d3c23154a0b8e14418f51a0
Parents: deec7aa a30d2f8
Author: mibo <mi...@apache.org>
Authored: Mon Sep 1 08:27:54 2014 +0200
Committer: mibo <mi...@apache.org>
Committed: Mon Sep 1 08:27:54 2014 +0200
----------------------------------------------------------------------
.../olingo/ext/proxy/api/AbstractOpenType.java | 6 +-
.../olingo/ext/proxy/api/Annotatable.java | 6 +-
.../apache/olingo/ext/proxy/api/EntityType.java | 3 +-
.../AbstractStructuredInvocationHandler.java | 75 +++++------
.../commons/AnnotatableInvocationHandler.java | 4 +-
.../proxy/commons/EntityInvocationHandler.java | 7 +-
.../olingo/ext/proxy/utils/ClassUtils.java | 5 +
.../olingo/fit/proxy/v3/OpenTypeTestITCase.java | 18 +--
.../fit/proxy/v4/APIBasicDesignTestITCase.java | 4 +-
.../olingo/fit/proxy/v4/OpenTypeTestITCase.java | 30 ++---
.../fit/proxy/v4/SingletonTestITCase.java | 12 +-
.../apache/olingo/client/core/uri/URIUtils.java | 17 ++-
.../server/core/ODataExceptionHandler.java | 54 --------
.../server/core/ODataExceptionHelper.java | 87 +++++++++++--
.../apache/olingo/server/core/ODataHandler.java | 66 +++++-----
.../server/core/ODataHttpHandlerImpl.java | 29 ++++-
.../olingo/server/core/uri/parser/Parser.java | 2 +-
.../core/uri/parser/UriParseTreeVisitor.java | 23 ++--
.../uri/parser/UriParserSemanticException.java | 3 +-
.../uri/parser/UriParserSyntaxException.java | 3 +-
.../server-core-exceptions-i18n.properties | 2 +
.../core/ODataHandlerExceptionHandlingTest.java | 124 +++++++++++++++++++
.../olingo/server/core/ODataHandlerTest.java | 81 ++----------
.../core/uri/antlr/TestFullResourcePath.java | 26 ++--
24 files changed, 401 insertions(+), 286 deletions(-)
----------------------------------------------------------------------
[4/7] git commit: [OLINGO-350] Transform exception to http status code
Posted by mi...@apache.org.
[OLINGO-350] Transform exception to http status code
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/a0f8f356
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/a0f8f356
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/a0f8f356
Branch: refs/heads/OLINGO-406
Commit: a0f8f356b23e829a7131fdaef27348719924009c
Parents: 9c78784
Author: Christian Amend <ch...@apache.org>
Authored: Fri Aug 29 15:00:10 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Aug 29 15:00:56 2014 +0200
----------------------------------------------------------------------
.../server/core/ODataExceptionHandler.java | 54 --------
.../server/core/ODataExceptionHelper.java | 87 +++++++++++--
.../apache/olingo/server/core/ODataHandler.java | 67 +++++-----
.../server/core/ODataHttpHandlerImpl.java | 29 ++++-
.../olingo/server/core/uri/parser/Parser.java | 2 +-
.../core/uri/parser/UriParseTreeVisitor.java | 23 ++--
.../uri/parser/UriParserSemanticException.java | 3 +-
.../uri/parser/UriParserSyntaxException.java | 3 +-
.../server-core-exceptions-i18n.properties | 2 +
.../core/ODataHandlerExceptionHandlingTest.java | 124 +++++++++++++++++++
.../olingo/server/core/ODataHandlerTest.java | 81 ++----------
.../core/uri/antlr/TestFullResourcePath.java | 26 ++--
12 files changed, 297 insertions(+), 204 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHandler.java
deleted file mode 100644
index dbdf804..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHandler.java
+++ /dev/null
@@ -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
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
index 3ba30c7..d0f248f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
@@ -20,30 +20,75 @@ package org.apache.olingo.server.core;
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.ODataServerError;
import org.apache.olingo.server.api.ODataTranslatedException;
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 static ODataServerError createServerErrorObject(Exception e, int statusCode) {
- ODataServerError serverError = basicServerError(e);
- serverError.setStatusCode(statusCode);
- serverError.setLocale(Locale.ENGLISH);
+
+ public static ODataServerError createServerErrorObject(UriValidationException e, Locale requestedLocale) {
+ ODataServerError serverError = basicTranslatedError(e, requestedLocale);
+ serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ 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;
}
- public static ODataServerError createServerErrorObject(ODataTranslatedException e, int statusCode,
- Locale requestedLocale) {
- ODataServerError serverError = basicServerError(e);
- ODataErrorMessage translatedMessage = e.getTranslatedMessage(requestedLocale);
- serverError.setMessage(translatedMessage.getMessage());
- serverError.setLocale(translatedMessage.getLocale());
- serverError.setStatusCode(statusCode);
+ public static ODataServerError createServerErrorObject(ODataHandlerException e, Locale requestedLocale) {
+ ODataServerError serverError = basicTranslatedError(e, requestedLocale);
+ if (ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED.equals(e.getMessageKey())
+ || ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_IMPLEMENTED.equals(e.getMessageKey())
+ || ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED.equals(e.getMessageKey())) {
+ serverError.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
+ } else if (ODataHandlerException.MessageKeys.ODATA_VERSION_NOT_SUPPORTED.equals(e.getMessageKey())) {
+ serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
+ }
+
return serverError;
}
+ public static ODataServerError createServerErrorObject(ODataTranslatedException e, Locale requestedLocale) {
+ return basicTranslatedError(e, requestedLocale);
+ }
+
public static ODataServerError createServerErrorObject(ODataApplicationException e) {
ODataServerError serverError = basicServerError(e);
serverError.setStatusCode(e.getStatusCode());
@@ -51,9 +96,25 @@ public class ODataExceptionHelper {
serverError.setCode(e.getODataErrorCode());
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) {
ODataServerError serverError = new ODataServerError().setException(e).setMessage(e.getMessage());
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;
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index de4851f..2a8f6f5 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -19,7 +19,6 @@
package org.apache.olingo.server.core;
import java.util.HashMap;
-import java.util.Locale;
import java.util.Map;
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.http.HttpHeader;
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.ODataServerError;
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.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.ExceptionProcessor;
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.core.uri.parser.Parser;
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.UriValidator;
@@ -73,30 +73,33 @@ public class ODataHandler {
processInternal(request, requestedContentType, response);
- } catch (final UriParserException e) {
- handleException(request, response,
- ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.BAD_REQUEST.getStatusCode(), null),
- requestedContentType);
} catch (final UriValidationException e) {
- handleException(request, response,
- ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.BAD_REQUEST.getStatusCode(), null),
- requestedContentType);
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
+ handleException(request, response, serverError, null);
+ } 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) {
- Locale requestedLocale = null;
- ODataServerError serverError =
- ODataExceptionHelper.createServerErrorObject(e, HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(),
- requestedLocale);
- handleException(request, response, serverError, requestedContentType);
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
+ handleException(request, response, serverError, null);
+ } catch (ODataHandlerException e) {
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
+ handleException(request, response, serverError, null);
} catch (ODataTranslatedException e) {
- Locale requestedLocale = null;
- ODataServerError serverError =
- ODataExceptionHelper.createServerErrorObject(e, response.getStatusCode(), requestedLocale);
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, requestedContentType);
} catch (ODataApplicationException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
handleException(request, response, serverError, requestedContentType);
} catch (Exception e) {
- ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, response.getStatusCode());
+ e.printStackTrace();
+ ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
handleException(request, response, serverError, requestedContentType);
}
return response;
@@ -118,7 +121,7 @@ public class ODataHandler {
switch (uriInfo.getKind()) {
case metadata:
- MetadataProcessor mp = selectProcessor(MetadataProcessor.class, response);
+ MetadataProcessor mp = selectProcessor(MetadataProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, mp, MetadataProcessor.class);
@@ -127,10 +130,10 @@ public class ODataHandler {
break;
case service:
if ("".equals(request.getRawODataPath())) {
- RedirectProcessor rdp = selectProcessor(RedirectProcessor.class, response);
+ RedirectProcessor rdp = selectProcessor(RedirectProcessor.class);
rdp.redirect(request, response);
} else {
- ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class, response);
+ ServiceDocumentProcessor sdp = selectProcessor(ServiceDocumentProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, sdp,
@@ -143,7 +146,6 @@ public class ODataHandler {
handleResourceDispatching(request, response, uriInfo);
break;
default:
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
@@ -153,7 +155,7 @@ public class ODataHandler {
ContentType requestedContentType) {
ExceptionProcessor exceptionProcessor;
try {
- exceptionProcessor = selectProcessor(ExceptionProcessor.class, response);
+ exceptionProcessor = selectProcessor(ExceptionProcessor.class);
} catch (ODataTranslatedException e) {
exceptionProcessor = new DefaultProcessor();
}
@@ -173,7 +175,7 @@ public class ODataHandler {
case entitySet:
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
if (request.getMethod().equals(HttpMethod.GET)) {
- EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class, response);
+ EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
@@ -181,20 +183,18 @@ public class ODataHandler {
cp.readCollection(request, response, uriInfo, requestedContentType);
} else {
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
} else {
if (request.getMethod().equals(HttpMethod.GET)) {
- EntityProcessor ep = selectProcessor(EntityProcessor.class, response);
+ EntityProcessor ep = selectProcessor(EntityProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
ep.readEntity(request, response, uriInfo, requestedContentType);
} else {
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
@@ -203,7 +203,7 @@ public class ODataHandler {
case navigationProperty:
if (((UriResourceNavigation) lastPathSegment).isCollection()) {
if (request.getMethod().equals(HttpMethod.GET)) {
- EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class, response);
+ EntityCollectionProcessor cp = selectProcessor(EntityCollectionProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, cp,
@@ -211,27 +211,24 @@ public class ODataHandler {
cp.readCollection(request, response, uriInfo, requestedContentType);
} else {
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
} else {
if (request.getMethod().equals(HttpMethod.GET)) {
- EntityProcessor ep = selectProcessor(EntityProcessor.class, response);
+ EntityProcessor ep = selectProcessor(EntityProcessor.class);
requestedContentType =
ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(), request, ep, EntityProcessor.class);
ep.readEntity(request, response, uriInfo, requestedContentType);
} else {
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
}
break;
default:
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("not implemented",
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
}
@@ -244,20 +241,18 @@ public class ODataHandler {
if (maxVersion != null) {
if (ODataServiceVersion.isBiggerThan(ODataServiceVersion.V40.toString(), maxVersion)) {
- response.setStatusCode(400);
throw new ODataHandlerException("ODataVersion 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 {
@SuppressWarnings("unchecked")
T p = (T) processors.get(cls);
if (p == null) {
- response.setStatusCode(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode());
throw new ODataHandlerException("Processor: " + cls.getName() + " not registered.",
ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED, cls.getName());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
index 436d54f..4e1f90c 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHttpHandlerImpl.java
@@ -20,6 +20,8 @@ package org.apache.olingo.server.core;
import org.apache.olingo.commons.api.ODataRuntimeException;
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.HttpMethod;
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.ODataRequest;
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.processor.Processor;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.ODataSerializerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,12 +40,14 @@ import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import java.util.Locale;
import java.util.Map.Entry;
public class ODataHttpHandlerImpl implements ODataHttpHandler {
@@ -85,8 +91,27 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
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;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
index 0c4d92c..016aeb9 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
@@ -188,7 +188,7 @@ public class Parser {
formatOption.setFormat(option.value);
} else {
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);
}
context.contextUriInfo.setSystemQueryOption(formatOption);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index 160cc2a..c23ae68 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -358,6 +358,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastResourcePart == null) {
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 "
+ "resource parts",
UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS, odi));
@@ -396,9 +401,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmElement property = structType.getProperty(odi);
if (property == null) {
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
- + structType.getNamespace() + "." + structType.getName() + "'",
+ + structType.getNamespace() + "." + structType.getName() + "'",
UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE,
- structType.getFullQualifiedName().toString(), odi));
+ structType.getFullQualifiedName().toString(), odi));
}
if (property instanceof EdmProperty) {
@@ -466,7 +471,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterEntityType)));
+ getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterEntityType)));
}
lastPartWithKeys.setEntryTypeFilter(filterEntityType);
return null;
@@ -476,7 +481,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterEntityType)));
+ getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterEntityType)));
}
lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
return null;
@@ -488,7 +493,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartTyped.getTypeFilter()), getName(filterEntityType)));
+ getName(lastPartTyped.getTypeFilter()), getName(filterEntityType)));
}
lastPartTyped.setTypeFilter(filterEntityType);
@@ -512,7 +517,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
throw wrap(new UriParserSemanticException(
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
+ getName(filterComplexType) + "'",
- UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, getName(source.type)));
+ UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER, getName(source.type)));
}
// is simple complex type cast
@@ -540,7 +545,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterComplexType)));
+ getName(lastPartWithKeys.getTypeFilterOnEntry()), getName(filterComplexType)));
}
lastPartWithKeys.setEntryTypeFilter(filterComplexType);
return null;
@@ -550,7 +555,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterComplexType)));
+ getName(lastPartWithKeys.getTypeFilterOnCollection()), getName(filterComplexType)));
}
lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
return null;
@@ -563,7 +568,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'",
UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE,
- getName(lastPartTyped.getTypeFilter()), getName(filterComplexType)));
+ getName(lastPartTyped.getTypeFilter()), getName(filterComplexType)));
}
lastPartTyped.setTypeFilter(filterComplexType);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 48e8647..b41fbbf 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -49,7 +49,8 @@ public class UriParserSemanticException extends UriParserException {
ONLY_SIMPLE_AND_COMPLEX_PROPERTIES_IN_SELECT,
COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED,
NOT_FOR_ENTITY_TYPE,
- PREVIOUS_PART_TYPED;
+ PREVIOUS_PART_TYPED,
+ /** parameter: resource_name */RESOURCE_NOT_FOUND;
@Override
public String getKey() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
index dd73236..e1506ee 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
@@ -27,7 +27,8 @@ public class UriParserSyntaxException extends UriParserException {
/** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION,
/** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
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
public String getKey() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 93f433f..4695c73 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -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.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.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.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
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_URI_KIND=The URI kind '%1$s' is not supported.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
new file mode 100644
index 0000000..0f40d19
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerExceptionHandlingTest.java
@@ -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());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
index 3ac7208..04ed434 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
@@ -21,35 +21,24 @@ package org.apache.olingo.server.core;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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 java.util.Arrays;
-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.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.HttpHeader;
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.processor.ServiceDocumentProcessor;
-import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class ODataHandlerTest {
@@ -223,86 +212,30 @@ public class ODataHandlerTest {
assertNotNull(response);
assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
}
-
- @Test
- public void testUnregisteredProcessor() {
- ODataRequest request = new ODataRequest();
-
- request.setMethod(HttpMethod.GET);
- request.setRawODataPath("ESAllPrim");
-
- ODataResponse response = handler.process(request);
- assertNotNull(response);
- assertEquals(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), response.getStatusCode());
- }
-
+
@Test
- public void testWithApplicationExceptionInProcessor() throws Exception {
+ public void testContentNegotiationNotSupported2() {
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);
+ request.setRawQueryPath("$format=notSupported");
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(425, response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), 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 {
+ public void testUnregisteredProcessor() {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
- request.setRawODataPath("ESAllPrim()");
+ request.setRawODataPath("ESAllPrim");
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_IMPLEMENTED.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()));
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/a0f8f356/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 60a0e13..8d2c565 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -968,33 +968,33 @@ public class TestFullResourcePath {
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/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")
- .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")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/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"
+ "/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")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ETBaseTwoKeyTwoPrim()")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
.isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_TYPED_PARTS);
testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value")
- .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
+ .isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_NOT_FOUND);
}
@Test
@@ -2553,15 +2553,15 @@ public class TestFullResourcePath {
.isKind(UriInfoKind.resource).goPath()
.isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
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/")
- .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")
- .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")
- .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
+ .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
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