International-Data-Spaces-Association / Java-Representation-of-IDS-Information-Model

Apache License 2.0
2 stars 7 forks source link

Deserialization Error with java library v4.0.8 #5

Closed juliapampus closed 3 years ago

juliapampus commented 3 years ago

When updating the Infomodel and Infomodel Serializer version in the Dataspace Connector to v4.0.8, we noticed some misbehavior for object deserialization. This causes test fails and avoids upgrading to this version, as we rely on proper deserialization for functionality as it used to work with older versions.

I provided three examples. In all of them, I use the builder classes and toRdf() method to create IDS objects. Then, I try to convert exactly these strings back to IDS objects using the Serializer.deserialize(String serialization, Class<T> valueType) method.

1. ConnectorEndpoint: everything works fine

IDS object (as RDF):

{
  "@context" : {
    "ids" : "https://w3id.org/idsa/core/"
  },
  "@type" : "ids:ConnectorEndpoint",
  "@id" : "https://w3id.org/idsa/autogen/connectorEndpoint/0b82f8f2-5180-467c-b0f7-36aebca206ff",
  "ids:accessURL" : {
    "@id" : "https://test.com"
  }
}

IDS object after deserialization (from IntelliJ debug console): image

2. ConfigurationModel: error

IDS object (as RDF):

{
  "@context" : {
    "ids" : "https://w3id.org/idsa/core/",
    "idsc" : "https://w3id.org/idsa/code/"
  },
  "@type" : "ids:ConfigurationModel",
  "@id" : "configId",
  "ids:keyStore" : {
    "@id" : "file:///conf/keystore.p12"
  },
  "ids:connectorStatus" : {
    "@id" : "https://w3id.org/idsa/code/CONNECTOR_ONLINE"
  },
  "ids:trustStore" : {
    "@id" : "file:///conf/truststore.p12"
  },
  "ids:connectorProxy" : [ {
    "@type" : "ids:Proxy",
    "@id" : "proxiId",
    "ids:proxyURI" : {
      "@id" : "proxy.dortmund.isst.fraunhofer.de:3128"
    },
    "ids:noProxy" : [ {
      "@id" : "https://localhost:8080/"
    } ],
    "ids:proxyAuthentication" : {
      "@type" : "ids:BasicAuthentication",
      "@id" : "basicAuthId"
    }
  } ],
  "ids:configurationModelLogLevel" : {
    "@id" : "https://w3id.org/idsa/code/NO_LOGGING"
  },
  "ids:connectorDescription" : {
    "@type" : "ids:BaseConnector",
    "@id" : "connectorId",
    "ids:publicKey" : {
      "@type" : "ids:PublicKey",
      "@id" : "keyId",
      "ids:keyType" : {
        "@id" : "https://w3id.org/idsa/code/RSA"
      },
      "ids:keyValue" : "WW91ciBkYXBzIHRva2VuIGhlcmUu"
    },
    "ids:version" : "v3.0.0",
    "ids:description" : [ {
      "@value" : "IDS Connector with static example resources hosted by the Fraunhofer ISST.",
      "@type" : "http://www.w3.org/2001/XMLSchema#string"
    } ],
    "ids:title" : [ {
      "@value" : "Dataspace Connector",
      "@type" : "http://www.w3.org/2001/XMLSchema#string"
    } ],
    "ids:securityProfile" : {
      "@id" : "https://w3id.org/idsa/code/BASE_SECURITY_PROFILE"
    },
    "ids:maintainer" : {
      "@id" : "https://example.com"
    },
    "ids:curator" : {
      "@id" : "https://example.com"
    },
    "ids:inboundModelVersion" : [ "4.0.0" ],
    "ids:outboundModelVersion" : "4.0.0",
    "ids:hasDefaultEndpoint" : {
      "@type" : "ids:ConnectorEndpoint",
      "@id" : "endpointId",
      "ids:accessURL" : {
        "@id" : "/api/ids/data"
      }
    }
  },
  "ids:connectorDeployMode" : {
    "@id" : "https://w3id.org/idsa/code/TEST_DEPLOYMENT"
  }
}

