From 70afb2acc50aef1270858bad75eb8dc125b08c3f Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Wed, 11 Jun 2014 13:39:53 +0200 Subject: [PATCH] [OLINGO-317] Finished DeSerializer refactoring --- .../apache/olingo/fit/AbstractServices.java | 114 ++++++++++------ .../org/apache/olingo/fit/V4Services.java | 2 +- .../olingo/fit/utils/AbstractUtilities.java | 54 ++++---- .../org/apache/olingo/fit/utils/Commons.java | 15 +-- .../apache/olingo/fit/utils/FSManager.java | 18 +-- .../olingo/fit/utils/JSONUtilities.java | 42 +++--- .../apache/olingo/fit/utils/XMLElement.java | 12 +- .../fit/utils/XMLEventReaderWrapper.java | 6 +- .../apache/olingo/fit/utils/XMLUtilities.java | 6 +- .../request/AbstractRequest.java | 4 +- .../cud/ODataEntityCreateRequestImpl.java | 17 ++- .../cud/ODataEntityUpdateRequestImpl.java | 17 ++- .../cud/ODataPropertyUpdateRequestImpl.java | 5 +- .../cud/v3/ODataLinkCreateRequestImpl.java | 11 +- .../cud/v3/ODataLinkUpdateRequestImpl.java | 19 +-- .../invoke/AbstractODataInvokeRequest.java | 18 +-- .../retrieve/ODataEntityRequestImpl.java | 5 +- .../retrieve/ODataEntitySetRequestImpl.java | 5 +- .../retrieve/ODataPropertyRequestImpl.java | 2 +- .../request/retrieve/ODataRawRequestImpl.java | 7 +- .../ODataServiceDocumentRequestImpl.java | 3 +- .../v3/ODataLinkCollectionRequestImpl.java | 2 +- .../retrieve/v4/ODataDeltaRequestImpl.java | 2 +- .../ODataMediaEntityCreateRequestImpl.java | 7 +- .../ODataMediaEntityUpdateRequestImpl.java | 7 +- .../client/core/op/AbstractODataBinder.java | 34 ++--- .../op/impl/v3/ODataDeserializerImpl.java | 7 +- .../core/op/impl/v4/ODataBinderImpl.java | 13 +- .../op/impl/v4/ODataDeserializerImpl.java | 4 +- .../client/core/v3/ODataClientImpl.java | 2 +- .../client/core/v4/ODataClientImpl.java | 2 +- .../core/data/AbstractAnnotatedObject.java | 23 +++- .../core/data/AbstractODataObject.java | 6 +- .../core/data/AbstractPayloadObject.java | 48 ------- .../commons/core/data/AnnotationImpl.java | 4 - .../commons/core/data/DeletedEntityImpl.java | 3 - .../commons/core/data/DeltaLinkImpl.java | 4 - .../olingo/commons/core/data/EntityImpl.java | 7 - .../commons/core/data/EntitySetImpl.java | 2 - .../data/JSONLinkCollectionDeserializer.java | 80 +++++++++++ .../commons/core/data/JsonSerializer.java | 2 +- .../olingo/commons/core/data/LinkImpl.java | 8 -- .../commons/core/data/PropertyImpl.java | 4 - .../core/data/v3/JSONLinkCollectionImpl.java | 118 ---------------- .../core/data/v3/LinkCollectionImpl.java | 6 +- .../commons/core/data/v4/DeltaImpl.java | 4 - .../core/op/AbstractODataDeserializer.java | 4 +- .../olingo/server/core/ODataHandler.java | 101 +------------- lib/server-tecsvc/pom.xml | 16 +++ .../server/tecsvc/TechnicalServlet.java | 6 +- .../tecsvc/processor/SampleJsonProcessor.java | 126 ++++++++++++++++++ 51 files changed, 495 insertions(+), 539 deletions(-) delete mode 100644 lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPayloadObject.java create mode 100755 lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java delete mode 100644 lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java create mode 100644 lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java index 71a7bf501..ad931b9f5 100644 --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@ -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 jcontainer = jsonDeserializer.toEntity( - IOUtils.toInputStream(entity, Constants.ENCODING)); - entry = jcontainer.getPayload(); - - container = new ResWrap( - 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 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 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 container = new ResWrap( 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 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()); diff --git a/fit/src/main/java/org/apache/olingo/fit/V4Services.java b/fit/src/main/java/org/apache/olingo/fit/V4Services.java index 81f70ee2d..eaa66d0a6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -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); diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java index 99a332014..4706aa46a 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java @@ -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 links) @@ -128,6 +127,7 @@ public abstract class AbstractUtilities { * @param is * @return * @throws IOException + * @throws XMLStreamException */ protected abstract Set 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 linksToBeKept; try { linksToBeKept = new HashSet(navigationProperties.keySet()); - } catch (Exception e) { + } catch (NullPointerException e) { linksToBeKept = Collections. emptySet(); } for (String availableLink : new HashSet(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 links) throws IOException { + final Collection links) throws Exception { final HashSet uris = new HashSet(); @@ -371,7 +368,7 @@ public abstract class AbstractUtilities { public void putLinksInMemory( final String basePath, final String entitySetName, final String linkName, final Collection uris) - throws IOException { + throws Exception { fsManager.putInMemory( Commons.getLinksAsJSON(version, entitySetName, new SimpleEntry>(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 path, final boolean justValue) throws Exception; - protected abstract InputStream deleteProperty(final InputStream src, final List path) throws Exception; + protected abstract InputStream deleteProperty(final InputStream src, final List path) + throws Exception; - public abstract Map.Entry> extractLinkURIs(final InputStream is) throws Exception; + public abstract Map.Entry> extractLinkURIs(final InputStream is) + throws Exception; public abstract Map.Entry> extractLinkURIs( - final String entitySetName, final String entityId, final String linkName) throws Exception; + final String entitySetName, final String entityId, final String linkName) + throws Exception; } diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java index c9f4128c7..16d984cc8 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java @@ -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); } diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java index 374d0f513..650a98f06 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java @@ -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 { } }); } -} \ No newline at end of file +} diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java index fe3f511fb..23a95cd76 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java @@ -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 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 retrieveAllLinkNames(InputStream is) throws Exception { + protected Set 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 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 getChanges(final InputStream src) throws Exception { + protected Map getChanges(final InputStream src) throws IOException { final Map res = new HashMap(); final JsonNode srcObject = mapper.readTree(src); @@ -348,15 +344,13 @@ public class JSONUtilities extends AbstractUtilities { @Override public Map.Entry> 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> extractLinkURIs(final InputStream is) - throws Exception { + public Map.Entry> 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 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 path) throws Exception { + public InputStream deleteProperty(final InputStream src, final List path) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); IOUtils.closeQuietly(src); diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLElement.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLElement.java index b412ba31f..c8a0ee8a8 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLElement.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLElement.java @@ -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; } diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLEventReaderWrapper.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLEventReaderWrapper.java index 7bae6d8ae..1774f0cd6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLEventReaderWrapper.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLEventReaderWrapper.java @@ -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("\""). diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java index 84a6cd2e6..f5ba1c1a6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java @@ -155,7 +155,7 @@ public class XMLUtilities extends AbstractUtilities { final Set attributes = new HashSet(); 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.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(); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java index da9b40f6f..d86f59928 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractRequest.java @@ -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())); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java index 10236e0af..67a6950a5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityCreateRequestImpl.java @@ -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 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 entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java index acbe76455..11650427e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataEntityUpdateRequestImpl.java @@ -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 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 entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java index 759ebbb67..5f9014d96 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/cud/ODataPropertyUpdateRequestImpl.java @@ -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 - * Just to create response templates to be initialized from batch. - */ - private ODataLinkUpdateResponseImpl() { - } - /** * Constructor. * diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java index 8ecd82781..7fcaa6599 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java @@ -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 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 } catch (IOException e) { throw new HttpClientException(e); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java index 2904577d2..cecbcd14e 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java @@ -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 entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java index 90df1e2a2..6e7df5012 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java @@ -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 entitySet = (ES) odataClient.getBinder().getODataEntitySet(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java index 0be792054..c409d99a4 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataPropertyRequestImpl.java @@ -89,7 +89,7 @@ public class ODataPropertyRequestImpl } catch (IOException e) { throw new HttpClientException(e); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java index faa8a283f..b2632b789 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataRawRequestImpl.java @@ -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 return odataClient.getReader(). read(new ByteArrayInputStream(obj), getContentType(), reference); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java index b8605f9f1..cd11e917c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java @@ -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(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java index 9cd541916..8c5ef8cec 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/ODataLinkCollectionRequestImpl.java @@ -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(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java index 00a61ccda..41708b9b1 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/ODataDeltaRequestImpl.java @@ -74,7 +74,7 @@ public class ODataDeltaRequestImpl extends AbstractODataRetrieveRequest entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java index f06bed246..87a6fdbd2 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/streamed/ODataMediaEntityUpdateRequestImpl.java @@ -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 entity = (E) odataClient.getBinder().getODataEntity(resource); } catch (final ODataDeserializerException e) { - throw new HttpClientException(e); + throw new IllegalArgumentException(e); } finally { this.close(); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java index 5b0376b4c..1327e4354 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/AbstractODataBinder.java @@ -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) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java index d238a75b0..348d524f8 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v3/ODataDeserializerImpl.java @@ -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); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java index 0d3631a58..9151b741c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataBinderImpl.java @@ -279,15 +279,14 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder @Override public ODataProperty getODataProperty(final ResWrap 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; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java index 445db3923..61e6ac6ae 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/op/impl/v4/ODataDeserializerImpl.java @@ -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; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java index 2042a9a34..a0813eb9a 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v3/ODataClientImpl.java @@ -104,7 +104,7 @@ public class ODataClientImpl extends AbstractODataClient implements @Override public ODataDeserializer getDeserializer(final Format format) { - return new ODataDeserializerImpl(getServiceVersion(), format); + return new ODataDeserializerImpl(getServiceVersion(), false, format); } @Override diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java index 9f3835350..4907a0b44 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/v4/ODataClientImpl.java @@ -115,7 +115,7 @@ public class ODataClientImpl extends AbstractODataClient implements @Override public ODataDeserializer getDeserializer(final Format format) { - return new ODataDeserializerImpl(getServiceVersion(), format); + return new ODataDeserializerImpl(getServiceVersion(), false, format); } @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAnnotatedObject.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAnnotatedObject.java index 6383c8073..a265f5c97 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAnnotatedObject.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractAnnotatedObject.java @@ -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 annotations = new ArrayList(); @@ -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); + } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java index b3eb7f93b..e768417a4 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractODataObject.java @@ -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() { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPayloadObject.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPayloadObject.java deleted file mode 100644 index bad009d2d..000000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AbstractPayloadObject.java +++ /dev/null @@ -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); - } -} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java index e6a277eb4..626c00e48 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/AnnotationImpl.java @@ -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 diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java index 67ab03b6f..1e2930fde 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeletedEntityImpl.java @@ -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 diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java index 0834b55eb..7ed1de664 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/DeltaLinkImpl.java @@ -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 diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java index 28451a939..003c72d60 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntityImpl.java @@ -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 associationLinks = new ArrayList(); - private final List navigationLinks = new ArrayList(); - private final List mediaEditLinks = new ArrayList(); private final List operations = new ArrayList(); @@ -52,9 +47,7 @@ public class EntityImpl extends AbstractODataObject implements Entity { private final List properties = new ArrayList(); private URI mediaContentSource; - private String mediaContentType; - private String mediaETag; @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java index 192080970..3a985b423 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/EntitySetImpl.java @@ -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 entities = new ArrayList(); diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java new file mode 100755 index 000000000..1876b9c49 --- /dev/null +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JSONLinkCollectionDeserializer.java @@ -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 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((URI) null, null, links); + } + + public ResWrap 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); + } + } +} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java index e067d8870..bf1c19e0a 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/JsonSerializer.java @@ -102,7 +102,7 @@ public class JsonSerializer implements ODataSerializer { } else if (obj instanceof Entity) { new JSONEntitySerializer(version, serverMode).doContainerSerialize((ResWrap) container, json); } else if (obj instanceof Property) { - new JSONPropertySerializer(version, serverMode).doSerialize((Property) obj, json); + new JSONPropertySerializer(version, serverMode).doContainerSerialize((ResWrap) container, json); } else if (obj instanceof Link) { link((Link) obj, json); } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java index 85acc8f31..72e09cfa1 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/LinkImpl.java @@ -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 diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java index 9d9f35cf2..f98e85467 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/PropertyImpl.java @@ -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 diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java deleted file mode 100644 index edf871b2f..000000000 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/JSONLinkCollectionImpl.java +++ /dev/null @@ -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 links = new ArrayList(); - - @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 getLinks() { - final List result = new ArrayList(); - - 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); - } -} diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java index 33107239b..f62b4233b 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v3/LinkCollectionImpl.java @@ -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 links = new ArrayList(); private URI next; diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java index 021a77dfc..d507ebead 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/data/v4/DeltaImpl.java @@ -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 deletedEntities = new ArrayList(); - private final List addedLinks = new ArrayList(); - private final List deletedLinks = new ArrayList(); @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java index a2ef13414..548d79d03 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/op/AbstractODataDeserializer.java @@ -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); } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java index cf9f3f300..acea9f542 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java @@ -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 wrap = new ResWrap( - 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; - } -} +} \ No newline at end of file diff --git a/lib/server-tecsvc/pom.xml b/lib/server-tecsvc/pom.xml index 1371a0083..3925fbd94 100644 --- a/lib/server-tecsvc/pom.xml +++ b/lib/server-tecsvc/pom.xml @@ -121,6 +121,17 @@ runtime + + org.apache.olingo + olingo-commons-api + ${project.version} + + + org.apache.olingo + olingo-commons-core + ${project.version} + + org.slf4j slf4j-simple @@ -140,6 +151,11 @@ commons-io test + + org.apache.olingo + core + 0.1.0-SNAPSHOT + diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java index ec8a06101..9841dd8f9 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java @@ -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); } diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java new file mode 100644 index 000000000..66e863b69 --- /dev/null +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/SampleJsonProcessor.java @@ -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; + } + }