[OLINGO-750] Fixed some critical issues

This commit is contained in:
mibo 2015-09-10 21:10:01 +02:00
parent 524dbebc4a
commit 637ca00db7
5 changed files with 25 additions and 37 deletions

View File

@ -21,6 +21,7 @@ package org.apache.olingo.client.core.communication.request;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.util.Arrays;
import org.apache.olingo.client.api.communication.request.ODataStreamer; import org.apache.olingo.client.api.communication.request.ODataStreamer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -87,7 +88,7 @@ public abstract class AbstractODataStreamer implements ODataStreamer {
public Writer(final byte[] src, final OutputStream os) { public Writer(final byte[] src, final OutputStream os) {
this.os = os; this.os = os;
this.src = src; this.src = Arrays.copyOf(src, src.length);
} }
@Override @Override

View File

@ -61,8 +61,6 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64; import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle; import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* URI utilities. * URI utilities.
@ -72,7 +70,7 @@ public final class URIUtils {
/** /**
* Logger. * Logger.
*/ */
private static final Logger LOG = LoggerFactory.getLogger(URIUtils.class); // private static final Logger LOG = LoggerFactory.getLogger(URIUtils.class);
private static final Pattern ENUM_VALUE = Pattern.compile("(.+\\.)?.+'.+'"); private static final Pattern ENUM_VALUE = Pattern.compile("(.+\\.)?.+'.+'");
@ -262,12 +260,7 @@ public final class URIUtils {
: obj.toString(); : obj.toString();
} }
} catch (Exception e) { } catch (Exception e) {
LOG.warn("While escaping '{}', using getName()", obj, e); value = obj.toString();
if (obj == null) {
value = "null";
} else {
value = obj.toString();
}
} }
return value; return value;
@ -298,7 +291,7 @@ public final class URIUtils {
bytes = IOUtils.toByteArray(input); bytes = IOUtils.toByteArray(input);
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
} catch (IOException e) { } catch (IOException e) {
LOG.error("While reading input for not chunked encoding", e); throw new RuntimeException("While reading input for not chunked encoding", e);
} }
entity = new ByteArrayEntity(bytes); entity = new ByteArrayEntity(bytes);
@ -307,7 +300,6 @@ public final class URIUtils {
} }
if (!useChunked && entity.getContentLength() < 0) { if (!useChunked && entity.getContentLength() < 0) {
LOG.error("Could not determine length - request will be sent as chunked.");
useChunked = true; useChunked = true;
} }
// both entities can be sent in chunked way or not // both entities can be sent in chunked way or not

View File

