From fac8c0ae6f32ab7385a6002cba82bee207394232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Thu, 24 Apr 2014 11:36:07 +0200 Subject: [PATCH] Fixing (again) the build on windows --- .../apache/olingo/fit/AbstractServices.java | 35 +++++++------ .../olingo/fit/V3ActionOverloading.java | 4 +- .../org/apache/olingo/fit/V3KeyAsSegment.java | 5 +- .../org/apache/olingo/fit/V3OpenType.java | 4 +- .../org/apache/olingo/fit/V3Services.java | 8 +-- .../org/apache/olingo/fit/V4KeyAsSegment.java | 5 +- .../org/apache/olingo/fit/V4OpenType.java | 4 +- .../org/apache/olingo/fit/V4Services.java | 19 +++---- .../fit/utils/AbstractJSONUtilities.java | 38 +++++++------- .../olingo/fit/utils/AbstractUtilities.java | 5 +- .../fit/utils/AbstractXMLUtilities.java | 50 +++++++++---------- .../org/apache/olingo/fit/utils/Commons.java | 6 +-- 12 files changed, 95 insertions(+), 88 deletions(-) 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 ca2fd843c..8e888bdd1 100644 --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@ -413,10 +413,10 @@ public abstract class AbstractServices { throw new UnsupportedMediaTypeException("Unsupported media type"); } else if (contentTypeValue == Accept.ATOM) { entryChanges = atomDeserializer.read( - IOUtils.toInputStream(changes), AtomEntryImpl.class).getObject(); + IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntryImpl.class).getObject(); } else { - final Container jcont = - mapper.readValue(IOUtils.toInputStream(changes), new TypeReference() { + final Container jcont = mapper.readValue(IOUtils.toInputStream(changes, Constants.ENCODING), + new TypeReference() { }); entryChanges = dataBinder.toAtomEntry(jcont.getObject()); @@ -495,11 +495,11 @@ public abstract class AbstractServices { InputStream res; if (acceptType == Accept.ATOM) { - res = xml.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity), - getUtilities(acceptType).readEntry(acceptType, IOUtils.toInputStream(entity))); + res = xml.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity, Constants.ENCODING), + getUtilities(acceptType).readEntry(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING))); } else { - res = json.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity), - getUtilities(acceptType).readEntry(acceptType, IOUtils.toInputStream(entity))); + res = json.addOrReplaceEntity(entityId, entitySetName, IOUtils.toInputStream(entity, Constants.ENCODING), + getUtilities(acceptType).readEntry(acceptType, IOUtils.toInputStream(entity, Constants.ENCODING))); } final Container cres; @@ -579,7 +579,7 @@ public abstract class AbstractServices { entityKey = xml.getDefaultEntryKey(entitySetName, entry); - utils.addMediaEntityValue(entitySetName, entityKey, IOUtils.toInputStream(entity)); + utils.addMediaEntityValue(entitySetName, entityKey, IOUtils.toInputStream(entity, Constants.ENCODING)); final String id = Commons.getMediaContent().get(entitySetName); if (StringUtils.isNotBlank(id)) { @@ -602,12 +602,13 @@ public abstract class AbstractServices { } else { final Accept contentTypeValue = Accept.parse(contentType, version); if (Accept.ATOM == contentTypeValue) { - container = atomDeserializer.read(IOUtils.toInputStream(entity), AtomEntryImpl.class); + container = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntryImpl.class); entry = container.getObject(); } else { final Container jcontainer = - mapper.readValue(IOUtils.toInputStream(entity), new TypeReference() { - }); + mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING), + new TypeReference() { + }); entry = dataBinder.toAtomEntry(jcontainer.getObject()); @@ -700,7 +701,7 @@ public abstract class AbstractServices { replaceAll("\\.*\\", "[Sacked]"); final FSManager fsManager = FSManager.instance(version); - fsManager.putInMemory(IOUtils.toInputStream(newContent, "UTF-8"), + fsManager.putInMemory(IOUtils.toInputStream(newContent, Constants.ENCODING), fsManager.getAbsolutePath(Commons.getEntityBasePath("Person", entityId) + Constants.get(version, ConstantKey.ENTITY), utils.getKey())); @@ -759,7 +760,7 @@ public abstract class AbstractServices { "" + newSalary + ""); } - FSManager.instance(version).putInMemory(IOUtils.toInputStream(newContent, "UTF-8"), + FSManager.instance(version).putInMemory(IOUtils.toInputStream(newContent, Constants.ENCODING), FSManager.instance(version).getAbsolutePath(path.toString(), acceptType)); return xml.createResponse(null, null, null, acceptType, Response.Status.NO_CONTENT); @@ -1150,7 +1151,7 @@ public abstract class AbstractServices { final InputStream changed = utils.replaceProperty( entitySetName, entityId, - IOUtils.toInputStream(changes), + IOUtils.toInputStream(changes, Constants.ENCODING), Arrays.asList(path.split("/")), acceptType, justValue); @@ -1306,7 +1307,8 @@ public abstract class AbstractServices { final AbstractUtilities utils = getUtilities(null); - final InputStream res = utils.putMediaInMemory(entitySetName, entityId, IOUtils.toInputStream(value)); + final InputStream res = utils.putMediaInMemory( + entitySetName, entityId, IOUtils.toInputStream(value, Constants.ENCODING)); final String location = uriInfo.getRequestUri().toASCIIString().replace("/$value", ""); @@ -1367,7 +1369,8 @@ public abstract class AbstractServices { try { final AbstractUtilities utils = getUtilities(null); - InputStream res = utils.putMediaInMemory(entitySetName, entityId, path, IOUtils.toInputStream(value)); + InputStream res = utils.putMediaInMemory( + entitySetName, entityId, path, IOUtils.toInputStream(value, Constants.ENCODING)); final Response response; if ("return-content".equalsIgnoreCase(prefer)) { diff --git a/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java b/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java index 6ddb502fc..974014b27 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3ActionOverloading.java @@ -61,7 +61,7 @@ public class V3ActionOverloading extends AbstractServices { private Response replaceServiceName(final Response response) { try { - final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8"). + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). replaceAll("Static\\.svc", "ActionOverloading.svc"); final Response.ResponseBuilder builder = status(response.getStatus()); @@ -71,7 +71,7 @@ public class V3ActionOverloading extends AbstractServices { } } - final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8"); + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); diff --git a/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java b/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java index da4a7db6a..35db43ed0 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3KeyAsSegment.java @@ -40,6 +40,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.fit.methods.MERGE; import org.apache.olingo.fit.methods.PATCH; +import org.apache.olingo.fit.utils.Constants; import org.springframework.stereotype.Service; @Service @@ -54,7 +55,7 @@ public class V3KeyAsSegment { private Response replaceServiceName(final Response response) { try { - final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8"). + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). replaceAll("Static\\.svc", "KeyAsSegment.svc"); final Response.ResponseBuilder builder = Response.status(response.getStatus()); @@ -64,7 +65,7 @@ public class V3KeyAsSegment { } } - final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8"); + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); diff --git a/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java b/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java index 18f5075b1..43e1201b8 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3OpenType.java @@ -72,7 +72,7 @@ public class V3OpenType { private Response replaceServiceName(final Response response) { try { - final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8"). + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). replaceAll("Static\\.svc", "OpenType.svc"); final Response.ResponseBuilder builder = Response.status(response.getStatus()); @@ -82,7 +82,7 @@ public class V3OpenType { } } - final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8"); + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); diff --git a/fit/src/main/java/org/apache/olingo/fit/V3Services.java b/fit/src/main/java/org/apache/olingo/fit/V3Services.java index a946b0df8..66b1150c1 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V3Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V3Services.java @@ -275,9 +275,9 @@ public class V3Services extends AbstractServices { final List links; if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) { - links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue(); + links = xml.extractLinkURIs(IOUtils.toInputStream(link, Constants.ENCODING)).getValue(); } else { - links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue(); + links = json.extractLinkURIs(IOUtils.toInputStream(link, Constants.ENCODING)).getValue(); } utils.putLinksInMemory( @@ -352,9 +352,9 @@ public class V3Services extends AbstractServices { final List links; if (content == Accept.XML || content == Accept.TEXT || content == Accept.ATOM) { - links = xml.extractLinkURIs(IOUtils.toInputStream(link)).getValue(); + links = xml.extractLinkURIs(IOUtils.toInputStream(link, Constants.ENCODING)).getValue(); } else { - links = json.extractLinkURIs(IOUtils.toInputStream(link)).getValue(); + links = json.extractLinkURIs(IOUtils.toInputStream(link, Constants.ENCODING)).getValue(); } utils.putLinksInMemory( diff --git a/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java b/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java index ca46ef25d..fa0657092 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4KeyAsSegment.java @@ -39,6 +39,7 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.fit.methods.PATCH; +import org.apache.olingo.fit.utils.Constants; import org.springframework.stereotype.Service; @Service @@ -53,7 +54,7 @@ public class V4KeyAsSegment { private Response replaceServiceName(final Response response) { try { - final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8"). + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). replaceAll("Static\\.svc", "KeyAsSegment.svc"); final Response.ResponseBuilder builder = Response.status(response.getStatus()); @@ -63,7 +64,7 @@ public class V4KeyAsSegment { } } - final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8"); + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); diff --git a/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java b/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java index 748a614a7..c9690f4bd 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4OpenType.java @@ -67,7 +67,7 @@ public class V4OpenType { private Response replaceServiceName(final Response response) { try { - final String content = IOUtils.toString((InputStream) response.getEntity(), "UTF-8"). + final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING). replaceAll("Static\\.svc", "OpenType.svc"); final Response.ResponseBuilder builder = Response.status(response.getStatus()); @@ -77,7 +77,7 @@ public class V4OpenType { } } - final InputStream toBeStreamedBack = IOUtils.toInputStream(content, "UTF-8"); + final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); 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 5b51a9fc9..3a8459ad3 100644 --- a/fit/src/main/java/org/apache/olingo/fit/V4Services.java +++ b/fit/src/main/java/org/apache/olingo/fit/V4Services.java @@ -106,7 +106,7 @@ public class V4Services extends AbstractServices { if (!providedAsync.containsKey(name)) { throw new NotFoundException(); } - final InputStream res = IOUtils.toInputStream(providedAsync.get(name)); + final InputStream res = IOUtils.toInputStream(providedAsync.get(name), Constants.ENCODING); providedAsync.remove(name); return xml.createMonitorResponse(res); } catch (Exception e) { @@ -304,7 +304,7 @@ public class V4Services extends AbstractServices { final Accept contentTypeValue = Accept.parse(contentType, version); final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); - + return xml.createResponse( null, xml.writeProperty(acceptType, entry.getProperty("IncreaseValue")), @@ -444,7 +444,7 @@ public class V4Services extends AbstractServices { try { final Accept contentTypeValue = Accept.parse(contentType, version); final Entry entry = xml.readEntry(contentTypeValue, IOUtils.toInputStream(param, Constants.ENCODING)); - + assert 1 == entry.getProperties().size(); assert entry.getProperty("newDate") != null; @@ -645,12 +645,13 @@ public class V4Services extends AbstractServices { final AtomEntryImpl entry; final Accept contentTypeValue = Accept.parse(contentType, version); if (Accept.ATOM == contentTypeValue) { - entryContainer = atomDeserializer.read(IOUtils.toInputStream(entity), AtomEntryImpl.class); + entryContainer = atomDeserializer.read(IOUtils.toInputStream(entity, Constants.ENCODING), AtomEntryImpl.class); entry = entryContainer.getObject(); } else { final Container jcontainer = - mapper.readValue(IOUtils.toInputStream(entity), new TypeReference() { - }); + mapper.readValue(IOUtils.toInputStream(entity, Constants.ENCODING), + new TypeReference() { + }); entry = dataBinder.toAtomEntry(jcontainer.getObject()); @@ -738,7 +739,7 @@ public class V4Services extends AbstractServices { final AtomEntryImpl entryChanges; if (Accept.ATOM == contentTypeValue) { - container = atomDeserializer.read(IOUtils.toInputStream(changes), AtomEntryImpl.class); + container = atomDeserializer.read(IOUtils.toInputStream(changes, Constants.ENCODING), AtomEntryImpl.class); entryChanges = container.getObject(); } else { final String entityType = getMetadataObj().getEntitySet(entitySetName).getType(); @@ -746,8 +747,8 @@ public class V4Services extends AbstractServices { getNavigationProperty(containedEntitySetName).getType(); final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(containedType).build(); - final Container jsonContainer = mapper.readValue(IOUtils.toInputStream(changes), - new TypeReference() { + final Container jsonContainer = mapper.readValue( + IOUtils.toInputStream(changes, Constants.ENCODING), new TypeReference() { }); jsonContainer.getObject().setType(typeInfo.getFullQualifiedName().toString()); entryChanges = dataBinder.toAtomEntry(jsonContainer.getObject()); diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractJSONUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractJSONUtilities.java index 369d6576d..b0493d219 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractJSONUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractJSONUtilities.java @@ -57,7 +57,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { protected InputStream addLinks( final String entitySetName, final String entitykey, final InputStream is, final Set links) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is); @@ -71,7 +71,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { @Override protected Set retrieveAllLinkNames(InputStream is) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is); @@ -101,7 +101,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { protected NavigationLinks retrieveNavigationInfo(final String entitySetName, final InputStream is) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is); @@ -144,7 +144,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { final String entitySetName, final String entityKey, final InputStream is, final NavigationLinks links) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); if (links != null) { @@ -175,16 +175,16 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { Constants.get(version, ConstantKey.JSON_EDITLINK_NAME), new TextNode( Constants.get(version, ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")")); - return IOUtils.toInputStream(srcNode.toString(), "UTF-8"); + return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); } @Override public InputStream getPropertyValue(final InputStream src, final List path) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final JsonNode srcNode = mapper.readTree(src); final JsonNode node = getProperty(srcNode, path); - return IOUtils.toInputStream(node.asText()); + return IOUtils.toInputStream(node.asText(), Constants.ENCODING); } @Override @@ -196,7 +196,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { Commons.getEntityBasePath(entitySetName, entityId) + Constants.get(version, ConstantKey.ENTITY), Accept.JSON_FULLMETA); - final ObjectMapper mapper = new ObjectMapper(); + final JsonNode srcNode = mapper.readTree(src); final ObjectNode propertyNode = new ObjectNode(JsonNodeFactory.instance); @@ -243,7 +243,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { public InputStream addJsonInlinecount( final InputStream src, final int count, final Accept accept) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final JsonNode srcNode = mapper.readTree(src); ((ObjectNode) srcNode).put(Constants.get(version, ConstantKey.ODATA_COUNT_NAME), count); @@ -258,7 +258,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { } public InputStream wrapJsonEntities(final InputStream entities) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(entities); final ObjectNode res; @@ -287,7 +287,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { @Override public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); final Set retain = new HashSet(); @@ -319,7 +319,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { throw new NotFoundException(); } - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode node = mapper.createObjectNode(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -363,7 +363,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { protected InputStream replaceLink( final InputStream toBeChanged, final String linkName, final InputStream replacement) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode toBeChangedNode = (ObjectNode) mapper.readTree(toBeChanged); final ObjectNode replacementNode = (ObjectNode) mapper.readTree(replacement); @@ -386,7 +386,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { protected Map getChanges(final InputStream src) throws Exception { final Map res = new HashMap(); - final ObjectMapper mapper = new ObjectMapper(); + final JsonNode srcObject = mapper.readTree(src); final Iterator> fields = srcObject.fields(); @@ -409,7 +409,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { @Override public Map.Entry> extractLinkURIs(final InputStream is) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is); @@ -436,7 +436,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { @Override public InputStream addEditLink( final InputStream content, final String title, final String href) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(content); IOUtils.closeQuietly(content); @@ -448,7 +448,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { public InputStream addOperation(final InputStream content, final String name, final String metaAnchor, final String href) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(content); IOUtils.closeQuietly(content); @@ -464,7 +464,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { public InputStream replaceProperty( final InputStream src, final InputStream replacement, final List path, final boolean justValue) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); IOUtils.closeQuietly(src); @@ -491,7 +491,7 @@ public abstract class AbstractJSONUtilities extends AbstractUtilities { @Override public InputStream deleteProperty(final InputStream src, final List path) throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); IOUtils.closeQuietly(src); 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 804c7c2fb..ab8ed81f6 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 @@ -386,7 +386,7 @@ public abstract class AbstractUtilities { + ""; fsManager.putInMemory( - IOUtils.toInputStream(entity), + IOUtils.toInputStream(entity, Constants.ENCODING), fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), Accept.ATOM)); // ----------------------------------------- @@ -406,7 +406,8 @@ public abstract class AbstractUtilities { + "\"Description\": null" + "}"; fsManager.putInMemory( - IOUtils.toInputStream(entity), fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), + IOUtils.toInputStream(entity, Constants.ENCODING), + fsManager.getAbsolutePath(path + Constants.get(version, ConstantKey.ENTITY), Accept.JSON_FULLMETA)); // ----------------------------------------- diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractXMLUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractXMLUtilities.java index 2e6ba7a4c..ea18750c1 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractXMLUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractXMLUtilities.java @@ -196,7 +196,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { while (true) { final Map.Entry linkInfo = extractElement(reader, null, - Collections.singletonList(Constants.get(version, ConstantKey.LINK)), startDepth, 2, 2); + Collections.singletonList(Constants.get(version, ConstantKey.LINK)), startDepth, 2, 2); startDepth = linkInfo.getKey(); @@ -247,7 +247,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { try { final XmlElement inlineElement = extractElement(link.getContentReader(), null, - Collections.singletonList(Constants.get(version, ConstantKey.INLINE)), 0, -1, -1). + Collections.singletonList(Constants.get(version, ConstantKey.INLINE)), 0, -1, -1). getValue(); final XMLEventReader inlineReader = inlineElement.getContentReader(); @@ -334,7 +334,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { title, link.getStart().getAttributeByName(new QName("type")).getValue()); - addAtomElement(IOUtils.toInputStream(normalizedLink), writer); + addAtomElement(IOUtils.toInputStream(normalizedLink, Constants.ENCODING), writer); } } } catch (Exception ignore) { @@ -451,9 +451,9 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { // check edit link existence extractElement(reader, writer, Collections.singletonList(Constants.get(version, ConstantKey.LINK)), Collections.>singletonList( - new AbstractMap.SimpleEntry("rel", "edit")), false, 0, -1, -1); + new AbstractMap.SimpleEntry("rel", "edit")), false, 0, -1, -1); - addAtomElement(IOUtils.toInputStream(editLinkElement), writer); + addAtomElement(IOUtils.toInputStream(editLinkElement, Constants.ENCODING), writer); writer.add(reader); } catch (Exception e) { @@ -468,7 +468,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { writer.add(entryElement.getStart()); - addAtomElement(IOUtils.toInputStream(editLinkElement), writer); + addAtomElement(IOUtils.toInputStream(editLinkElement, Constants.ENCODING), writer); writer.add(entryElement.getContentReader()); writer.add(entryElement.getEnd()); @@ -544,7 +544,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { try { final XmlElement entryElement = extractElement(reader, writer, Collections.singletonList( - Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3).getValue(); + Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3).getValue(); addAtomElement( IOUtils.toInputStream(""), @@ -741,7 +741,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { extractElement(reader, writer, Collections.singletonList("feed"), 0, 1, 1).getValue(); writer.add(feedElement.getStart()); - addAtomElement(IOUtils.toInputStream(String.format("%d", count)), writer); + addAtomElement(IOUtils.toInputStream(String.format("%d", count), Constants.ENCODING), writer); writer.add(feedElement.getContentReader()); writer.add(feedElement.getEnd()); @@ -799,7 +799,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { if (event.getEventType() == XMLStreamConstants.START_ELEMENT && Constants.get(version, ConstantKey.LINK).equals(event.asStartElement().getName().getLocalPart()) && !fieldToBeSaved.contains( - event.asStartElement().getAttributeByName(new QName("title")).getValue()) + event.asStartElement().getAttributeByName(new QName("title")).getValue()) && !"edit".equals(event.asStartElement().getAttributeByName(new QName("rel")).getValue())) { writeCurrent = false; } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT @@ -807,13 +807,13 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { writeNext = true; } else if (event.getEventType() == XMLStreamConstants.START_ELEMENT && (Constants.get(version, ConstantKey.PROPERTIES)).equals( - event.asStartElement().getName().getLocalPart())) { + event.asStartElement().getName().getLocalPart())) { writeCurrent = true; writeNext = false; inProperties = true; } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT && (Constants.get(version, ConstantKey.PROPERTIES)).equals( - event.asEndElement().getName().getLocalPart())) { + event.asEndElement().getName().getLocalPart())) { writeCurrent = true; } else if (inProperties) { if (event.getEventType() == XMLStreamConstants.START_ELEMENT) { @@ -830,7 +830,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { } else if (event.getEventType() == XMLStreamConstants.END_ELEMENT && StringUtils.isNotBlank(currentName) && (Constants.get(version, ConstantKey.ATOM_PROPERTY_PREFIX) + currentName.trim()).equals( - event.asEndElement().getName().getLocalPart())) { + event.asEndElement().getName().getLocalPart())) { writeNext = false; currentName = null; } @@ -898,10 +898,10 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { final XmlElement entry = extractElement( - getEventReader(readEntity(uri.getKey(), uri.getValue(), Accept.ATOM).getValue()), - null, - Collections.singletonList("entry"), - 0, 1, 1).getValue(); + getEventReader(readEntity(uri.getKey(), uri.getValue(), Accept.ATOM).getValue()), + null, + Collections.singletonList("entry"), + 0, 1, 1).getValue(); IOUtils.copy(entry.toStream(), writer, encoding); } catch (Exception e) { @@ -938,7 +938,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { final Map.Entry propertyElement = extractElement(reader, null, - Collections.singletonList(Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3); + Collections.singletonList(Constants.get(version, ConstantKey.PROPERTIES)), 0, 2, 3); reader.close(); reader = propertyElement.getValue().getContentReader(); @@ -962,7 +962,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { while (true) { final Map.Entry linkElement = extractElement(reader, null, - Collections.singletonList(Constants.get(version, ConstantKey.LINK)), pos, 2, 2); + Collections.singletonList(Constants.get(version, ConstantKey.LINK)), pos, 2, 2); res.put("[Constants.get(version, ConstantKey.LINK)]" + linkElement.getValue().getStart().getAttributeByName(new QName("title")).getValue(), @@ -992,9 +992,9 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { try { final XmlElement linkElement = extractElement(reader, writer, - Collections.singletonList(Constants.get(version, ConstantKey.LINK)), - Collections.>singletonList( - new SimpleEntry("title", linkName)), false, 0, -1, -1).getValue(); + Collections.singletonList(Constants.get(version, ConstantKey.LINK)), + Collections.>singletonList( + new SimpleEntry("title", linkName)), false, 0, -1, -1).getValue(); writer.add(linkElement.getStart()); // ------------------------------------------ @@ -1054,7 +1054,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { public Map.Entry> extractLinkURIs( final String entitySetName, final String entityId, final String linkName) throws Exception { - + final LinkInfo links = readLinks(entitySetName, entityId, linkName, Accept.XML); return extractLinkURIs(links.getLinks()); } @@ -1106,7 +1106,7 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { final InputStream src = fsManager.readFile(Commons.getEntityBasePath(entitySetName, entityId) - + Constants.get(version, ConstantKey.ENTITY), Accept.XML); + + Constants.get(version, ConstantKey.ENTITY), Accept.XML); final XMLEventReader reader = getEventReader(src); final XmlElement property = extractElement(reader, null, pathElements, 0, 3, 4).getValue(); @@ -1211,8 +1211,8 @@ public abstract class AbstractXMLUtilities extends AbstractUtilities { final Map.Entry element = extractElement(reader, writer, pathElements, 0, 3, 4); - final XMLEventReader changesReader = new XMLEventReaderWrapper( - IOUtils.toInputStream(String.format("<%s m:null=\"true\" />", path.get(path.size() - 1)))); + final XMLEventReader changesReader = new XMLEventReaderWrapper(IOUtils.toInputStream( + String.format("<%s m:null=\"true\" />", path.get(path.size() - 1)), Constants.ENCODING)); writer.add(changesReader); changesReader.close(); 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 5d35bdc76..af15f2d2f 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 @@ -222,7 +222,7 @@ public abstract class Commons { builder.append(""); - return IOUtils.toInputStream(builder.toString()); + return IOUtils.toInputStream(builder.toString(), Constants.ENCODING); } public static InputStream getLinksAsJSON(final ODataServiceVersion version, @@ -252,7 +252,7 @@ public abstract class Commons { links.set("value", uris); } - return IOUtils.toInputStream(links.toString(), "UTF-8"); + return IOUtils.toInputStream(links.toString(), Constants.ENCODING); } public static InputStream changeFormat(final InputStream is, final ODataServiceVersion version, final Accept target) { @@ -266,7 +266,7 @@ public abstract class Commons { final JsonNode node = changeFormat((ObjectNode) mapper.readTree(new ByteArrayInputStream(bos.toByteArray())), version, target); - return IOUtils.toInputStream(node.toString(), "UTF-8"); + return IOUtils.toInputStream(node.toString(), Constants.ENCODING); } catch (Exception e) { LOG.error("Error changing format", e); return new ByteArrayInputStream(bos.toByteArray());