[OLINGO-317] Finished DeSerializer refactoring

This commit is contained in:
Michael Bolz 2014-06-11 13:39:53 +02:00
parent 46a3417825
commit 70afb2acc5
51 changed files with 495 additions and 539 deletions

View File

@ -73,6 +73,7 @@ import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Value;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
@ -80,6 +81,7 @@ import org.apache.olingo.commons.api.op.ODataDeserializer;
import org.apache.olingo.commons.api.op.ODataSerializer;
import org.apache.olingo.commons.core.data.AtomSerializer;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.JsonDeserializer;
import org.apache.olingo.commons.core.data.JsonSerializer;
import org.apache.olingo.commons.core.data.LinkImpl;
@ -201,7 +203,7 @@ public abstract class AbstractServices {
try {
final boolean continueOnError = prefer.contains("odata.continue-on-error");
return xml.createBatchResponse(
exploreMultipart(attachment.getAllAttachments(), BOUNDARY, continueOnError), BOUNDARY);
exploreMultipart(attachment.getAllAttachments(), BOUNDARY, continueOnError));
} catch (IOException e) {
return xml.createFaultResponse(Accept.XML.toString(version), e);
}
@ -638,17 +640,11 @@ public abstract class AbstractServices {
final Accept contentTypeValue = Accept.parse(contentType, version);
if (Accept.ATOM == contentTypeValue) {
container = atomDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING));
entry = container.getPayload();
} else {
final ResWrap<Entity> jcontainer = jsonDeserializer.toEntity(
IOUtils.toInputStream(entity, Constants.ENCODING));
entry = jcontainer.getPayload();
container = new ResWrap<Entity>(
jcontainer.getContextURL(),
jcontainer.getMetadataETag(),
entry);
container = jsonDeserializer.toEntity(IOUtils.toInputStream(entity, Constants.ENCODING));
}
entry = container.getPayload();
updateInlineEntities(entry);
entityKey = xml.getDefaultEntryKey(entitySetName, entry);
}
@ -1116,7 +1112,7 @@ public abstract class AbstractServices {
} catch (Exception e) {
LOG.error("Error retrieving entity", e);
return xml.createFaultResponse(accept, e);
}
}
} else {
return internal;
}
@ -1348,8 +1344,7 @@ public abstract class AbstractServices {
} else {
final Property pchanges = xml.readProperty(
Accept.parse(contentType, version),
IOUtils.toInputStream(changes, Constants.ENCODING),
entry.getType());
IOUtils.toInputStream(changes, Constants.ENCODING));
toBeReplaced.setValue(pchanges.getValue());
}
@ -1710,26 +1705,16 @@ public abstract class AbstractServices {
final ByteArrayOutputStream content = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(content, Constants.ENCODING);
if (linkInfo.isFeed()) {
final ResWrap<EntitySet> container = atomDeserializer.toEntitySet(stream);
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
} else {
jsonSerializer.write(writer, container);
}
writer.flush();
writer.close();
final ResWrap<?> container = linkInfo.isFeed() ?
atomDeserializer.toEntitySet(stream) :
atomDeserializer.toEntity(stream);
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
} else {
final ResWrap<Entity> container = atomDeserializer.toEntity(stream);
if (acceptType == Accept.ATOM) {
atomSerializer.write(writer, container);
} else {
jsonSerializer.write(writer, container);
}
writer.flush();
writer.close();
jsonSerializer.write(writer, container);
}
writer.flush();
writer.close();
final String basePath = Commons.getEntityBasePath(entitySetName, entityId);
@ -1797,20 +1782,17 @@ public abstract class AbstractServices {
final ResWrap<Property> container = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ (version.compareTo(ODataServiceVersion.V40) >= 0
? entitySetName + "(" + entityId + ")/" + path
: property.getType())),
+ (version.compareTo(ODataServiceVersion.V40) >= 0 ?
entitySetName + "(" + entityId + ")/" + path : property.getType())),
entryContainer.getMetadataETag(),
property);
return xml.createResponse(
null,
searchForValue
? IOUtils.toInputStream(
container.getPayload().getValue() == null || container.getPayload().getValue().isNull()
? StringUtils.EMPTY
: container.getPayload().getValue().asPrimitive().get(), Constants.ENCODING)
: utils.writeProperty(acceptType, container),
return xml.createResponse(null,
searchForValue ?
IOUtils.toInputStream(container.getPayload().getValue() == null
|| container.getPayload().getValue().isNull() ? StringUtils.EMPTY :
container.getPayload().getValue().asPrimitive().get(), Constants.ENCODING) :
utils.writeProperty(acceptType, container),
Commons.getETag(Commons.getEntityBasePath(entitySetName, entityId), version),
acceptType);
}
@ -1871,6 +1853,54 @@ public abstract class AbstractServices {
return utils;
}
protected void updateInlineEntities(Entity entity) {
final String type = entity.getType();
EntityType entityType;
Map<String, NavigationProperty> navProperties = Collections.emptyMap();
if (type != null && type.length() > 0) {
entityType = metadata.getEntityOrComplexType(type);
navProperties = entityType.getNavigationPropertyMap();
}
for (Property property : entity.getProperties()) {
if (navProperties.containsKey(property.getName())) {
Link alink = new LinkImpl();
alink.setTitle(property.getName());
alink.getAnnotations().addAll(property.getAnnotations());
alink.setType(navProperties.get(property.getName()).isEntitySet()
? Constants.get(version, ConstantKey.ATOM_LINK_FEED)
: Constants.get(version, ConstantKey.ATOM_LINK_ENTRY));
alink.setRel(Constants.get(version, ConstantKey.ATOM_LINK_REL) + property.getName());
if (property.getValue().isComplex()) {
Entity inline = new EntityImpl();
inline.setType(navProperties.get(property.getName()).getType());
for (Property prop : property.getValue().asComplex().get()) {
inline.getProperties().add(prop);
}
alink.setInlineEntity(inline);
} else if (property.getValue().isCollection()) {
EntitySet inline = new EntitySetImpl();
for (Value value : property.getValue().asCollection().get()) {
Entity inlineEntity = new EntityImpl();
inlineEntity.setType(navProperties.get(property.getName()).getType());
for (Property prop : value.asComplex().get()) {
inlineEntity.getProperties().add(prop);
}
inline.getEntities().add(inlineEntity);
}
alink.setInlineEntitySet(inline);
} else {
throw new IllegalStateException("Invalid navigation property " + property);
}
entity.getNavigationLinks().add(alink);
}
}
}
protected void normalizeAtomEntry(final Entity entry, final String entitySetName, final String entityKey) {
final org.apache.olingo.fit.metadata.EntitySet entitySet = metadata.getEntitySet(entitySetName);
final EntityType entityType = metadata.getEntityOrComplexType(entitySet.getType());

View File

@ -134,7 +134,7 @@ public class V4Services extends AbstractServices {
return xml.createResponse(feed, null, Accept.JSON_FULLMETA);
} else {
throw new Exception("Unexpected crossjoin pattern");
throw new IOException("Unexpected crossjoin pattern");
}
} catch (Exception e) {
return xml.createFaultResponse(Accept.JSON.toString(version), e);

View File

@ -100,7 +100,7 @@ public abstract class AbstractUtilities {
this.fsManager = FSManager.instance(version);
atomDeserializer = new FITAtomDeserializer(version);
jsonDeserializer = new JsonDeserializer(version, true);
atomSerializer = new AtomSerializer(version);
atomSerializer = new AtomSerializer(version, true);
jsonSerializer = new JsonSerializer(version, true);
}
@ -116,7 +116,6 @@ public abstract class AbstractUtilities {
* @param is
* @param links links to be added.
* @return
* @throws IOException
*/
protected abstract InputStream addLinks(
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
@ -128,6 +127,7 @@ public abstract class AbstractUtilities {
* @param is
* @return
* @throws IOException
* @throws XMLStreamException
*/
protected abstract Set<String> retrieveAllLinkNames(final InputStream is) throws Exception;
@ -137,10 +137,8 @@ public abstract class AbstractUtilities {
* @param entitySetName
* @param is
* @return
* @throws IOException
*/
protected abstract NavigationLinks retrieveNavigationInfo(
final String entitySetName, final InputStream is)
protected abstract NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is)
throws Exception;
/**
@ -151,7 +149,6 @@ public abstract class AbstractUtilities {
* @param is
* @param links
* @return
* @throws IOException
*/
protected abstract InputStream normalizeLinks(
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
@ -219,13 +216,13 @@ public abstract class AbstractUtilities {
Set<String> linksToBeKept;
try {
linksToBeKept = new HashSet<String>(navigationProperties.keySet());
} catch (Exception e) {
} catch (NullPointerException e) {
linksToBeKept = Collections.<String> emptySet();
}
for (String availableLink : new HashSet<String>(linksToBeKept)) {
try {
fsManager.resolve(Commons.getLinksPath(version, entitySetName, key, availableLink, Accept.JSON_FULLMETA));
fsManager.resolve(Commons.getLinksPath(entitySetName, key, availableLink, Accept.JSON_FULLMETA));
} catch (Exception e) {
linksToBeKept.remove(availableLink);
}
@ -350,7 +347,7 @@ public abstract class AbstractUtilities {
final String entitySetName,
final String entityKey,
final String linkName,
final Collection<String> links) throws IOException {
final Collection<String> links) throws Exception {
final HashSet<String> uris = new HashSet<String>();
@ -371,7 +368,7 @@ public abstract class AbstractUtilities {
public void putLinksInMemory(
final String basePath, final String entitySetName, final String linkName, final Collection<String> uris)
throws IOException {
throws Exception {
fsManager.putInMemory(
Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry<String, Collection<String>>(linkName, uris)),
@ -416,7 +413,7 @@ public abstract class AbstractUtilities {
return createResponse(null, entity, etag, accept, null);
}
public Response createBatchResponse(final InputStream stream, final String boundary) {
public Response createBatchResponse(final InputStream stream) {
final Response.ResponseBuilder builder = version.compareTo(ODataServiceVersion.V30) <= 0
? Response.accepted(stream)
: Response.ok(stream);
@ -590,8 +587,7 @@ public abstract class AbstractUtilities {
return IOUtils.toInputStream(writer.toString(), Constants.ENCODING);
}
public Property readProperty(final Accept accept, final InputStream property, final String entryType)
throws ODataDeserializerException {
public Property readProperty(final Accept accept, final InputStream property) throws ODataDeserializerException {
return (Accept.ATOM == accept || Accept.XML == accept ?
atomDeserializer.toProperty(property) : jsonDeserializer.toProperty(property))
.getPayload();
@ -611,14 +607,14 @@ public abstract class AbstractUtilities {
}
private String getDefaultEntryKey(final String entitySetName, final Entity entry, final String propertyName)
throws Exception {
throws IOException {
String res;
if (entry.getProperty(propertyName) == null) {
if (Commons.SEQUENCE.containsKey(entitySetName)) {
res = String.valueOf(Commons.SEQUENCE.get(entitySetName) + 1);
} else {
throw new Exception(String.format("Unable to retrieve entity key value for %s", entitySetName));
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
res = entry.getProperty(propertyName).getValue().asPrimitive().get();
@ -639,7 +635,7 @@ public abstract class AbstractUtilities {
productID = Commons.SEQUENCE.get(entitySetName) + 1;
res = "OrderID=1" + ",ProductID=" + String.valueOf(productID);
} else {
throw new Exception(String.format("Unable to retrieve entity key value for %s", entitySetName));
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
productID = Integer.valueOf(entity.getProperty("OrderID").getValue().asPrimitive().get());
@ -654,7 +650,7 @@ public abstract class AbstractUtilities {
messageId = Commons.SEQUENCE.get(entitySetName) + 1;
res = "FromUsername=1" + ",MessageId=" + String.valueOf(messageId);
} else {
throw new Exception(String.format("Unable to retrieve entity key value for %s", entitySetName));
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
} else {
messageId = Integer.valueOf(entity.getProperty("MessageId").getValue().asPrimitive().get());
@ -697,7 +693,7 @@ public abstract class AbstractUtilities {
productDetailId = Commons.SEQUENCE.get(entitySetName) + 1;
res = "ProductID=" + String.valueOf(productId) + ",ProductDetailID=" + String.valueOf(productDetailId);
} else {
throw new Exception(String.format("Unable to retrieve entity key value for %s", entitySetName));
throw new IOException(String.format("Unable to retrieve entity key value for %s", entitySetName));
}
Commons.SEQUENCE.put(entitySetName, productDetailId);
} else {
@ -715,7 +711,7 @@ public abstract class AbstractUtilities {
} else if ("People".equals(entitySetName)) {
res = getDefaultEntryKey(entitySetName, entity, "PersonID");
} else {
throw new Exception(String.format("EntitySet '%s' not found", entitySetName));
throw new IOException(String.format("EntitySet '%s' not found", entitySetName));
}
return res;
@ -740,7 +736,7 @@ public abstract class AbstractUtilities {
*/
public LinkInfo readLinks(
final String entitySetName, final String entityId, final String linkName, final Accept accept)
throws Exception {
throws Exception {
final String basePath = getLinksBasePath(entitySetName, entityId);
@ -857,9 +853,11 @@ public abstract class AbstractUtilities {
throws Exception;
protected abstract InputStream replaceLink(
final InputStream toBeChanged, final String linkName, final InputStream replacement) throws Exception;
final InputStream toBeChanged, final String linkName, final InputStream replacement)
throws Exception;
public abstract InputStream selectEntity(final InputStream entity, final String[] propertyNames) throws Exception;
public abstract InputStream selectEntity(final InputStream entity, final String[] propertyNames)
throws Exception;
protected abstract Accept getDefaultFormat();
@ -869,16 +867,20 @@ public abstract class AbstractUtilities {
final InputStream content, final String title, final String href) throws Exception;
public abstract InputStream addOperation(
final InputStream content, final String name, final String metaAnchor, final String href) throws Exception;
final InputStream content, final String name, final String metaAnchor, final String href)
throws Exception;
protected abstract InputStream replaceProperty(
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
throws Exception;
protected abstract InputStream deleteProperty(final InputStream src, final List<String> path) throws Exception;
protected abstract InputStream deleteProperty(final InputStream src, final List<String> path)
throws Exception;
public abstract Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws Exception;
public abstract Map.Entry<String, List<String>> extractLinkURIs(final InputStream is)
throws Exception;
public abstract Map.Entry<String, List<String>> extractLinkURIs(
final String entitySetName, final String entityId, final String linkName) throws Exception;
final String entitySetName, final String entityId, final String linkName)
throws Exception;
}

View File

@ -122,20 +122,13 @@ public abstract class Commons {
+ (StringUtils.isNotBlank(entityKey) ? getEntityKey(entityKey) + File.separatorChar : "");
}
public static String getLinksURI(
final ODataServiceVersion version,
final String entitySetName,
final String entityId,
final String linkName) throws IOException {
public static String getLinksURI(final String entitySetName, final String entityId, final String linkName)
throws IOException {
return getEntityURI(entitySetName, entityId) + "/" + linkName;
}
public static String getLinksPath(
final ODataServiceVersion version,
final String entitySetName,
final String entityId,
final String linkName,
final Accept accept) throws IOException {
public static String getLinksPath(final String entitySetName, final String entityId,
final String linkName, final Accept accept) throws IOException {
return getLinksPath(ODataServiceVersion.V30, getEntityBasePath(entitySetName, entityId), linkName, accept);
}

View File

@ -65,14 +65,14 @@ public class FSManager {
private final ODataServiceVersion version;
public static FSManager instance(final ODataServiceVersion version) throws Exception {
public static FSManager instance(final ODataServiceVersion version) throws IOException {
if (!instance.containsKey(version)) {
instance.put(version, new FSManager(version));
}
return instance.get(version);
}
private FSManager(final ODataServiceVersion version) throws Exception {
private FSManager(final ODataServiceVersion version) throws IOException {
this.version = version;
fsManager = VFS.getManager();
@ -150,15 +150,15 @@ public class FSManager {
try {
final FileObject fileObject = fsManager.resolveFile(fs + path);
if (!fileObject.exists()) {
if (fileObject.exists()) {
// return new in-memory content
return fileObject.getContent().getInputStream();
} else {
LOG.warn("In-memory path '{}' not found", path);
throw new NotFoundException();
}
// return new in-memory content
return fileObject.getContent().getInputStream();
} catch (IOException e) {
throw new NotFoundException(e);
} catch (FileSystemException e) {
throw new NotFoundException();
}
}
@ -227,4 +227,4 @@ public class FSManager {
}
});
}
}
}

View File

@ -20,6 +20,7 @@ package org.apache.olingo.fit.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
@ -73,21 +74,21 @@ public class JSONUtilities extends AbstractUtilities {
@Override
protected InputStream addLinks(
final String entitySetName, final String entitykey, final InputStream is, final Set<String> links)
throws Exception {
throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
IOUtils.closeQuietly(is);
for (String link : links) {
srcNode.set(link + Constants.get(version, ConstantKey.JSON_NAVIGATION_SUFFIX),
new TextNode(Commons.getLinksURI(version, entitySetName, entitykey, link)));
new TextNode(Commons.getLinksURI(entitySetName, entitykey, link)));
}
return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
}
@Override
protected Set<String> retrieveAllLinkNames(InputStream is) throws Exception {
protected Set<String> retrieveAllLinkNames(InputStream is) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
IOUtils.closeQuietly(is);
@ -115,7 +116,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
protected NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is)
throws Exception {
throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
IOUtils.closeQuietly(is);
@ -150,13 +151,10 @@ public class JSONUtilities extends AbstractUtilities {
return links;
}
/**
* {@inheritDoc }
*/
@Override
protected InputStream normalizeLinks(
final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links)
throws Exception {
throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
@ -191,9 +189,7 @@ public class JSONUtilities extends AbstractUtilities {
return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
}
public InputStream addJsonInlinecount(
final InputStream src, final int count, final Accept accept)
throws Exception {
public InputStream addJsonInlinecount(final InputStream src, final int count) throws Exception {
final JsonNode srcNode = mapper.readTree(src);
@ -208,7 +204,7 @@ public class JSONUtilities extends AbstractUtilities {
return res;
}
public InputStream wrapJsonEntities(final InputStream entities) throws Exception {
public InputStream wrapJsonEntities(final InputStream entities) throws IOException {
final JsonNode node = mapper.readTree(entities);
@ -237,7 +233,7 @@ public class JSONUtilities extends AbstractUtilities {
}
@Override
public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws Exception {
public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
@ -264,7 +260,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
public InputStream readEntities(
final List<String> links, final String linkName, final String next, final boolean forceFeed)
throws Exception {
throws IOException {
if (links.isEmpty()) {
throw new NotFoundException();
@ -312,7 +308,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
protected InputStream replaceLink(
final InputStream toBeChanged, final String linkName, final InputStream replacement)
throws Exception {
throws IOException {
final ObjectNode toBeChangedNode = (ObjectNode) mapper.readTree(toBeChanged);
final ObjectNode replacementNode = (ObjectNode) mapper.readTree(replacement);
@ -332,7 +328,7 @@ public class JSONUtilities extends AbstractUtilities {
}
@Override
protected Map<String, InputStream> getChanges(final InputStream src) throws Exception {
protected Map<String, InputStream> getChanges(final InputStream src) throws IOException {
final Map<String, InputStream> res = new HashMap<String, InputStream>();
final JsonNode srcObject = mapper.readTree(src);
@ -348,15 +344,13 @@ public class JSONUtilities extends AbstractUtilities {
@Override
public Map.Entry<String, List<String>> extractLinkURIs(
final String entitySetName, final String entityId, final String linkName)
throws Exception {
final String entitySetName, final String entityId, final String linkName) throws Exception {
final LinkInfo links = readLinks(entitySetName, entityId, linkName, Accept.JSON_FULLMETA);
return extractLinkURIs(links.getLinks());
}
@Override
public Map.Entry<String, List<String>> extractLinkURIs(final InputStream is)
throws Exception {
public Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);
IOUtils.closeQuietly(is);
@ -383,7 +377,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
public InputStream addEditLink(
final InputStream content, final String title, final String href) throws Exception {
final InputStream content, final String title, final String href) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(content);
IOUtils.closeQuietly(content);
@ -394,7 +388,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
public InputStream addOperation(final InputStream content, final String name, final String metaAnchor,
final String href) throws Exception {
final String href) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(content);
IOUtils.closeQuietly(content);
@ -410,7 +404,7 @@ public class JSONUtilities extends AbstractUtilities {
@Override
public InputStream replaceProperty(
final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue)
throws Exception {
throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
IOUtils.closeQuietly(src);
@ -440,7 +434,7 @@ public class JSONUtilities extends AbstractUtilities {
}
@Override
public InputStream deleteProperty(final InputStream src, final List<String> path) throws Exception {
public InputStream deleteProperty(final InputStream src, final List<String> path) throws IOException {
final ObjectNode srcNode = (ObjectNode) mapper.readTree(src);
IOUtils.closeQuietly(src);

View File

@ -24,10 +24,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.slf4j.Logger;
@ -66,7 +68,8 @@ public class XMLElement {
return new ByteArrayInputStream(content.toByteArray());
}
public XMLEventReader getContentReader(final ODataServiceVersion version) throws Exception {
public XMLEventReader getContentReader(final ODataServiceVersion version)
throws XMLStreamException, IOException {
return new XMLEventReaderWrapper(getContent(), version);
}
@ -83,7 +86,7 @@ public class XMLElement {
IOUtils.closeQuietly(content);
}
public InputStream toStream() throws Exception {
public InputStream toStream() {
InputStream res;
try {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@ -98,7 +101,10 @@ public class XMLElement {
osw.close();
res = new ByteArrayInputStream(bos.toByteArray());
} catch (Exception e) {
} catch (IOException e) {
LOG.error("Error serializing element", e);
res = null;
} catch (XMLStreamException e) {
LOG.error("Error serializing element", e);
res = null;
}

View File

@ -19,13 +19,16 @@
package org.apache.olingo.fit.utils;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
@ -43,7 +46,8 @@ public class XMLEventReaderWrapper implements XMLEventReader {
private XMLEvent nextGivenEvent = null;
public XMLEventReaderWrapper(final InputStream stream, final ODataServiceVersion version) throws Exception {
public XMLEventReaderWrapper(final InputStream stream, final ODataServiceVersion version)
throws IOException, XMLStreamException {
final StringBuilder startBuilder = new StringBuilder();
startBuilder.append("<").append(CONTENT).
append(" xmlns:m").append("=\"").append(Constants.get(version, ConstantKey.METADATA_NS)).append("\"").

View File

@ -155,7 +155,7 @@ public class XMLUtilities extends AbstractUtilities {
final Set<Attribute> attributes = new HashSet<Attribute>();
attributes.add(eventFactory.createAttribute(new QName("title"), link));
attributes.add(eventFactory.createAttribute(new QName("href"),
Commons.getLinksURI(version, entitySetName, entitykey, link)));
Commons.getLinksURI(entitySetName, entitykey, link)));
attributes.add(eventFactory.createAttribute(new QName("rel"),
Constants.get(version, ConstantKey.ATOM_LINK_REL) + link));
attributes.add(eventFactory.createAttribute(new QName("type"),
@ -727,9 +727,7 @@ public class XMLUtilities extends AbstractUtilities {
return new SimpleEntry<Integer, XMLElement>(Integer.valueOf(depth - 1), getXmlElement(start, reader));
}
public InputStream addAtomInlinecount(
final InputStream feed, final int count, final Accept accept)
throws Exception {
public InputStream addAtomInlinecount(final InputStream feed, final int count) throws Exception {
final XMLEventReader reader = getEventReader(feed);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();

View File

@ -50,12 +50,12 @@ public abstract class AbstractRequest {
// If using and Edm enabled client, checks that the cached service root matches the request URI
if (odataClient instanceof CommonEdmEnabledODataClient
&& !request.getURI().toASCIIString().startsWith(
((CommonEdmEnabledODataClient) odataClient).getServiceRoot())) {
((CommonEdmEnabledODataClient<?>) odataClient).getServiceRoot())) {
throw new IllegalArgumentException(
String.format("The current request URI %s does not match the configured service root %s",
request.getURI().toASCIIString(),
((CommonEdmEnabledODataClient) odataClient).getServiceRoot()));
((CommonEdmEnabledODataClient<?>) odataClient).getServiceRoot()));
}
}

View File

@ -28,17 +28,16 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
/**
* This class implements an OData create request.
@ -74,7 +73,7 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
try {
return odataClient.getWriter().writeEntity(entity, ODataPubFormat.fromString(getContentType()));
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
@ -132,7 +131,7 @@ public class ODataEntityCreateRequestImpl<E extends CommonODataEntity>
entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,17 +28,16 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
/**
* This class implements an OData update request.
@ -89,7 +88,7 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
try {
return odataClient.getWriter().writeEntity(changes, ODataPubFormat.fromString(getContentType()));
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
@ -130,7 +129,7 @@ public class ODataEntityUpdateRequestImpl<E extends CommonODataEntity>
entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,7 +28,6 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
@ -84,7 +83,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
try {
return odataClient.getWriter().writeProperty(property, ODataFormat.fromString(getContentType()));
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
@ -122,7 +121,7 @@ public class ODataPropertyUpdateRequestImpl extends AbstractODataBasicRequest<OD
property = odataClient.getBinder().getODataProperty(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,14 +28,13 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
/**
* This class implements an insert link OData request.
@ -81,7 +80,7 @@ public class ODataLinkCreateRequestImpl extends AbstractODataBasicRequest<ODataL
try {
return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}

View File

@ -28,14 +28,13 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.ODataLink;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
/**
* This class implements an update link OData request.
@ -81,7 +80,7 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
try {
return odataClient.getWriter().writeLink(link, ODataFormat.fromString(getContentType()));
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
@ -90,14 +89,6 @@ public class ODataLinkUpdateRequestImpl extends AbstractODataBasicRequest<ODataL
*/
public class ODataLinkUpdateResponseImpl extends AbstractODataResponse implements ODataLinkOperationResponse {
/**
* Constructor.
* <p>
* Just to create response templates to be initialized from batch.
*/
private ODataLinkUpdateResponseImpl() {
}
/**
* Constructor.
*

View File

@ -34,21 +34,21 @@ import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.domain.ODataInvokeResult;
import org.apache.olingo.commons.api.domain.CommonODataProperty;
import org.apache.olingo.commons.api.domain.ODataInvokeResult;
import org.apache.olingo.commons.api.domain.ODataValue;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.api.op.ODataSerializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.api.v4.ODataClient;
import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
/**
* This class implements an OData invoke operation request.
@ -143,7 +143,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
try {
return odataClient.getWriter().writeEntity(tmp, getPOSTParameterFormat());
} catch (final ODataSerializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
@ -228,7 +228,7 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
} catch (IOException e) {
throw new HttpClientException(e);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -25,9 +25,8 @@ import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
@ -89,7 +88,7 @@ public class ODataEntityRequestImpl<E extends CommonODataEntity>
entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -25,9 +25,8 @@ import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
@ -98,7 +97,7 @@ public class ODataEntitySetRequestImpl<ES extends CommonODataEntitySet>
entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -89,7 +89,7 @@ public class ODataPropertyRequestImpl<T extends CommonODataProperty>
} catch (IOException e) {
throw new HttpClientException(e);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,13 +28,12 @@ import org.apache.http.client.HttpClient;
import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
import org.apache.olingo.client.api.communication.response.ODataRawResponse;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataRequest;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.format.ODataPubFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
* This class implements a generic OData request.
@ -101,7 +100,7 @@ public class ODataRawRequestImpl extends AbstractODataRequest<ODataPubFormat>
return odataClient.getReader().
read(new ByteArrayInputStream(obj), getContentType(), reference);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
}
}
}

View File

@ -26,7 +26,6 @@ import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.data.ServiceDocument;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.ODataServiceDocument;
import org.apache.olingo.commons.api.format.ODataFormat;
@ -91,7 +90,7 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
serviceDocument = odataClient.getBinder().getODataServiceDocument(resource.getPayload());
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -89,7 +89,7 @@ public class ODataLinkCollectionRequestImpl extends AbstractODataRetrieveRequest
} catch (IOException e) {
throw new HttpClientException(e);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -74,7 +74,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest<ODataDel
} catch (IOException e) {
throw new HttpClientException(e);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,13 +28,12 @@ import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
@ -128,7 +127,7 @@ public class ODataMediaEntityCreateRequestImpl<E extends CommonODataEntity>
entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -28,13 +28,12 @@ import org.apache.olingo.client.api.CommonODataClient;
import org.apache.olingo.client.api.communication.request.streamed.MediaEntityUpdateStreamManager;
import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest;
import org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.client.api.http.HttpMethod;
import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.domain.CommonODataEntity;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
/**
@ -129,7 +128,7 @@ public class ODataMediaEntityUpdateRequestImpl<E extends CommonODataEntity>
entity = (E) odataClient.getBinder().getODataEntity(resource);
} catch (final ODataDeserializerException e) {
throw new HttpClientException(e);
throw new IllegalArgumentException(e);
} finally {
this.close();
}

View File

@ -347,23 +347,23 @@ public abstract class AbstractODataBinder implements CommonODataBinder {
if (contextURL.getDerivedEntity() == null) {
for (EdmSchema schema : edm.getSchemas()) {
final EdmEntityContainer container = schema.getEntityContainer();
if(container != null) {
EdmBindingTarget bindingTarget = container.getEntitySet(contextURL.getEntitySetOrSingletonOrType());
if (bindingTarget == null) {
bindingTarget = container.getSingleton(contextURL.getEntitySetOrSingletonOrType());
}
if (bindingTarget != null) {
if (contextURL.getNavOrPropertyPath() == null) {
type = bindingTarget.getEntityType();
} else {
final EdmNavigationProperty navProp = bindingTarget.getEntityType().
getNavigationProperty(contextURL.getNavOrPropertyPath());
type = navProp == null
? bindingTarget.getEntityType()
: navProp.getType();
}
}
if (container != null) {
EdmBindingTarget bindingTarget = container.getEntitySet(contextURL.getEntitySetOrSingletonOrType());
if (bindingTarget == null) {
bindingTarget = container.getSingleton(contextURL.getEntitySetOrSingletonOrType());
}
if (bindingTarget != null) {
if (contextURL.getNavOrPropertyPath() == null) {
type = bindingTarget.getEntityType();
} else {
final EdmNavigationProperty navProp = bindingTarget.getEntityType().
getNavigationProperty(contextURL.getNavOrPropertyPath());
type = navProp == null
? bindingTarget.getEntityType()
: navProp.getType();
}
}
}
}
if (type == null) {

View File

@ -36,14 +36,15 @@ import org.apache.olingo.commons.api.format.Format;
import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.core.data.AtomDeserializer;
import org.apache.olingo.commons.core.data.JSONLinkCollectionDeserializer;
import org.apache.olingo.commons.core.op.AbstractODataDeserializer;
public class ODataDeserializerImpl extends AbstractODataDeserializer implements ODataDeserializer {
private final Format format;
public ODataDeserializerImpl(final ODataServiceVersion version, final Format format) {
super(version, format);
public ODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, final Format format) {
super(version, serverMode, format);
this.format = format;
}
@ -68,7 +69,7 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements
try {
return format == ODataFormat.XML ?
new AtomDeserializer(version).linkCollection(input) :
null; //json(input, LinkCollection.class);
new JSONLinkCollectionDeserializer(version, false).toLinkCollection(input);
} catch (final XMLStreamException e) {
throw new ODataDeserializerException(e);
}

View File

@ -279,15 +279,14 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder
@Override
public ODataProperty getODataProperty(final ResWrap<Property> resource) {
final Property payload = resource.getPayload();
final EdmTypeInfo typeInfo = buildTypeInfo(resource.getContextURL(), resource.getMetadataETag(),
resource.getPayload().getName(), resource.getPayload().getType());
payload.getName(), payload.getType());
final ODataProperty property = new ODataPropertyImpl(resource.getPayload().getName(),
getODataValue(typeInfo == null
? null
: typeInfo.getFullQualifiedName(),
resource.getPayload(), resource.getContextURL(), resource.getMetadataETag()));
odataAnnotations(resource.getPayload(), property);
final ODataProperty property = new ODataPropertyImpl(payload.getName(),
getODataValue(typeInfo == null ? null : typeInfo.getFullQualifiedName(),
payload, resource.getContextURL(), resource.getMetadataETag()));
odataAnnotations(payload, property);
return property;
}

View File

@ -44,8 +44,8 @@ public class ODataDeserializerImpl extends AbstractODataDeserializer implements
private final Format format;
public ODataDeserializerImpl(final ODataServiceVersion version, final Format format) {
super(version, format);
public ODataDeserializerImpl(final ODataServiceVersion version, final boolean serverMode, final Format format) {
super(version, serverMode, format);
this.format = format;
}

View File

@ -104,7 +104,7 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
@Override
public ODataDeserializer getDeserializer(final Format format) {
return new ODataDeserializerImpl(getServiceVersion(), format);
return new ODataDeserializerImpl(getServiceVersion(), false, format);
}
@Override

View File

@ -115,7 +115,7 @@ public class ODataClientImpl extends AbstractODataClient<UpdateType> implements
@Override
public ODataDeserializer getDeserializer(final Format format) {
return new ODataDeserializerImpl(getServiceVersion(), format);
return new ODataDeserializerImpl(getServiceVersion(), false, format);
}
@Override

View File

@ -20,12 +20,15 @@ package org.apache.olingo.commons.core.data;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.olingo.commons.api.data.Annotatable;
import org.apache.olingo.commons.api.data.Annotation;
public abstract class AbstractAnnotatedObject extends AbstractPayloadObject implements Annotatable {
private static final long serialVersionUID = 4163841499530412213L;
public abstract class AbstractAnnotatedObject implements Annotatable {
private final List<Annotation> annotations = new ArrayList<Annotation>();
@ -34,4 +37,18 @@ public abstract class AbstractAnnotatedObject extends AbstractPayloadObject impl
return annotations;
}
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -21,14 +21,10 @@ package org.apache.olingo.commons.core.data;
import java.net.URI;
import java.text.ParseException;
abstract class AbstractODataObject extends AbstractAnnotatedObject {
private static final long serialVersionUID = -4391162864875546927L;
public abstract class AbstractODataObject extends AbstractAnnotatedObject {
private URI baseURI;
private URI id;
private String title;
public URI getBaseURI() {

View File

@ -1,48 +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.commons.core.data;
import java.io.Serializable;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* Abstract representation of a payload (Atom, JSON) object.
*/
public abstract class AbstractPayloadObject implements Serializable {
private static final long serialVersionUID = 1634654241914156675L;
@Override
public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

View File

@ -23,12 +23,8 @@ import org.apache.olingo.commons.api.data.Value;
public class AnnotationImpl extends AbstractAnnotatedObject implements Annotation {
private static final long serialVersionUID = -2532246000091187020L;
private String term;
private String type;
private Value value;
@Override

View File

@ -23,10 +23,7 @@ import org.apache.olingo.commons.api.data.DeletedEntity;
public class DeletedEntityImpl extends AbstractAnnotatedObject implements DeletedEntity {
private static final long serialVersionUID = 2075093398299488510L;
private URI id;
private Reason reason;
@Override

View File

@ -23,12 +23,8 @@ import org.apache.olingo.commons.api.data.DeltaLink;
public class DeltaLinkImpl extends AbstractAnnotatedObject implements DeltaLink {
private static final long serialVersionUID = 581329273399308799L;
private URI source;
private String relationship;
private URI target;
@Override

View File

@ -31,20 +31,15 @@ import org.apache.olingo.commons.api.domain.ODataOperation;
*/
public class EntityImpl extends AbstractODataObject implements Entity {
private static final long serialVersionUID = 2127764552600969783L;
private String eTag;
private String type;
private Link readLink;
private Link editLink;
private final List<Link> associationLinks = new ArrayList<Link>();
private final List<Link> navigationLinks = new ArrayList<Link>();
private final List<Link> mediaEditLinks = new ArrayList<Link>();
private final List<ODataOperation> operations = new ArrayList<ODataOperation>();
@ -52,9 +47,7 @@ public class EntityImpl extends AbstractODataObject implements Entity {
private final List<Property> properties = new ArrayList<Property>();
private URI mediaContentSource;
private String mediaContentType;
private String mediaETag;
@Override

View File

@ -26,8 +26,6 @@ import org.apache.olingo.commons.api.data.EntitySet;
public class EntitySetImpl extends AbstractODataObject implements EntitySet {
private static final long serialVersionUID = -9159884750819150969L;
private Integer count;
private final List<Entity> entities = new ArrayList<Entity>();

View File

@ -0,0 +1,80 @@
/*
* 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.commons.core.data;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ResWrap;
import org.apache.olingo.commons.api.data.v3.LinkCollection;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.op.ODataDeserializerException;
import org.apache.olingo.commons.core.data.v3.LinkCollectionImpl;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class JSONLinkCollectionDeserializer extends JsonDeserializer {
public JSONLinkCollectionDeserializer(final ODataServiceVersion version, final boolean serverMode) {
super(version, serverMode);
}
protected ResWrap<LinkCollection> doDeserialize(final JsonParser parser) throws IOException {
final ObjectNode tree = parser.getCodec().readTree(parser);
final LinkCollectionImpl links = new LinkCollectionImpl();
if (tree.hasNonNull("odata.metadata")) {
links.setMetadata(URI.create(tree.get("odata.metadata").textValue()));
}
if (tree.hasNonNull(Constants.JSON_URL)) {
links.getLinks().add(URI.create(tree.get(Constants.JSON_URL).textValue()));
}
if (tree.hasNonNull(Constants.VALUE)) {
for (final JsonNode item : tree.get(Constants.VALUE)) {
final URI uri = URI.create(item.get(Constants.JSON_URL).textValue());
links.getLinks().add(uri);
}
}
if (tree.hasNonNull(jsonNextLink)) {
links.setNext(URI.create(tree.get(jsonNextLink).textValue()));
}
return new ResWrap<LinkCollection>((URI) null, null, links);
}
public ResWrap<LinkCollection> toLinkCollection(InputStream input) throws ODataDeserializerException {
try {
JsonParser parser = new JsonFactory(new ObjectMapper()).createParser(input);
return doDeserialize(parser);
} catch (final IOException e) {
throw new ODataDeserializerException(e);
}
}
}

View File

@ -102,7 +102,7 @@ public class JsonSerializer implements ODataSerializer {
} else if (obj instanceof Entity) {
new JSONEntitySerializer(version, serverMode).doContainerSerialize((ResWrap<Entity>) container, json);
} else if (obj instanceof Property) {
new JSONPropertySerializer(version, serverMode).doSerialize((Property) obj, json);
new JSONPropertySerializer(version, serverMode).doContainerSerialize((ResWrap<Property>) container, json);
} else if (obj instanceof Link) {
link((Link) obj, json);
}

View File

@ -24,20 +24,12 @@ import org.apache.olingo.commons.api.data.Link;
public class LinkImpl extends AbstractAnnotatedObject implements Link {
private static final long serialVersionUID = -3449344217160035501L;
private String title;
private String rel;
private String href;
private String type;
private String mediaETag;
private Entity entity;
private EntitySet entitySet;
@Override

View File

@ -23,12 +23,8 @@ import org.apache.olingo.commons.api.data.Value;
public class PropertyImpl extends AbstractAnnotatedObject implements Property {
private static final long serialVersionUID = -7175704800169997060L;
private String name;
private String type;
private Value value;
@Override

View File

@ -1,118 +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.commons.core.data.v3;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.data.v3.LinkCollection;
import org.apache.olingo.commons.core.data.AbstractPayloadObject;
/**
* Link from an entity, represented via JSON.
*/
public class JSONLinkCollectionImpl extends AbstractPayloadObject implements LinkCollection {
private static final long serialVersionUID = -5006368367235783907L;
/**
* JSON link URL representation.
*/
static class JSONLinkURL extends AbstractPayloadObject {
private static final long serialVersionUID = 5365055617973271468L;
private URI url;
public URI getUrl() {
return url;
}
public void setUrl(final URI url) {
this.url = url;
}
}
@JsonProperty(value = "odata.metadata", required = false)
private URI metadata;
@JsonProperty(required = false)
private URI url;
@JsonProperty(value = "value", required = false)
private final List<JSONLinkURL> links = new ArrayList<JSONLinkURL>();
@JsonProperty(value = "odata.nextLink", required = false)
private String next;
/**
* Gets the metadata URI.
*/
public URI getMetadata() {
return metadata;
}
/**
* Sets the metadata URI.
*
* @param metadata metadata URI.
*/
public void setMetadata(final URI metadata) {
this.metadata = metadata;
}
/**
* {@inheritDoc }
*/
@JsonIgnore
@Override
public List<URI> getLinks() {
final List<URI> result = new ArrayList<URI>();
if (this.url == null) {
for (JSONLinkURL link : links) {
result.add(link.getUrl());
}
} else {
result.add(this.url);
}
return result;
}
/**
* {@inheritDoc }
*/
@JsonIgnore
@Override
public void setNext(final URI next) {
this.next = next == null ? null : next.toASCIIString();
}
/**
* {@inheritDoc }
*/
@JsonIgnore
@Override
public URI getNext() {
return next == null ? null : URI.create(next);
}
}

View File

@ -21,9 +21,11 @@ package org.apache.olingo.commons.core.data.v3;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.commons.api.data.v3.LinkCollection;
public class LinkCollectionImpl implements LinkCollection {
import org.apache.olingo.commons.api.data.v3.LinkCollection;
import org.apache.olingo.commons.core.data.AbstractAnnotatedObject;
public class LinkCollectionImpl extends AbstractAnnotatedObject implements LinkCollection {
private final List<URI> links = new ArrayList<URI>();
private URI next;

View File

@ -27,12 +27,8 @@ import org.apache.olingo.commons.core.data.EntitySetImpl;
public class DeltaImpl extends EntitySetImpl implements Delta {
private static final long serialVersionUID = 4576771708961553195L;
private final List<DeletedEntity> deletedEntities = new ArrayList<DeletedEntity>();
private final List<DeltaLink> addedLinks = new ArrayList<DeltaLink>();
private final List<DeltaLink> deletedLinks = new ArrayList<DeltaLink>();
@Override

View File

@ -51,12 +51,12 @@ public abstract class AbstractODataDeserializer {
protected final ODataServiceVersion version;
protected final ODataDeserializer deserializer;
public AbstractODataDeserializer(final ODataServiceVersion version, final Format format) {
public AbstractODataDeserializer(final ODataServiceVersion version, final boolean serverMode, final Format format) {
this.version = version;
if (format == ODataFormat.XML || format == ODataPubFormat.ATOM) {
deserializer = new AtomDeserializer(version);
} else {
deserializer = new JsonDeserializer(version, false);
deserializer = new JsonDeserializer(version, serverMode);
}
}

View File

@ -18,52 +18,26 @@
*/
package org.apache.olingo.server.core;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
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;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ResWrap;
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.HttpMethod;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
import org.apache.olingo.commons.core.op.InjectableSerializerProvider;
import org.apache.olingo.commons.api.http.HttpMethod;
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.DefaultProcessor;
import org.apache.olingo.server.api.processor.EntityProcessor;
import org.apache.olingo.server.api.processor.EntitySetProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.processor.*;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriResource;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.uri.parser.Parser;
import org.apache.olingo.server.core.uri.validator.UriValidator;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ODataHandler {
@ -134,39 +108,6 @@ public class ODataHandler {
UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
switch (lastPathSegment.getKind()) {
case entitySet:
long time = System.nanoTime();
ResWrap<EntitySet> wrap = new ResWrap<EntitySet>(
ContextURL.getInstance(URI.create("dummyContextURL")), "dummyMetadataETag",
createEntitySet());
System.out.println((System.nanoTime() - time) / 1000 + " microseconds");
time = System.nanoTime();
CircleStreamBuffer buffer = new CircleStreamBuffer();
if (false) {
ObjectMapper mapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);
mapper.setInjectableValues(new InjectableValues.Std()
.addValue(ODataServiceVersion.class, ODataServiceVersion.V40)
.addValue(Boolean.class, Boolean.TRUE));
mapper.setSerializerProvider(new InjectableSerializerProvider(mapper.getSerializerProvider(),
mapper.getSerializationConfig()
.withAttribute(ODataServiceVersion.class, ODataServiceVersion.V40)
.withAttribute(Boolean.class, Boolean.TRUE),
mapper.getSerializerFactory()));
try {
mapper.writeValue(buffer.getOutputStream(), wrap);
} catch (final IOException e) {}
response.setContent(buffer.getInputStream());
} else {
ODataSerializer serializer = odata.createSerializer(org.apache.olingo.server.api.serializer.ODataFormat.JSON);
response.setContent(serializer.entitySet(
edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container"))
.getEntitySet("ESAllPrim"),
wrap.getPayload(),
ContextURL.getInstance(URI.create("dummyContextURL"))));
}
System.out.println((System.nanoTime() - time) / 1000 + " microseconds");
response.setStatusCode(200);
response.setHeader("Content-Type", ContentType.APPLICATION_JSON);
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
if (request.getMethod().equals(HttpMethod.GET)) {
EntitySetProcessor esp = selectProcessor(EntitySetProcessor.class);
@ -240,34 +181,4 @@ public class ODataHandler {
}
}
}
protected Entity createEntity() {
Entity entity = new EntityImpl();
Property property = new PropertyImpl();
property.setName("PropertyString");
property.setType("String"); //"dummyType");
property.setValue(new PrimitiveValueImpl("dummyValue"));
entity.getProperties().add(property);
Property propertyInt = new PropertyImpl();
propertyInt.setName("PropertyInt16");
// propertyInt.setType("Edm.Int32");
propertyInt.setValue(new PrimitiveValueImpl("042"));
entity.getProperties().add(propertyInt);
Property propertyGuid = new PropertyImpl();
propertyGuid.setName("PropertyGuid");
propertyGuid.setType("Edm.Guid");
propertyGuid.setValue(new PrimitiveValueImpl(UUID.randomUUID().toString()));
entity.getProperties().add(propertyGuid);
return entity;
}
protected EntitySet createEntitySet() {
EntitySet entitySet = new EntitySetImpl();
entitySet.setCount(4242);
entitySet.setNext(URI.create("nextLinkURI"));
for (int i = 0; i < 1000; i++) {
entitySet.getEntities().add(createEntity());
}
return entitySet;
}
}
}

View File

@ -121,6 +121,17 @@
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-commons-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>olingo-commons-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
@ -140,6 +151,11 @@
<artifactId>commons-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
<artifactId>core</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -29,6 +29,7 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.server.api.ODataHttpHandler;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.processor.SampleJsonProcessor;
import org.apache.olingo.server.tecsvc.processor.TechnicalProcessor;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.slf4j.Logger;
@ -56,8 +57,9 @@ public class TechnicalServlet extends HttpServlet {
ODataHttpHandler handler = odata.createHandler(edm);
handler.register(new TechnicalProcessor(dataProvider));
// handler.register(new TechnicalProcessor(dataProvider));
handler.register(new SampleJsonProcessor());
handler.process(req, resp);
}

View File

@ -0,0 +1,126 @@
/*
* 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.tecsvc.processor;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntitySet;
import org.apache.olingo.commons.api.data.Property;
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.core.data.EntityImpl;
import org.apache.olingo.commons.core.data.EntitySetImpl;
import org.apache.olingo.commons.core.data.PrimitiveValueImpl;
import org.apache.olingo.commons.core.data.PropertyImpl;
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.EntityProcessor;
import org.apache.olingo.server.api.processor.EntitySetProcessor;
import org.apache.olingo.server.api.serializer.ODataFormat;
import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.uri.UriInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.UUID;
public class SampleJsonProcessor implements EntitySetProcessor, EntityProcessor {
private static final Logger LOG = LoggerFactory.getLogger(SampleJsonProcessor.class);
private OData odata;
private Edm edm;
@Override
public void init(OData odata, Edm edm) {
this.odata = odata;
this.edm = edm;
}
@Override
public void readEntitySet(ODataRequest request, ODataResponse response, UriInfo uriInfo, String format) {
long time = System.nanoTime();
EntitySet entitySet = createEntitySet();
LOG.info((System.nanoTime() - time) / 1000 + " microseconds");
time = System.nanoTime();
ODataSerializer serializer = odata.createSerializer(ODataFormat.JSON);
response.setContent(serializer.entitySet(
edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container"))
.getEntitySet("ESAllPrim"),
entitySet,
ContextURL.getInstance(URI.create("dummyContextURL"))));
LOG.info("Finished in " + (System.nanoTime() - time) / 1000 + " microseconds");
response.setStatusCode(200);
response.setHeader("Content-Type", ContentType.APPLICATION_JSON);
}
@Override
public void readEntity(ODataRequest request, ODataResponse response, UriInfo uriInfo, String format) {
long time = System.nanoTime();
Entity entity = createEntity();
LOG.info((System.nanoTime() - time) / 1000 + " microseconds");
time = System.nanoTime();
ODataSerializer serializer = odata.createSerializer(ODataFormat.JSON);
response.setContent(serializer.entity(
edm.getEntityContainer(new FullQualifiedName("com.sap.odata.test1", "Container"))
.getEntitySet("ESAllPrim").getEntityType(),
entity,
ContextURL.getInstance(URI.create("dummyContextURL"))));
LOG.info("Finished in " + (System.nanoTime() - time) / 1000 + " microseconds");
response.setStatusCode(200);
response.setHeader("Content-Type", ContentType.APPLICATION_JSON);
}
protected Entity createEntity() {
Entity entity = new EntityImpl();
Property property = new PropertyImpl();
property.setName("PropertyString");
property.setType("String"); //"dummyType");
property.setValue(new PrimitiveValueImpl("dummyValue"));
entity.getProperties().add(property);
Property propertyInt = new PropertyImpl();
propertyInt.setName("PropertyInt16");
// propertyInt.setType("Edm.Int32");
propertyInt.setValue(new PrimitiveValueImpl("42"));
entity.getProperties().add(propertyInt);
Property propertyGuid = new PropertyImpl();
propertyGuid.setName("PropertyGuid");
propertyGuid.setType("Edm.Guid");
propertyGuid.setValue(new PrimitiveValueImpl(UUID.randomUUID().toString()));
entity.getProperties().add(propertyGuid);
return entity;
}
protected EntitySet createEntitySet() {
EntitySet entitySet = new EntitySetImpl();
entitySet.setCount(4242);
entitySet.setNext(URI.create("nextLinkURI"));
for (int i = 0; i < 1000; i++) {
entitySet.getEntities().add(createEntity());
}
return entitySet;
}
}