SmartGridready / SGrJava

SmartGridready communication handler in Java
0 stars 0 forks source link

Added unit-tests for SGrDeviceBuilder. #68

Closed ergo-furrer closed 3 weeks ago

ergo-furrer commented 3 weeks ago

Fixed XmlResourceLoader and DeviceDescriptionLoader by using resource name 'eid.xml'.

ergo-furrer commented 3 weeks ago

I did merge now so it will be available for you. I will remove the Parameter with the next commit, need to switch to work on another project now...

mkrebs81 commented 3 weeks ago

thank you. My next step is to try to make POST form parameters work. there might be a workaround that uses the request body.

ergo-furrer commented 3 weeks ago

My next step is to try to make POST form parameters work. there might be a workaround that uses the request body.

I think it is possible. Something like: <requestBody>sensor_id={{sensor_id}}&voltage={{value}}</requestBody> should work. However we need to set the content type to application/x-www-form-urlencoded in ApacheRestServiceClient correctly.

We can take it from the Headers provided in the EI-XML.

  <restApiServiceCall>
            <requestHeader>
              <header>
                <headerName>Content-Type</headerName><value> application/x-www-form-urlencoded</value>
              </header>
            </requestHeader>
            <requestMethod>POST</requestMethod>
            <requestBody>sensor_id={{sensor_id}}&voltage={{value}}</requestBody>

However I found out that ApacheRestService client does not URL encode by itself, so we need to do it ourselves. We have to use httpPost.setEntity(new UrlEncodedFormEntity(urlParameters)); provided by the Apache http client.

Alternatively we could also extend the EI-XML as follows:

    <requestHeader>
              <header>
                <headerName>Content-Type</headerName><value> application/x-www-form-urlencoded</value>
              </header>
            </requestHeader>
            <requestMethod>POST</requestMethod>
            <requestPath>/authentication</requestPath>
            <formData>
              <parameter><key>analogOutId</key><value>{{analogOutId}}</value></parameter>
              <parameter><key>voltageDC</key><vakue>4.5</vakue></parameter>
            </formData>
mkrebs81 commented 3 weeks ago

I am trying the first approach in a separate branch right now.

As for the second approach: Can we also use properties instead of whole objects, like this?

<formData>
  <parameter name="analogOutId" value="{{analogOutId}}" />
  <parameter name="voltageDC" value="4.5" />
</formData>

That would result in less additional classes.

ergo-furrer commented 3 weeks ago

I am trying the first approach in a separate branch right now.

As for the second approach: Can we also use properties instead of whole objects, like this?

<formData>
  <parameter name="analogOutId" value="{{analogOutId}}" />
  <parameter name="voltageDC" value="4.5" />
</formData>

That would result in less additional classes.

We had once attributes, but got rid of them for several reasons (currently there are no attributes defined within the spec). So I would keep using elements.