eclipse-basyx / basyx-java-server-sdk

MIT License
58 stars 46 forks source link

Internal Server error on updating $value of file SubmodelElement #246

Closed aaronzi closed 5 months ago

aaronzi commented 7 months ago

After switching to the image tag milestone_02 of the AAS Environment I am not able to update the value of file SubmodelElements anymore. The AAS Env will return an internal server error with error code 500 (see log). Also updating the file SubmodelElement with PUT /submodels/{submodelIdentifier}/submodel-elements/{idShortPath} is throwing an internal server error.

2024-03-20 13:42:20 2024-03-20T12:42:20.260Z ERROR 1 --- [nio-8081-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.ClassCastException: class org.eclipse.digitaltwin.basyx.submodelservice.value.PropertyValue cannot be cast to class org.eclipse.digitaltwin.basyx.submodelservice.value.FileBlobValue (org.eclipse.digitaltwin.basyx.submodelservice.value.PropertyValue and org.eclipse.digitaltwin.basyx.submodelservice.value.FileBlobValue are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @6d03e736)] with root cause
2024-03-20 13:42:20 
2024-03-20 13:42:20 java.lang.ClassCastException: class org.eclipse.digitaltwin.basyx.submodelservice.value.PropertyValue cannot be cast to class org.eclipse.digitaltwin.basyx.submodelservice.value.FileBlobValue (org.eclipse.digitaltwin.basyx.submodelservice.value.PropertyValue and org.eclipse.digitaltwin.basyx.submodelservice.value.FileBlobValue are in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @6d03e736)
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelservice.value.mapper.FileValueMapper.setValue(FileValueMapper.java:36) ~[basyx.submodelservice-core-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelservice.InMemorySubmodelService.setSubmodelElementValue(InMemorySubmodelService.java:110) ~[basyx.submodelservice-backend-inmemory-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.backend.CrudSubmodelRepository.setSubmodelElementValue(CrudSubmodelRepository.java:183) ~[basyx.submodelrepository-backend-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration.RegistryIntegrationSubmodelRepository.setSubmodelElementValue(RegistryIntegrationSubmodelRepository.java:117) ~[basyx.submodelrepository-feature-registry-integration-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.feature.operation.delegation.OperationDelegationSubmodelRepository.setSubmodelElementValue(OperationDelegationSubmodelRepository.java:111) ~[basyx.submodelrepository-feature-operation-delegation-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.http.SubmodelRepositoryApiHTTPController.handleSubmodelElementValueSetRequest(SubmodelRepositoryApiHTTPController.java:259) ~[basyx.submodelrepository-http-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.http.SubmodelRepositoryApiHTTPController.patchSubmodelElementByPathValueOnlySubmodelRepo(SubmodelRepositoryApiHTTPController.java:200) ~[basyx.submodelrepository-http-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
2024-03-20 13:42:20     at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
2024-03-20 13:42:20     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:751) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:141) ~[spring-context-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:751) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:703) ~[spring-aop-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.submodelrepository.http.SubmodelRepositoryApiHTTPController$$SpringCGLIB$$0.patchSubmodelElementByPathValueOnlySubmodelRepo(<generated>) ~[basyx.submodelrepository-http-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
2024-03-20 13:42:20     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
2024-03-20 13:42:20     at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
2024-03-20 13:42:20     at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1081) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:974) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:888) ~[spring-webmvc-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.eclipse.digitaltwin.basyx.http.HttpBaSyxHeader.doFilterInternal(HttpBaSyxHeader.java:53) ~[basyx.http-2.0.0-SNAPSHOT.jar!/:2.0.0-SNAPSHOT]
2024-03-20 13:42:20     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.springframework.web.filter.ServerHttpObservationFilter.doFilterInternal(ServerHttpObservationFilter.java:109) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.12.jar!/:6.0.12]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:894) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1740) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.13.jar!/:na]
2024-03-20 13:42:20     at java.base/java.lang.Thread.run(Thread.java:840) ~[na:na]
2024-03-20 13:42:20
mansei commented 7 months ago

Hi, my situation is worse. I call PUT /submodels/{submodelIdentifier}/submodel-elements/{idShortPath} (not valueOnly), the httpstatus returned is 404 and the SubmodelElement is removed from the submodel! Even if I'm doing something wrong, the call to update the SubmodelElement should never remove it from the submodel.

BR Manfred

RequestBody: { "modelType": "Property", "value": "Some content", "valueType": "xs:string", "idShort": "String" }

mdanish98 commented 7 months ago

Hi @aaronzi , Hi @mansei ,

Thanks for raising this issue. Could you please update the request body also in your descriptions?

aaronzi commented 7 months ago

Hi @mdanish98, this is the request I was sending:

curl 'http://localhost:8081/submodels/MWVmYzY0OTktZTQ3NC00Njc5LWJiMmUtNzI5ZWIyOGRjZjgw/submodel-elements/CompanyLogo/$value' \
  -X 'PATCH' \
  -H 'Accept: */*' \
  -H 'Accept-Language: en-US,en' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Origin: http://localhost:3000' \
  -H 'Referer: http://localhost:3000/' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-site' \
  -H 'Sec-GPC: 1' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Brave";v="123", "Not:A-Brand";v="8", "Chromium";v="123"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw '"test"'

That's the response I get in the browser:

{
    "timestamp": 1711027657561,
    "status": 500,
    "error": "Internal Server Error",
    "path": "/submodels/MWVmYzY0OTktZTQ3NC00Njc5LWJiMmUtNzI5ZWIyOGRjZjgw/submodel-elements/CompanyLogo/$value"
}

The log of the container is already in the original issue message.

mdanish98 commented 7 months ago

Hi @aaronzi ,

Thanks for providing the requested details. The ValueOnly serialization for File SME looks like below: { "contentType": "application/json", "value": "testFile.json" }

So, instead of "test" please try with the above serialization.

aaronzi commented 7 months ago

Thank you, you are right. This works.

But as @mansei also mentioned, the PUT-request has an issue. This is my request for example:

curl -X 'PUT' \
  'http://localhost:8081/submodels/MWVmYzY0OTktZTQ3NC00Njc5LWJiMmUtNzI5ZWIyOGRjZjgw/submodel-elements/CompanyLogo?level=deep' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "modelType": "File",
  "contentType": "application/json",
  "value": "demo.json",
  "semanticId": {
    "keys": [
      {
        "type": "GlobalReference",
        "value": "https://admin-shell.io/zvei/nameplate/2/0/Nameplate/CompanyLogo "
      }
    ],
    "type": "ExternalReference"
  },
  "qualifiers": [
    {
      "kind": "ConceptQualifier",
      "type": "Multiplicity",
      "value": "ZeroToOne",
      "valueType": "xs:string"
    }
  ],
  "idShort": "CompanyLogo"
}'

When executing this I get a 404 error and the property gets removed entirely.

mdanish98 commented 7 months ago

We are analyzing this issue, and we'll get back to you with the analysis results.

FrankSchnicke commented 5 months ago

The fix will be included in the next SNAPSHOT release.