@ -20,7 +20,7 @@ package org.apache.olingo.server.core;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
@ -33,6 +33,7 @@ import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlAction;
import org.apache.olingo.commons.api.edm.provider.CsdlActionImport; import org.apache.olingo.commons.api.edm.provider.CsdlActionImport;
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
@ -74,7 +75,7 @@ public class MetadataParser {
void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider, void build(XMLEventReader reader, StartElement element, SchemaBasedEdmProvider provider,
String name) throws XMLStreamException { String name) throws XMLStreamException {
String version = attr(element, "Version"); String version = attr(element, "Version");
if (version.equals("4.0")) { if ("4.0".equals(version)) {
readDataServicesAndReference(reader, element, provider); readDataServicesAndReference(reader, element, provider);
} }
} }
@ -140,10 +141,9 @@ public class MetadataParser {
throws XMLStreamException { throws XMLStreamException {
if (name.equals("Action")) { if (name.equals("Action")) {
readAction(reader, element, schema); readAction(reader, element, schema);
} else if (name.equals("Annotations")) { // } else if (name.equals("Annotations")) {
// TODO: // } else if (name.equals("Annotation")) {
} else if (name.equals("Annotation")) { // TODO: Add support for annotations
// TODO:
} else if (name.equals("ComplexType")) { } else if (name.equals("ComplexType")) {
readComplexType(reader, element, schema); readComplexType(reader, element, schema);
} else if (name.equals("EntityContainer")) { } else if (name.equals("EntityContainer")) {
@ -182,7 +182,7 @@ public class MetadataParser {
private FullQualifiedName readType(StartElement element) { private FullQualifiedName readType(StartElement element) {
String type = attr(element, "Type"); String type = attr(element, "Type");
if (type.startsWith("Collection(") && type.endsWith(")")) { if (type != null && type.startsWith("Collection(") && type.endsWith(")")) {
return new FullQualifiedName(type.substring(11, type.length() - 1)); return new FullQualifiedName(type.substring(11, type.length() - 1));
} }
return new FullQualifiedName(type); return new FullQualifiedName(type);
@ -190,7 +190,7 @@ public class MetadataParser {
private boolean isCollectionType(StartElement element) { private boolean isCollectionType(StartElement element) {
String type = attr(element, "Type"); String type = attr(element, "Type");
if (type.startsWith("Collection(") && type.endsWith(")")) { if (type != null && type.startsWith("Collection(") && type.endsWith(")")) {
return true; return true;
} }
return false; return false;
@ -217,6 +217,7 @@ public class MetadataParser {
String srid = attr(element, "SRID"); String srid = attr(element, "SRID");
if (srid != null) { if (srid != null) {
// TODO: no olingo support yet. // TODO: no olingo support yet.
returnType.setSrid(SRID.valueOf(srid));
} }
operation.setReturnType(returnType); operation.setReturnType(returnType);
} }
@ -243,6 +244,7 @@ public class MetadataParser {
String srid = attr(element, "SRID"); String srid = attr(element, "SRID");
if (srid != null) { if (srid != null) {
// TODO: no olingo support yet. // TODO: no olingo support yet.
parameter.setSrid(SRID.valueOf(srid));
} }
operation.getParameters().add(parameter); operation.getParameters().add(parameter);
} }
@ -268,6 +270,7 @@ public class MetadataParser {
String srid = attr(element, "SRID"); String srid = attr(element, "SRID");
if (srid != null) { if (srid != null) {
// TODO: no olingo support yet. // TODO: no olingo support yet.
td.setSrid(SRID.valueOf(srid));
} }
return td; return td;
} }
@ -283,7 +286,7 @@ public class MetadataParser {
term.setDefaultValue(attr(element, "DefaultValue")); term.setDefaultValue(attr(element, "DefaultValue"));
} }
if (attr(element, "AppliesTo") != null) { if (attr(element, "AppliesTo") != null) {
term.setAppliesTo(Arrays.asList(attr(element, "AppliesTo"))); term.setAppliesTo(Collections.singletonList(attr(element, "AppliesTo")));
} }
term.setNullable(Boolean.parseBoolean(attr(element, "Nullable"))); term.setNullable(Boolean.parseBoolean(attr(element, "Nullable")));
String maxLength = attr(element, "MaxLength"); String maxLength = attr(element, "MaxLength");
@ -301,6 +304,7 @@ public class MetadataParser {
String srid = attr(element, "SRID"); String srid = attr(element, "SRID");
if (srid != null) { if (srid != null) {
// TODO: no olingo support yet. // TODO: no olingo support yet.
term.setSrid(SRID.valueOf(srid));
} }
return term; return term;
} }
@ -473,6 +477,7 @@ public class MetadataParser {
String srid = attr(element, "SRID"); String srid = attr(element, "SRID");
if (srid != null) { if (srid != null) {
// TODO: no olingo support yet. // TODO: no olingo support yet.
property.setSrid(SRID.valueOf(srid));
} }
String defaultValue = attr(element, "DefaultValue"); String defaultValue = attr(element, "DefaultValue");
if (defaultValue != null) { if (defaultValue != null) {
@ -570,7 +575,6 @@ public class MetadataParser {
} }
}.read(reader, element, bindings, "NavigationPropertyBinding"); }.read(reader, element, bindings, "NavigationPropertyBinding");
;
} }
}.read(reader, element, schema, "EntitySet", "Singleton", "ActionImport", "FunctionImport"); }.read(reader, element, schema, "EntitySet", "Singleton", "ActionImport", "FunctionImport");
schema.setEntityContainer(container); schema.setEntityContainer(container);
@ -622,19 +626,19 @@ public class MetadataParser {
boolean hit = false; boolean hit = false;
for (int i = 0; i < names.length; i++) { for (String name : names) {
if (event.isStartElement()) { if (event.isStartElement()) {
element = event.asStartElement(); element = event.asStartElement();
if (element.getName().getLocalPart().equals(names[i])) { if (element.getName().getLocalPart().equals(name)) {
reader.nextEvent(); // advance cursor reader.nextEvent(); // advance cursor
// System.out.println("reading = "+names[i]); // System.out.println("reading = "+names[i]);
build(reader, element, t, names[i]); build(reader, element, t, name);
hit = true; hit = true;
} }
} }
if (event.isEndElement()) { if (event.isEndElement()) {
EndElement e = event.asEndElement(); EndElement e = event.asEndElement();
if (e.getName().getLocalPart().equals(names[i])) { if (e.getName().getLocalPart().equals(name)) {
reader.nextEvent(); // advance cursor reader.nextEvent(); // advance cursor
// System.out.println("done reading = "+names[i]); // System.out.println("done reading = "+names[i]);
hit = true; hit = true;

View File

@ -752,16 +752,6 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
isNullable, maxLength, precision, scale, isUnicode); isNullable, maxLength, precision, scale, isUnicode);
if (value == null) { if (value == null) {
writer.writeAttribute(DATA, NS_DATA, "null", "true"); writer.writeAttribute(DATA, NS_DATA, "null", "true");
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int16)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Single)) {
writer.writeCharacters(value);
} else { } else {
writer.writeCharacters(value); writer.writeCharacters(value);
} }

View File

@ -39,6 +39,7 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -73,7 +74,7 @@ public class AsyncProcessor<T extends Processor> {
public Object invoke(Object o, Method method, Object[] objects) throws Throwable { public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
if (Processor.class.isAssignableFrom(method.getDeclaringClass())) { if (Processor.class.isAssignableFrom(method.getDeclaringClass())) {
invokeMethod = method; invokeMethod = method;
invokeParameters = objects; invokeParameters = Arrays.copyOf(objects, objects.length);
} else { } else {
throw new ODataRuntimeException("Invalid class '" + method.getDeclaringClass() + throw new ODataRuntimeException("Invalid class '" + method.getDeclaringClass() +
"' can not wrapped for asynchronous processing."); "' can not wrapped for asynchronous processing.");