IDS object after deserialization (from IntelliJ debug console): We don't get that far, an error is thrown during deserilization.

image

Stack trace snippet:

java.io.IOException: Could not extract class from input message
    at de.fraunhofer.iais.eis.ids.jsonld.Parser.parseMessage(Parser.java:947) ~[infomodel-serializer-4.0.8.jar:?]
    at de.fraunhofer.iais.eis.ids.jsonld.Parser.parseMessage(Parser.java:995) ~[infomodel-serializer-4.0.8.jar:?]
    at de.fraunhofer.iais.eis.ids.jsonld.Serializer.deserialize(Serializer.java:119) ~[infomodel-serializer-4.0.8.jar:?]
    at io.dataspaceconnector.controller.ExampleController.getConnectorConfiguration(ExampleController.java:136) ~[classes/:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) ~[spring-web-5.3.7.jar:5.3.7]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) ~[spring-web-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1063) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.46.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.7.jar:5.3.7]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.46.jar:4.0.FR]

3. Rule: missing attributes

IDS object (as RDF):

{
  "@type": "ids:Permission",
  "@id": "https://w3id.org/idsa/autogen/permission/885c4512-8031-42d3-a9c0-d50594dad37f",
  "ids:description": [
    {
      "@value": "provide-access",
      "@type": "http://www.w3.org/2001/XMLSchema#string"
    }
  ],
  "ids:title": [
    {
      "@value": "Allow Data Usage",
      "@type": "http://www.w3.org/2001/XMLSchema#string"
    }
  ],
  "ids:action": [
    {
      "@id": "https://w3id.org/idsa/code/USE"
    }
  ]
}

and/or

{
  "@type": "ids:Permission",
  "@id": "https://w3id.org/idsa/autogen/permission/770f890f-9ea1-4cd6-9f87-8d8d3f126188",
  "ids:description": [
    {
      "@value": "provide-access",
      "@type": "http://www.w3.org/2001/XMLSchema#string"
    }
  ],
  "ids:title": [
    {
      "@value": "Allow Data Usage",
      "@type": "http://www.w3.org/2001/XMLSchema#string"
    }
  ],
  "ids:action": [
    {
      "@id": "idsc:USE"
    }
  ]
}

IDS object after deserialization (from IntelliJ debug console):

image

Can you help us with this problem? @maboeckmann @sebbader

maboeckmann commented 3 years ago

Hi @juliapampus, thanks for reporting this. Regarding 2) I see that some values of the "@id" fields are not URIs. This makes Jena fail to retrieve information via SPARQL from the RDF graph. Could you please make sure that all id fields are proper, distinct URIs, and try again? I will need to take a closer look at 3)

maboeckmann commented 3 years ago

Adding to my previous comment: In the third example, the context is missing. Adding a context made my local serializer work just fine. We improved the context generation a while back, fixing some bugs where the context would be missing. Did you create these examples manually, or could you provide a reproducible example that creates such a policy with a missing context?

brianjahnke commented 3 years ago

Hi, you are right. If you add the context to example 3 the serializer will work.

But there are still open questions with this:

maboeckmann commented 3 years ago

Hi, that is correct - it should be included automatically. If it isn't and you are on the latest release, please send us a reproducible example.

brianjahnke commented 3 years ago

Hi,

found some missing toRdf in our code. I guess that the builder class itself has nothing to do with the context? Maybe this problem could have been prevented with #3, thus making usage of the lib less errorprone?

Thank you for your help!

maboeckmann commented 3 years ago

Hi, it should not be a builder-related issue. If the context is missing, we need to look at the serializer. Was your issue resolved in the meantime, or can we assist you here?

brianjahnke commented 3 years ago

Hi, the problem should resolved. Thank you! (I cannot close the issue ^^)