Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: error code and message not parsed. e.g of raw response: #71

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public BuilderImpl setType(final EdmType type) {

@Override
public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
if (type == EdmPrimitiveTypeKind.Stream) {
// Ilya: throwing these exceptions from here doesn't make sense
/*if (type == EdmPrimitiveTypeKind.Stream) {
throw new IllegalArgumentException(String.format(
"Cannot build a primitive value for %s", EdmPrimitiveTypeKind.Stream.toString()));
}
Expand All @@ -66,7 +67,7 @@ public BuilderImpl setType(final EdmPrimitiveTypeKind type) {
+ "An entity can declare a property to be of type Geometry. "
+ "An instance of an entity MUST NOT have a value of type Geometry. "
+ "Each value MUST be of some subtype.");
}
}*/

instance.typeKind = type == null ? EdmPrimitiveTypeKind.String : type;
instance.type = EdmPrimitiveTypeFactory.getInstance(instance.typeKind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,91 @@

public class JsonODataErrorDeserializer extends JsonDeserializer {

public JsonODataErrorDeserializer(final boolean serverMode) {
super(serverMode);
}
public JsonODataErrorDeserializer(final boolean serverMode) {
super(serverMode);
}

protected ODataError doDeserialize(final JsonParser parser) throws IOException {
protected ODataError doDeserialize(final JsonParser parser) throws IOException {

final ODataError error = new ODataError();
final ODataError error = new ODataError();

final ObjectNode tree = parser.getCodec().readTree(parser);
if (tree.has(Constants.JSON_ERROR)) {
final JsonNode errorNode = tree.get(Constants.JSON_ERROR);
final ObjectNode tree = parser.getCodec().readTree(parser);
if (tree.has(Constants.JSON_ERROR)) {
final JsonNode errorNode = tree.get(Constants.JSON_ERROR);

if (errorNode.has(Constants.ERROR_CODE)) {
error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
}
if (errorNode.has(Constants.ERROR_MESSAGE)) {
final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE);
if (message.isValueNode()) {
error.setMessage(message.textValue());
} else if (message.isObject()) {
error.setMessage(message.get(Constants.VALUE).asText());
}
}
if (errorNode.has(Constants.ERROR_TARGET)) {
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) {
List<ODataErrorDetail> details = new ArrayList<>();
JsonODataErrorDetailDeserializer detailDeserializer = new JsonODataErrorDetailDeserializer(serverMode);
for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) {
details.add(detailDeserializer.doDeserialize(jsonNode.traverse(parser.getCodec()))
.getPayload());
}
if (errorNode.has(Constants.ERROR_CODE)) {
error.setCode(errorNode.get(Constants.ERROR_CODE).textValue());
}
if (errorNode.has(Constants.ERROR_MESSAGE)) {
final JsonNode message = errorNode.get(Constants.ERROR_MESSAGE);
if (message.isValueNode()) {
error.setMessage(message.textValue());
} else if (message.isObject()) {
error.setMessage(message.get(Constants.VALUE).asText());
}
}
if (errorNode.has(Constants.ERROR_TARGET)) {
error.setTarget(errorNode.get(Constants.ERROR_TARGET).textValue());
}
if (errorNode.hasNonNull(Constants.ERROR_DETAILS)) {
List<ODataErrorDetail> details = new ArrayList<>();
JsonODataErrorDetailDeserializer detailDeserializer =
new JsonODataErrorDetailDeserializer(serverMode);
for (JsonNode jsonNode : errorNode.get(Constants.ERROR_DETAILS)) {
details.add(detailDeserializer.doDeserialize(
jsonNode.traverse(parser.getCodec())).getPayload());
}

error.setDetails(details);
}
if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) {
HashMap<String, String> innerErrorMap = new HashMap<>();
final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR);
for (final Iterator<String> itor = innerError.fieldNames(); itor.hasNext();) {
final String keyTmp = itor.next();
final String val = innerError.get(keyTmp).toString();
innerErrorMap.put(keyTmp, val);
}
error.setInnerError(innerErrorMap);
}
}
error.setDetails(details);
}
if (errorNode.hasNonNull(Constants.ERROR_INNERERROR)) {
HashMap<String, String> innerErrorMap = new HashMap<>();
final JsonNode innerError = errorNode.get(Constants.ERROR_INNERERROR);
for (final Iterator<String> itor = innerError.fieldNames(); itor.hasNext();) {
final String keyTmp = itor.next();
final String val = innerError.get(keyTmp).toString();
innerErrorMap.put(keyTmp, val);
}
error.setInnerError(innerErrorMap);
}
} else if (tree.has(Constants.ERROR_CODE)) {
if (tree.has(Constants.ERROR_CODE)) {
error.setCode(tree.get(Constants.ERROR_CODE).textValue());
}
if (tree.has(Constants.ERROR_MESSAGE)) {
final JsonNode message = tree.get(Constants.ERROR_MESSAGE);
if (message.isValueNode()) {
error.setMessage(message.textValue());
} else if (message.isObject()) {
error.setMessage(message.get(Constants.VALUE).asText());
}
}
if (tree.has(Constants.ERROR_TARGET)) {
error.setTarget(tree.get(Constants.ERROR_TARGET).textValue());
}
if (tree.hasNonNull(Constants.ERROR_DETAILS)) {
List<ODataErrorDetail> details = new ArrayList<>();
JsonODataErrorDetailDeserializer detailDeserializer =
new JsonODataErrorDetailDeserializer(serverMode);
for (JsonNode jsonNode : tree.get(Constants.ERROR_DETAILS)) {
details.add(detailDeserializer.doDeserialize(
jsonNode.traverse(parser.getCodec())).getPayload());
}

return error;
}
error.setDetails(details);
}
if (tree.hasNonNull(Constants.ERROR_INNERERROR)) {
HashMap<String, String> innerErrorMap = new HashMap<>();
final JsonNode innerError = tree.get(Constants.ERROR_INNERERROR);
for (final Iterator<String> itor = innerError.fieldNames(); itor.hasNext();) {
final String keyTmp = itor.next();
final String val = innerError.get(keyTmp).toString();
innerErrorMap.put(keyTmp, val);
}
error.setInnerError(innerErrorMap);
}
}

return error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,9 @@ protected ClientValue getODataValue(FullQualifiedName type,
value.asCollection().add(getODataValue(type, fake, contextURL, metadataETag));
}
} else if (valuable.isEnum()) {
Object enumValue = valuable.asEnum();
value = client.getObjectFactory().newEnumValue(type == null ? null : type.toString(),
valuable.asEnum().toString());
enumValue==null? null: enumValue.toString());
} else if (valuable.isComplex()) {
final ClientComplexValue lcValue =
client.getObjectFactory().newComplexValue(type == null ? null : type.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private void annotated(final ContentType contentType) throws EdmPrimitiveTypeExc
assertEquals("com.contoso.display.styleType", annotation.getValue().getTypeName());
assertTrue(annotation.hasComplexValue());
assertEquals(2,
annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class), 0);
annotation.getValue().asComplex().get("order").getPrimitiveValue().toCastValue(Integer.class).intValue(), 0);

final ClientEntity written = client.getBinder().getODataEntity(
new ResWrap<Entity>((URI) null, null, client.getBinder().getEntity(entity)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
public interface EdmAnnotation extends EdmAnnotatable {

String getTermAsString();

/**
* @return the term of this annotation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public EdmAnnotationImpl(final Edm edm, final CsdlAnnotation annotation) {
this.annotation = annotation;
}

@Override
public String getTermAsString() {
return annotation.getTerm();
}

@Override
public EdmTerm getTerm() {
if (term == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ private EdmTypeInfo(final Edm edm, final String typeExpression, final boolean in
}
}
}
if (primitiveType==null && typeDefinition==null && enumType==null && complexType==null && entityType==null) {
primitiveType = EdmPrimitiveTypeKind.String;
}
}

public String internal() {
Expand Down
4 changes: 2 additions & 2 deletions lib/server-tecsvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</execution>
</executions>
</plugin>
<plugin>
<!-- <plugin>
<groupId>com.keyboardsamurais.maven</groupId>
<artifactId>maven-timestamp-plugin</artifactId>
<configuration>
Expand All @@ -111,7 +111,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin> -->
</plugins>
</build>

Expand Down