eclipse-basyx / basyx-java-sdk

java-sdk
MIT License
26 stars 33 forks source link

ConnectedSubmodel.getSubmodelElement() building wrong path for http-request #285

Closed wasn93 closed 1 year ago

wasn93 commented 1 year ago

While working with the sdk I figured out a problem (and probably the solution) in the ConnectedSubmodel class. I instantiate the class:

AASRegistryProxy registry = new AASRegistryProxy(urlRegistryLocal);
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry);
ConnectedSubmodel aimcSm = (ConnectedSubmodel) manager.retrieveSubmodel(
                new Identifier(IdentifierType.IRI, "th-koeln.de-GART-Labor-BACnetDevices-1678804990"),
                new Identifier(IdentifierType.IRI, "SMAssetInterfaceMappingConfiguration")
        );

This works perfectly fine. As soon as I want to retrieve a submodel element via getSubmodelElement() (here the SubmodelElementCollection "Configurations") the following error is thrown:

Exception in thread "main" org.eclipse.basyx.vab.exception.provider.MalformedRequestException: [6 | 400 - MalformedRequestException: Unknown path Configurations was requested, 6 | [HTTP GET] Failed to request http://<ip>:<port>/shells/th-koeln.de-GART-Labor-BACnetDevices-1678804990/aas/submodels/AssetInterfaceMappingConfiguration with mediatype application/json;charset=UTF-8. "MalformedRequestException: Unknown path Configurations was requested"]
    at org.eclipse.basyx.vab.protocol.http.server.ExceptionToHTTPCodeMapper.mapToException(ExceptionToHTTPCodeMapper.java:100)
    at org.eclipse.basyx.vab.protocol.http.connector.HTTPConnector.handleProcessingException(HTTPConnector.java:325)
    at org.eclipse.basyx.vab.protocol.http.connector.HTTPConnector.httpGet(HTTPConnector.java:211)
    at org.eclipse.basyx.vab.protocol.http.connector.HTTPConnector.getValue(HTTPConnector.java:78)
    at org.eclipse.basyx.vab.coder.json.connector.JSONConnector.getValue(JSONConnector.java:105)
    at org.eclipse.basyx.vab.modelprovider.VABElementProxy.getValue(VABElementProxy.java:78)
    at org.eclipse.basyx.submodel.metamodel.connected.ConnectedSubmodel.getSubmodelElement(ConnectedSubmodel.java:210)
        at <myClass>

The Submodel contains this element and it can be requested via direct approach in a browser. Doing some testing I could reproduce the error in the browser. The url to request a SubmodelElement is supposed to look like:

/shells/{aasId}/aas/submodels/{submodelIdShort}/submodel/submodelElements/{seIdShortPath}

Leaving out the "submodel"-part behind the {submodelIdShort} produces the error.

I checked the code of ConnectedSubmodel-class. The concrete function does:

public ISubmodelElement getSubmodelElement(String id) {
        Map<String, Object> node = (Map<String, Object>) getProxy().getValue(VABPathTools.concatenatePaths(MultiSubmodelElementProvider.ELEMENTS, id));
        ISubmodelElement element = ConnectedSubmodelElementFactory.getConnectedSubmodelElement(getProxy(), MultiSubmodelElementProvider.ELEMENTS, id, node);
        return element;
    }

The path to request is build here. Indeed it is only build from MultiSubmodelElementProvider.ELEMENTS, which equals to "submodelElements" and the idShort of the submodelElement. Due to the missing "submodel"-part it is not possible to request SubmodelElements with this function.

Additional: It seems like the error was already in version 1.3.1, as trying it out produces the same error. Here the code was:

Map<String, Object> node = (Map)this.getProxy().getValue(VABPathTools.concatenatePaths(new String[]{"submodelElements", id}));
ISubmodelElement element = ConnectedSubmodelElementFactory.getConnectedSubmodelElement(this.getProxy(), "submodelElements", id, node);
FrankSchnicke commented 1 year ago

Thank you very much for this detailed description. Is is possible that the Submodel entry in the Registry is missing the "submodel" part? This error could propagate down to this retrieval. Due to legacy reasons, retrieving a Submodel works without the "submodel" part. The SubmodelElement retrieval, however, requires this part.

FrankSchnicke commented 1 year ago

Is this still relevant? Otherwise, I will close the issue.

wasn93 commented 1 year ago

Sorry for the late response, I could check it now. Yes, this was the problem. Thanks for the assistance!

Frank Schnicke @.***> schrieb am Do., 25. Mai 2023, 11:34:

Is this still relevant? Otherwise, I will close the issue.

— Reply to this email directly, view it on GitHub https://github.com/eclipse-basyx/basyx-java-sdk/issues/285#issuecomment-1562505808, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6YTJ4WACLRB4UAHRG4DQYLXH4KSTANCNFSM6AAAAAAXVYL5QM . You are receiving this because you authored the thread.Message ID: @.***>

FrankSchnicke commented 1 year ago

Perfect, happy to help!