Issue with OrthancPluginGetPeerUserProperty method

Hi all,

I am still working on a plugin to get data from remote peer.

I manage to get peer url from an index of the peer list with OrthancPluginGetPeerUrl method.

But when I want to get username and password from peer configuration, the code failed.

For that purpose I use the OrthancPluginLogInfo method from OrthancCPlugin.h class.
My code looks like that :

uint32_t peerIndex = 0;

string url_peer = OrthancPluginGetPeerUrl(context, peers, peerIndex);
if (url_peer.empty())
{
throw MessageException((“Url peer not found for alias:” + alias).c_str());
}
OrthancPluginLogInfo(context, ("PeerInfoFromAlias url_peer: " + url_peer).c_str());

const char* userProperty = “Username”;
const char* username = OrthancPluginGetPeerUserProperty(context, peers, peerIndex, userProperty);
if (username == NULL)
{
throw MessageException((“Peer username cannot be read for alias:” + alias).c_str());
}
OrthancPluginLogInfo(context, ("PeerInfoFromAlias OrthancPluginGetPeerUserProperty: " + string(username)).c_str());

Do you know my mistake?
Is there another way to get peer username and password?

Thanks a lot
Regards

Audrey

Hi Audrey,

Well, this OrthancPluginGetPeerUserProperty method is actually able to return only “user” properties and not the standard ones.

/**

  • @brief Get some user-defined property of an Orthanc peer.

Sorry for the OrthancPluginGetPeerUserProperty, it was well documented.
Thanks for the OrthancPluginCallPeerApi , this is exactly what i was looking for!

Regards

Audrey

Hi Alain,

I try to add peer using OrthancPluginCallPeerApi .
For that purpose I pass the following parameters :

  • context : the orthanc plugin context

  • answerBody : NULL

  • answerHeaders : NULL

  • peers : the peer list from OrthancPluginGetPeers

  • peerIndex : the peer list size

  • method :

    OrthancPluginHttpMethod_Put

  • uri : the peer to add AET

  • body : a serialized json with url, username, password

  • the bodySize

  • a timeout value
    The problem is that the peerIndex does not exist.
    So I’ve tried to add a peer in the peer list (using Orthanc*::WebServiceParameters)*,
    but I didn’t manage to do that.

How to proceed to dynamically add a peer in an Orthanc Plugin?

Do you have some code example doing that use this sdk?

Regards.

Audrey

Hi Audrey,

Indeed, you can not use CallPeerApi on a peer that does not exist yet. You should use OrthancPluginRestApiPut to call PUT on /peers/alias (https://api.orthanc-server.com/#tag/Networking/paths/~1peers~1{id}/put)

HTH

Alain

Thank you so muck for your quick reply.

So I did a call to OrthancPluginRestApiPut with uri : /peers/myPeerAlias, but I have this error : “ErrorCode_UnknownResource”.
I found that this error come from Orthanc::ReadJsonInternal method : “Cannot parse JSON: Line 1, Column 2\n Missing ‘}’ or object member name\n”.

What is the json format of the body passed in OrthancPluginRestApiPut method?

Is my code faulty?
What kind of data do I need to pass in the body parameter?

Screenshot from 2022-10-26 16-57-30.png

Regards

replace sizeof(bodyC) by peerToAddDataStr.size()

Screenshot from 2022-10-26 16-57-30.png

Thank you so much and sorry to bother you with that.
It works well now.

Hi Alain,

Sorry to bother you.
I am still trying to get data from remote peer using a plugin.

My code add a peer in my Orthanc configuration and call the OrthancPluginCallPeerApi function to get Orthanc id from dicom id.

Now I have an OrthancException “BadSequenceOfCalls” just after the call of OrthancPluginCallPeerApi.
It’s raised on OrthancPluginCppWrapper.cpp, method **“**GetGlobalContext”.

Do you have an idea why the globalContext_ became NULL ?

Regards