[OLINGO-317] Translatable ODataSerializerException
This commit is contained in:
parent
b891821153
commit
327873253c
|
@ -51,15 +51,20 @@ public class ODataTranslatedException extends ODataException {
|
|||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public ODataTranslatedException(String developmentMessage, Throwable cause, String messageKey, String... parameters) {
|
||||
super(developmentMessage, cause);
|
||||
this.messageKey = messageKey;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return getTranslatedMessage(DEFAULT_LOCALE).getMessage();
|
||||
}
|
||||
|
||||
public ODataTranslatedException(String developmentMessage, Throwable cause, String messageKey, String... parameters) {
|
||||
super(developmentMessage, cause);
|
||||
this.messageKey = messageKey;
|
||||
this.parameters = parameters;
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
|
||||
public String getMessageKey() {
|
||||
|
|
|
@ -26,12 +26,12 @@ 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.HttpStatusCode;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
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.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.olingo.commons.api.data.Entity;
|
|||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
|
||||
public interface ODataSerializer {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.api.serializer;
|
||||
|
||||
import org.apache.olingo.server.api.ODataTranslatedException;
|
||||
|
||||
public class ODataSerializerException extends ODataTranslatedException {
|
||||
|
||||
private static final long serialVersionUID = 5358683245923127425L;
|
||||
|
||||
// MessageKeys
|
||||
public static final String NOT_IMPLEMENTED = "ODataSerializerException.NOT_IMPLEMENTED";
|
||||
public static final String JSON_METADATA = "ODataSerializerException.JSON_METADATA";
|
||||
public static final String IO_EXCEPTION = "ODataSerializerException.IO_EXCEPTION";
|
||||
public static final String NO_CONTEXT_URL = "ODataSerializerException.NO_CONTEXT_URL";
|
||||
/** parameter: property name */
|
||||
public static final String UNSUPPORTED_PROPERTY_TYPE = "ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE";
|
||||
/** parameter: property name */
|
||||
public static final String INCONSISTENT_PROPERTY_TYPE = "ODataSerializerException.INCONSISTENT_PROPERTY_TYPE";
|
||||
/** parameter: property name */
|
||||
public static final String MISSING_PROPERTY = "ODataSerializerException.MISSING_PROPERTY";
|
||||
/** parameters: property name, property value */
|
||||
public static final String WRONG_PROPERTY_VALUE = "ODataSerializerException.WRONG_PROPERTY_VALUE";
|
||||
|
||||
public ODataSerializerException(final String developmentMessage,
|
||||
final String messageKey, final String... parameters) {
|
||||
super(developmentMessage, messageKey, parameters);
|
||||
}
|
||||
|
||||
public ODataSerializerException(final String developmentMessage, final Throwable cause,
|
||||
final String messageKey, final String... parameters) {
|
||||
super(developmentMessage, cause, messageKey, parameters);
|
||||
}
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# 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
|
||||
# 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
|
||||
# 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.
|
||||
# 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.
|
||||
#-------------------------------------------------------------------------------
|
||||
# Basic Apache Olingo exception messages
|
||||
#
|
||||
|
@ -22,3 +22,12 @@ ODataTranslatedException.AMBIGUOUS_XHTTP_METHOD=x-http-method header '%1$s' and
|
|||
ODataTranslatedException.HTTP_METHOD_NOT_IMPLEMENTED=Invalid http method given: '%1$s'.
|
||||
ODataTranslatedException.PROCESSOR_NOT_IMPLEMENTED=No processor for interface '%1$s' registered.
|
||||
ODataTranslatedException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported.
|
||||
|
||||
ODataSerializerException.NOT_IMPLEMENTED=The requested serialization method has not been implemented yet.
|
||||
ODataSerializerException.JSON_METADATA=The metadata document cannot be provided in JSON format.
|
||||
ODataSerializerException.IO_EXCEPTION=An I/O exception occurred.
|
||||
ODataSerializerException.NO_CONTEXT_URL=No context URL has been provided.
|
||||
ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE=The type of the property '%1$s' is not yet supported.
|
||||
ODataSerializerException.INCONSISTENT_PROPERTY_TYPE=An inconsistency has been detected in the type definition of property '%1$s'.
|
||||
ODataSerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing.
|
||||
ODataSerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
|
||||
|
|
|
@ -22,12 +22,12 @@ import java.util.Locale;
|
|||
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
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 {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ import javax.xml.stream.XMLOutputFactory;
|
|||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.commons.api.data.ContextURL;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
|
@ -32,6 +31,7 @@ import org.apache.olingo.commons.api.edm.Edm;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
|
||||
import org.apache.olingo.server.core.serializer.xml.MetadataDocumentXmlSerializer;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -42,12 +42,13 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
|
|||
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializerImpl.class);
|
||||
|
||||
@Override
|
||||
public InputStream serviceDocument(final Edm edm, final String serviceRoot) {
|
||||
throw new ODataRuntimeException("Service Document not implemented for XML format");
|
||||
public InputStream serviceDocument(final Edm edm, final String serviceRoot) throws ODataSerializerException {
|
||||
throw new ODataSerializerException("Service Document not implemented for XML format",
|
||||
ODataSerializerException.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream metadataDocument(final Edm edm) {
|
||||
public InputStream metadataDocument(final Edm edm) throws ODataSerializerException {
|
||||
CircleStreamBuffer buffer;
|
||||
XMLStreamWriter xmlStreamWriter = null;
|
||||
|
||||
|
@ -61,34 +62,38 @@ public class ODataXmlSerializerImpl implements ODataSerializer {
|
|||
xmlStreamWriter.close();
|
||||
|
||||
return buffer.getInputStream();
|
||||
} catch (Exception e) {
|
||||
} catch (final XMLStreamException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new ODataRuntimeException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
} finally {
|
||||
if (xmlStreamWriter != null) {
|
||||
try {
|
||||
xmlStreamWriter.close();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new ODataRuntimeException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream entity(final EdmEntitySet edmEntitySet, final Entity entity, final ContextURL contextURL) {
|
||||
throw new ODataRuntimeException("Entity serialization not implemented for XML format");
|
||||
public InputStream entity(final EdmEntitySet edmEntitySet, final Entity entity, final ContextURL contextURL)
|
||||
throws ODataSerializerException {
|
||||
throw new ODataSerializerException("Entity serialization not implemented for XML format",
|
||||
ODataSerializerException.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream entitySet(final EdmEntitySet edmEntitySet, final EntitySet entitySet,
|
||||
final ContextURL contextURL) {
|
||||
throw new ODataRuntimeException("Entityset serialization not implemented for XML format");
|
||||
final ContextURL contextURL) throws ODataSerializerException {
|
||||
throw new ODataSerializerException("Entityset serialization not implemented for XML format",
|
||||
ODataSerializerException.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream error(ODataServerError error) {
|
||||
throw new ODataRuntimeException("error serialization not implemented for XML format");
|
||||
public InputStream error(ODataServerError error) throws ODataSerializerException {
|
||||
throw new ODataSerializerException("error serialization not implemented for XML format",
|
||||
ODataSerializerException.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
|||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
|
||||
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -81,15 +81,15 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
|
||||
return buffer.getInputStream();
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (final IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new ODataSerializerException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
} finally {
|
||||
if (gen != null) {
|
||||
try {
|
||||
gen.close();
|
||||
} catch (IOException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,8 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
|
||||
@Override
|
||||
public InputStream metadataDocument(final Edm edm) throws ODataSerializerException {
|
||||
throw new ODataSerializerException("Metadata in JSON format not supported!");
|
||||
throw new ODataSerializerException("Metadata in JSON format not supported!",
|
||||
ODataSerializerException.JSON_METADATA);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,7 +109,7 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
new ODataErrorSerializer().writeErrorDocument(json, error);
|
||||
json.close();
|
||||
} catch (final IOException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
}
|
||||
return buffer.getInputStream();
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
json.writeStartObject();
|
||||
if (format != ODataFormat.JSON_NO_METADATA) {
|
||||
if (contextURL == null) {
|
||||
throw new ODataSerializerException("ContextURL null!");
|
||||
throw new ODataSerializerException("ContextURL null!", ODataSerializerException.NO_CONTEXT_URL);
|
||||
} else {
|
||||
json.writeStringField(Constants.JSON_CONTEXT, ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
}
|
||||
|
@ -141,9 +142,7 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
}
|
||||
json.close();
|
||||
} catch (final IOException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
}
|
||||
return buffer.getInputStream();
|
||||
}
|
||||
|
@ -152,7 +151,7 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
public InputStream entity(final EdmEntitySet edmEntitySet, final Entity entity, final ContextURL contextURL)
|
||||
throws ODataSerializerException {
|
||||
if (format != ODataFormat.JSON_NO_METADATA && contextURL == null) {
|
||||
throw new ODataSerializerException("ContextURL null!");
|
||||
throw new ODataSerializerException("ContextURL null!", ODataSerializerException.NO_CONTEXT_URL);
|
||||
}
|
||||
CircleStreamBuffer buffer = new CircleStreamBuffer();
|
||||
try {
|
||||
|
@ -160,15 +159,13 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
writeEntity(edmEntitySet, entity, contextURL, json);
|
||||
json.close();
|
||||
} catch (final IOException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new ODataSerializerException(e);
|
||||
throw new ODataSerializerException("An I/O exception occurred.", e, ODataSerializerException.IO_EXCEPTION);
|
||||
}
|
||||
return buffer.getInputStream();
|
||||
}
|
||||
|
||||
protected void writeEntity(final EdmEntitySet entitySet, final Entity entity, final ContextURL contextURL,
|
||||
final JsonGenerator json) throws IOException, EdmPrimitiveTypeException, ODataSerializerException {
|
||||
final JsonGenerator json) throws IOException, ODataSerializerException {
|
||||
final EdmEntityType entityType = entitySet.getEntityType();
|
||||
json.writeStartObject();
|
||||
if (format != ODataFormat.JSON_NO_METADATA) {
|
||||
|
@ -196,25 +193,32 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
}
|
||||
|
||||
protected void writeProperty(final EdmProperty edmProperty, final Property property, final JsonGenerator json)
|
||||
throws IOException, EdmPrimitiveTypeException, ODataSerializerException {
|
||||
throws IOException, ODataSerializerException {
|
||||
json.writeFieldName(edmProperty.getName());
|
||||
if (property == null || property.isNull()) {
|
||||
if (edmProperty.isNullable() == Boolean.FALSE) {
|
||||
throw new ODataSerializerException("Non-nullable property not present!");
|
||||
throw new ODataSerializerException("Non-nullable property not present!",
|
||||
ODataSerializerException.MISSING_PROPERTY, edmProperty.getName());
|
||||
} else {
|
||||
json.writeNull();
|
||||
}
|
||||
} else {
|
||||
if (edmProperty.isCollection()) {
|
||||
writeCollection(edmProperty, property, json);
|
||||
} else if (edmProperty.isPrimitive()) {
|
||||
writePrimitive(edmProperty, property, json);
|
||||
} else if (property.isLinkedComplex()) {
|
||||
writeComplexValue(edmProperty, property.asLinkedComplex().getValue(), json);
|
||||
} else if (property.isComplex()) {
|
||||
writeComplexValue(edmProperty, property.asComplex(), json);
|
||||
} else {
|
||||
throw new ODataSerializerException("Property type not yet supported!");
|
||||
try {
|
||||
if (edmProperty.isCollection()) {
|
||||
writeCollection(edmProperty, property, json);
|
||||
} else if (edmProperty.isPrimitive()) {
|
||||
writePrimitive(edmProperty, property, json);
|
||||
} else if (property.isLinkedComplex()) {
|
||||
writeComplexValue(edmProperty, property.asLinkedComplex().getValue(), json);
|
||||
} else if (property.isComplex()) {
|
||||
writeComplexValue(edmProperty, property.asComplex(), json);
|
||||
} else {
|
||||
throw new ODataSerializerException("Property type not yet supported!",
|
||||
ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
|
||||
}
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new ODataSerializerException("Wrong value for property!", e,
|
||||
ODataSerializerException.WRONG_PROPERTY_VALUE, edmProperty.getName(), property.getValue().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +232,8 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
writePrimitiveValue(edmProperty, value, json);
|
||||
break;
|
||||
case COLLECTION_GEOSPATIAL:
|
||||
throw new ODataSerializerException("Property type not yet supported!");
|
||||
throw new ODataSerializerException("Property type not yet supported!",
|
||||
ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
|
||||
case COLLECTION_ENUM:
|
||||
json.writeString(value.toString());
|
||||
break;
|
||||
|
@ -239,7 +244,8 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
writeComplexValue(edmProperty, property.asComplex(), json);
|
||||
break;
|
||||
default:
|
||||
throw new ODataSerializerException("Property type not yet supported!");
|
||||
throw new ODataSerializerException("Property type not yet supported!",
|
||||
ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
|
||||
}
|
||||
}
|
||||
json.writeEndArray();
|
||||
|
@ -250,11 +256,13 @@ public class ODataJsonSerializer implements ODataSerializer {
|
|||
if (property.isPrimitive()) {
|
||||
writePrimitiveValue(edmProperty, property.asPrimitive(), json);
|
||||
} else if (property.isGeospatial()) {
|
||||
throw new ODataSerializerException("Property type not yet supported!");
|
||||
throw new ODataSerializerException("Property type not yet supported!",
|
||||
ODataSerializerException.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
|
||||
} else if (property.isEnum()) {
|
||||
writePrimitiveValue(edmProperty, property.asEnum(), json);
|
||||
} else {
|
||||
throw new ODataSerializerException("Inconsistent property type!");
|
||||
throw new ODataSerializerException("Inconsistent property type!",
|
||||
ODataSerializerException.INCONSISTENT_PROPERTY_TYPE, edmProperty.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map;
|
|||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.EntitySet;
|
||||
import org.apache.olingo.commons.api.data.LinkedComplexValue;
|
||||
|
@ -99,7 +100,7 @@ public class DataProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public static class DataProviderException extends Exception {
|
||||
public static class DataProviderException extends ODataException {
|
||||
private static final long serialVersionUID = 5098059649321796156L;
|
||||
|
||||
public DataProviderException(String message, Throwable throwable) {
|
||||
|
@ -286,7 +287,7 @@ public class DataProvider {
|
|||
Entity entity = new EntityImpl();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 1));
|
||||
entity.addProperty(createCollection("CollPropertyString",
|
||||
"spiderman@comic.com", "spidermaus@comic.com", "spidergirl@comic.com"));
|
||||
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"));
|
||||
entity.addProperty(createCollection("CollPropertyBoolean", true, false, true));
|
||||
entity.addProperty(createCollection("CollPropertyByte", 50, 200, 249));
|
||||
entity.addProperty(createCollection("CollPropertySByte", -120, 120, 126));
|
||||
|
@ -333,7 +334,7 @@ public class DataProvider {
|
|||
Entity entity = new EntityImpl();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE));
|
||||
entity.addProperty(createCollection("CollPropertyString",
|
||||
"spiderman@comic.com", "spidermaus@comic.com", "spidergirl@comic.com"));
|
||||
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"));
|
||||
LinkedComplexValue complexValue = new LinkedComplexValueImpl();
|
||||
complexValue.getValue().add(createPrimitive("PropertyInt16", 111));
|
||||
complexValue.getValue().add(createPrimitive("PropertyString", "TEST A"));
|
||||
|
@ -358,7 +359,7 @@ public class DataProvider {
|
|||
entity = new EntityImpl();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 7));
|
||||
entity.addProperty(createCollection("CollPropertyString",
|
||||
"spiderman@comic.com", "spidermaus@comic.com", "spidergirl@comic.com"));
|
||||
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"));
|
||||
complexValue = new LinkedComplexValueImpl();
|
||||
complexValue.getValue().add(createPrimitive("PropertyInt16", 222));
|
||||
complexValue.getValue().add(createPrimitive("PropertyString", "TEST B"));
|
||||
|
@ -370,7 +371,7 @@ public class DataProvider {
|
|||
entity = new EntityImpl();
|
||||
entity.addProperty(createPrimitive("PropertyInt16", 0));
|
||||
entity.addProperty(createCollection("CollPropertyString",
|
||||
"spiderman@comic.com", "spidermaus@comic.com", "spidergirl@comic.com"));
|
||||
"Employee1@company.example", "Employee2@company.example", "Employee3@company.example"));
|
||||
complexValue = new LinkedComplexValueImpl();
|
||||
complexValue.getValue().add(createPrimitive("PropertyInt16", 333));
|
||||
complexValue.getValue().add(createPrimitive("PropertyString", "TEST C"));
|
||||
|
|
|
@ -27,13 +27,13 @@ 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.HttpStatusCode;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.processor.CollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.uri.UriInfo;
|
||||
import org.apache.olingo.server.api.uri.UriInfoResource;
|
||||
import org.apache.olingo.server.api.uri.UriResource;
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.apache.olingo.commons.api.edm.EdmEntityContainer;
|
|||
import org.apache.olingo.commons.api.edm.EdmEntitySet;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.tecsvc.data.DataProvider;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.junit.Assert;
|
||||
|
@ -106,13 +106,21 @@ public class ODataJsonSerializerTest {
|
|||
ContextURL.Builder.create().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build());
|
||||
}
|
||||
|
||||
@Test(expected = ODataSerializerException.class)
|
||||
@Test
|
||||
public void entityWrongData() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
|
||||
entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false);
|
||||
serializer.entity(edmEntitySet, entity,
|
||||
ContextURL.Builder.create().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build());
|
||||
try {
|
||||
serializer.entity(edmEntitySet, entity,
|
||||
ContextURL.Builder.create().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build());
|
||||
Assert.fail("Expected exception not thrown!");
|
||||
} catch (final ODataSerializerException e) {
|
||||
Assert.assertEquals(ODataSerializerException.WRONG_PROPERTY_VALUE, e.getMessageKey());
|
||||
// final String message = e.getLocalizedMessage();
|
||||
// Assert.assertThat(message, CoreMatchers.containsString("PropertyInt16"));
|
||||
// Assert.assertThat(message, CoreMatchers.containsString("false"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -151,7 +159,8 @@ public class ODataJsonSerializerTest {
|
|||
final String expectedResult = "{"
|
||||
+ "\"@odata.context\":\"http://host/service/$metadata#ESCollAllPrim/$entity\","
|
||||
+ "\"PropertyInt16\":1,"
|
||||
+ "\"CollPropertyString\":[\"spiderman@comic.com\",\"spidermaus@comic.com\",\"spidergirl@comic.com\"],"
|
||||
+ "\"CollPropertyString\":"
|
||||
+ "[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"],"
|
||||
+ "\"CollPropertyBoolean\":[true,false,true],"
|
||||
+ "\"CollPropertyByte\":[50,200,249],"
|
||||
+ "\"CollPropertySByte\":[-120,120,126],"
|
||||
|
@ -214,7 +223,8 @@ public class ODataJsonSerializerTest {
|
|||
final String expectedResult = "{"
|
||||
+ "\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\","
|
||||
+ "\"PropertyInt16\":32767,"
|
||||
+ "\"CollPropertyString\":[\"spiderman@comic.com\",\"spidermaus@comic.com\",\"spidergirl@comic.com\"],"
|
||||
+ "\"CollPropertyString\":"
|
||||
+ "[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"],"
|
||||
+ "\"PropertyComp\":{\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"},"
|
||||
+ "\"CollPropertyComp\":["
|
||||
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
|||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.commons.api.edm.Target;
|
||||
import org.apache.olingo.commons.api.format.ODataFormat;
|
||||
import org.apache.olingo.commons.api.serialization.ODataSerializerException;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.edm.provider.Action;
|
||||
import org.apache.olingo.server.api.edm.provider.ActionImport;
|
||||
|
@ -56,6 +55,7 @@ import org.apache.olingo.server.api.edm.provider.Schema;
|
|||
import org.apache.olingo.server.api.edm.provider.Singleton;
|
||||
import org.apache.olingo.server.api.edm.provider.TypeDefinition;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializerException;
|
||||
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.junit.Test;
|
||||
|
|
Loading…
Reference in New Issue