[OLINGO-200] V3 Atom and JSON (de)serializers replaced are now DOM free - all tests succeed
This commit is contained in:
commit
4431a80db5
|
@ -423,6 +423,7 @@ public abstract class AbstractUtilities {
|
|||
|
||||
public Response createFaultResponse(final String accept, final Exception e) {
|
||||
LOG.debug("Create fault response about .... ", e);
|
||||
e.printStackTrace();
|
||||
|
||||
final Response.ResponseBuilder builder = Response.serverError();
|
||||
if (version == ODataVersion.v3) {
|
||||
|
|
|
@ -84,7 +84,7 @@ public class FSManager {
|
|||
IOUtils.copy(is, os);
|
||||
IOUtils.closeQuietly(is);
|
||||
IOUtils.closeQuietly(os);
|
||||
|
||||
|
||||
return memObject;
|
||||
}
|
||||
|
||||
|
|
|
@ -319,7 +319,9 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
startDepth = linkInfo.getKey();
|
||||
|
||||
final String title = link.getStart().getAttributeByName(new QName("title")).getValue();
|
||||
final String href = link.getStart().getAttributeByName(new QName("href")).getValue();
|
||||
|
||||
final Attribute hrefAttr = link.getStart().getAttributeByName(new QName("href"));
|
||||
final String href = hrefAttr == null ? null : hrefAttr.getValue();
|
||||
|
||||
try {
|
||||
final XmlElement inlineElement =
|
||||
|
@ -341,7 +343,7 @@ public class XMLUtilities extends AbstractUtilities {
|
|||
inlineReader.close();
|
||||
} catch (Exception ignore) {
|
||||
// inline element not found (inlines are not mondatory).
|
||||
if (entityUriPattern.matcher(href).matches()) {
|
||||
if (StringUtils.isNotBlank(href) && entityUriPattern.matcher(href).matches()) {
|
||||
links.addLinks(title, href.substring(href.lastIndexOf('/') + 1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,6 +147,8 @@ public class Constants {
|
|||
|
||||
public static final String ELEM_PROPERTY = "property";
|
||||
|
||||
public static final String ELEM_LINKS = "links";
|
||||
|
||||
public static final String ELEM_URI = "uri";
|
||||
|
||||
// JSON stuff
|
||||
|
|
|
@ -48,6 +48,9 @@ abstract class AbstractAtomDealer {
|
|||
|
||||
protected final QName countQName;
|
||||
|
||||
protected final QName uriQName;
|
||||
protected final QName nextQName;
|
||||
|
||||
public AbstractAtomDealer(final ODataServiceVersion version) {
|
||||
this.version = version;
|
||||
|
||||
|
@ -65,6 +68,10 @@ abstract class AbstractAtomDealer {
|
|||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_ELEMENT);
|
||||
this.countQName =
|
||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_METADATA), Constants.ATOM_ELEM_COUNT);
|
||||
this.uriQName =
|
||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_URI);
|
||||
this.nextQName =
|
||||
new QName(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.NEXT_LINK_REL);
|
||||
}
|
||||
|
||||
protected void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
|
||||
|
|
|
@ -122,6 +122,34 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
|||
}
|
||||
}
|
||||
|
||||
private XMLLinkCollectionImpl linkCollection(final InputStream input) throws XMLStreamException {
|
||||
final XMLEventReader reader = FACTORY.createXMLEventReader(input);
|
||||
|
||||
final XMLLinkCollectionImpl linkCollection = new XMLLinkCollectionImpl();
|
||||
|
||||
boolean isURI = false;
|
||||
boolean isNext = false;
|
||||
while (reader.hasNext()) {
|
||||
final XMLEvent event = reader.nextEvent();
|
||||
if (event.isStartElement()) {
|
||||
isURI = uriQName.equals(event.asStartElement().getName());
|
||||
isNext = nextQName.equals(event.asStartElement().getName());
|
||||
}
|
||||
|
||||
if (event.isCharacters() && !event.asCharacters().isWhiteSpace()) {
|
||||
if (isURI) {
|
||||
linkCollection.getLinks().add(URI.create(event.asCharacters().getData()));
|
||||
isURI = false;
|
||||
} else if (isNext) {
|
||||
linkCollection.setNext(URI.create(event.asCharacters().getData()));
|
||||
isNext = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return linkCollection;
|
||||
}
|
||||
|
||||
private void properties(final XMLEventReader reader, final StartElement start, final AtomEntryImpl entry)
|
||||
throws XMLStreamException {
|
||||
|
||||
|
@ -333,6 +361,8 @@ public class AtomDeserializer extends AbstractAtomDealer {
|
|||
return (T) entry(input);
|
||||
} else if (AtomPropertyImpl.class.equals(reference)) {
|
||||
return (T) property(input);
|
||||
} else if (XMLLinkCollectionImpl.class.equals(reference)) {
|
||||
return (T) linkCollection(input);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -236,13 +236,16 @@ public class AtomSerializer extends AbstractAtomDealer {
|
|||
final XMLStreamWriter writer = FACTORY.createXMLStreamWriter(outWriter);
|
||||
|
||||
writer.writeStartDocument();
|
||||
writer.writeNamespace(
|
||||
Constants.PREFIX_DATASERVICES, version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
|
||||
|
||||
writer.writeStartElement(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES), Constants.ELEM_URI);
|
||||
writer.writeStartElement(Constants.ELEM_LINKS);
|
||||
writer.writeDefaultNamespace(version.getNamespaceMap().get(ODataServiceVersion.NS_DATASERVICES));
|
||||
|
||||
writer.writeStartElement(Constants.ELEM_URI);
|
||||
writer.writeCharacters(link.getHref());
|
||||
writer.writeEndElement();
|
||||
|
||||
writer.writeEndElement();
|
||||
|
||||
writer.writeEndDocument();
|
||||
writer.flush();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.olingo.client.api.Constants;
|
||||
import org.apache.olingo.client.api.data.Entry;
|
||||
import org.apache.olingo.client.api.data.Link;
|
||||
|
@ -70,7 +71,9 @@ public class JSONEntrySerializer extends AbstractJsonSerializer<JSONEntryImpl> {
|
|||
}
|
||||
uris.add(link.getHref());
|
||||
} else {
|
||||
jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
|
||||
if (StringUtils.isNotBlank(link.getHref())) {
|
||||
jgen.writeStringField(link.getTitle() + Constants.JSON_BIND_LINK_SUFFIX, link.getHref());
|
||||
}
|
||||
}
|
||||
|
||||
if (link.getInlineEntry() != null) {
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.apache.olingo.client.core.data;
|
|||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
@ -63,20 +62,8 @@ public class JSONPropertyDeserializer extends AbstractJsonDeserializer<JSONPrope
|
|||
property.setValue(new NullValueImpl());
|
||||
}
|
||||
|
||||
JsonNode subtree = null;
|
||||
if (tree.has(Constants.JSON_VALUE)) {
|
||||
final JsonNode value = tree.get(Constants.JSON_VALUE);
|
||||
if (value.isValueNode()) {
|
||||
property.setValue(new PrimitiveValueImpl(value.asText()));
|
||||
} else {
|
||||
subtree = tree.get(Constants.JSON_VALUE);
|
||||
}
|
||||
} else {
|
||||
subtree = tree;
|
||||
}
|
||||
|
||||
if (property.getValue() == null && subtree != null) {
|
||||
value(property, subtree);
|
||||
if (property.getValue() == null) {
|
||||
value(property, tree.has(Constants.JSON_VALUE) ? tree.get(Constants.JSON_VALUE) : tree);
|
||||
}
|
||||
|
||||
return property;
|
||||
|
|
|
@ -136,7 +136,7 @@ public abstract class AbstractODataBinder implements ODataBinder {
|
|||
entrySelfLink.setRel(Constants.SELF_LINK_REL);
|
||||
entry.setSelfLink(entrySelfLink);
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Append navigation links (handling inline entry / feed as well)
|
||||
|
@ -148,7 +148,7 @@ public abstract class AbstractODataBinder implements ODataBinder {
|
|||
entry.getNavigationLinks().add(getLink(link,
|
||||
ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Append edit-media links
|
||||
|
@ -158,7 +158,7 @@ public abstract class AbstractODataBinder implements ODataBinder {
|
|||
entry.getMediaEditLinks().add(getLink(link,
|
||||
ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// Append association links
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
*/
|
||||
package org.apache.olingo.client.core.op.impl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.client.api.ODataClient;
|
||||
import org.apache.olingo.client.api.data.Entry;
|
||||
import org.apache.olingo.client.api.data.Error;
|
||||
|
@ -78,7 +76,7 @@ public abstract class AbstractODataDeserializer extends AbstractJacksonTool impl
|
|||
@Override
|
||||
public LinkCollection toLinkCollection(final InputStream input, final ODataFormat format) {
|
||||
return format == ODataFormat.XML
|
||||
? xml(input, XMLLinkCollectionImpl.class)
|
||||
? atom(input, XMLLinkCollectionImpl.class)
|
||||
: json(input, JSONLinkCollectionImpl.class);
|
||||
}
|
||||
|
||||
|
@ -110,10 +108,7 @@ public abstract class AbstractODataDeserializer extends AbstractJacksonTool impl
|
|||
|
||||
protected <T> T json(final InputStream input, final Class<T> reference) {
|
||||
try {
|
||||
String maz = IOUtils.toString(input);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(maz.getBytes());
|
||||
System.out.println("KKKKKKKKKKKKKKKKKK\n" + maz);
|
||||
return getObjectMapper().readValue(bais, reference);
|
||||
return getObjectMapper().readValue(input, reference);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("While deserializing " + reference.getName(), e);
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ public abstract class AbstractTestITCase {
|
|||
|
||||
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Information",
|
||||
getClient().getPrimitiveValueBuilder().setText(sampleinfo).setType(
|
||||
ODataJClientEdmPrimitiveType.String).build()));
|
||||
ODataJClientEdmPrimitiveType.String).build()));
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
@ -228,12 +228,12 @@ public abstract class AbstractTestITCase {
|
|||
// add name attribute
|
||||
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
|
||||
getClient().getPrimitiveValueBuilder().setText(sampleName).setType(
|
||||
ODataJClientEdmPrimitiveType.String).build()));
|
||||
ODataJClientEdmPrimitiveType.String).build()));
|
||||
|
||||
// add key attribute
|
||||
entity.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
|
||||
getClient().getPrimitiveValueBuilder().setText(String.valueOf(id)).setType(
|
||||
ODataJClientEdmPrimitiveType.Int32).build()));
|
||||
ODataJClientEdmPrimitiveType.Int32).build()));
|
||||
|
||||
// add BackupContactInfo attribute (collection)
|
||||
final ODataCollectionValue backupContactInfoValue = new ODataCollectionValue(
|
||||
|
|
Loading…
Reference in New Issue