Skip to content

Commit 13725c7

Browse files
Merge pull request #219 from eclipse-basyx/release/1.3.1
Release/1.3.1
2 parents 57d8d45 + 92e70d8 commit 13725c7

File tree

11 files changed

+244
-57
lines changed

11 files changed

+244
-57
lines changed

pom.xml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.eclipse.basyx</groupId>
77
<artifactId>basyx.sdk</artifactId>
8-
<version>1.3.0</version>
8+
<version>1.3.1</version>
99
<name>BaSyx SDK</name>
1010
<description>BaSyx Software Development Kit</description>
1111
<url>https://www.eclipse.org/basyx/</url>
@@ -46,7 +46,7 @@
4646
<properties>
4747
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4848
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
49-
<spring-security-version>5.8.0</spring-security-version>
49+
<spring-security-version>5.8.1</spring-security-version>
5050
</properties>
5151

5252
<repositories>
@@ -110,7 +110,7 @@
110110
<plugin>
111111
<groupId>org.apache.maven.plugins</groupId>
112112
<artifactId>maven-surefire-plugin</artifactId>
113-
<version>3.0.0-M7</version>
113+
<version>3.0.0-M8</version>
114114
<configuration>
115115
<excludes>
116116
<exclude>**/*HTTP*</exclude>
@@ -126,7 +126,7 @@
126126
<plugin>
127127
<groupId>org.apache.maven.plugins</groupId>
128128
<artifactId>maven-failsafe-plugin</artifactId>
129-
<version>3.0.0-M7</version>
129+
<version>3.0.0-M8</version>
130130
<configuration>
131131
<includes>
132132
<include>**/*HTTP*</include>
@@ -184,15 +184,15 @@
184184
<dependency>
185185
<groupId>org.mockito</groupId>
186186
<artifactId>mockito-core</artifactId>
187-
<version>4.10.0</version>
187+
<version>5.1.1</version>
188188
<scope>test</scope>
189189
</dependency>
190190

191191
<!-- Moquette MQTT broker for testing MQTT events -->
192192
<dependency>
193193
<groupId>io.moquette</groupId>
194194
<artifactId>moquette-broker</artifactId>
195-
<version>0.15</version>
195+
<version>0.16</version>
196196
<scope>test</scope>
197197
<exclusions>
198198
<exclusion>
@@ -234,21 +234,21 @@
234234
<dependency>
235235
<groupId>org.glassfish.jersey.core</groupId>
236236
<artifactId>jersey-client</artifactId>
237-
<version>2.37</version>
237+
<version>2.38</version>
238238
</dependency>
239239

240240
<!-- Jersey InjectionManager (for Jersey client) -->
241241
<dependency>
242242
<groupId>org.glassfish.jersey.inject</groupId>
243243
<artifactId>jersey-hk2</artifactId>
244-
<version>2.37</version>
244+
<version>2.38</version>
245245
</dependency>
246246

247247
<!-- Tomcat 8 for HTTP server resource -->
248248
<dependency>
249249
<groupId>org.apache.tomcat</groupId>
250250
<artifactId>tomcat-catalina</artifactId>
251-
<version>9.0.70</version>
251+
<version>9.0.71</version>
252252
</dependency>
253253

254254
<!-- Used for creating .aasx files -->
@@ -276,7 +276,7 @@
276276
<dependency>
277277
<groupId>com.google.code.gson</groupId>
278278
<artifactId>gson</artifactId>
279-
<version>2.10</version>
279+
<version>2.10.1</version>
280280
</dependency>
281281

282282
<!-- Handles resources & files -->
@@ -327,13 +327,13 @@
327327
<dependency>
328328
<groupId>org.keycloak</groupId>
329329
<artifactId>keycloak-admin-client</artifactId>
330-
<version>19.0.2</version>
330+
<version>19.0.3</version>
331331
</dependency>
332332
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
333333
<dependency>
334334
<groupId>com.fasterxml.jackson.core</groupId>
335335
<artifactId>jackson-databind</artifactId>
336-
<version>2.14.1</version>
336+
<version>2.14.2</version>
337337
</dependency>
338338

339339
<dependency>

src/main/java/org/eclipse/basyx/submodel/factory/xml/XMLHelper.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ public static List<Map<String, Object>> getList(Object xmlObject) {
6767
/**
6868
* If the content of a XML-Element is requested, the parser returns an Object or
6969
* null, if it doesn't exist.<br>
70-
* This function casts the Object into a String and replaces null with an empty
71-
* String.
70+
* This function returns a String representation if possible. Null and Maps are
71+
* replaced with an empty String.
7272
*
7373
* @param object
74-
* a Object that is either a String or null
75-
* @return the given String or an empty String
74+
* @return the trimmed String object or an empty String
7675
*/
7776
public static String getString(Object object) {
78-
return object instanceof String ? ((String) object).trim() : "";
77+
// On XML level, it is not differentiated between an empty tag that should
78+
// contain text and an empty tag that should contain further text. Thus, Maps
79+
// are replaced with ""
80+
if (object == null || (object instanceof Map<?, ?>))
81+
return "";
82+
83+
return object.toString().trim();
7984
}
8085

8186
/**

src/main/java/org/eclipse/basyx/submodel/metamodel/map/qualifier/qualifiable/Qualifier.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ public void setValue(Object obj) {
156156
@Override
157157
public Object getValue() {
158158
Object value = get(Qualifier.VALUE);
159-
if (value instanceof String) {
160-
return ValueTypeHelper.getJavaObject(value, getValueType());
161-
} else {
162-
return value;
163-
}
159+
return ValueTypeHelper.getJavaObject(value, getValueType());
164160
}
165161

166162
public void setValueId(IReference obj) {

src/main/java/org/eclipse/basyx/submodel/metamodel/map/submodelelement/dataelement/property/valuetype/ValueType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
public enum ValueType implements StandardizedLiteralEnum {
3939
Int8("byte"), Int16("short"), Int32("int"), Int64("long"), UInt8("unsignedByte"), UInt16("unsignedShort"), UInt32("unsignedInt"), UInt64("unsignedLong"), String("string"), LangString("langString"), AnyURI("anyURI"), Base64Binary(
4040
"base64Binary"), HexBinary("hexBinary"), NOTATION("notation"), ENTITY("entity"), ID("id"), IDREF("idref"), Integer("integer"), NonPositiveInteger("nonPositiveInteger"), NonNegativeInteger("nonNegativeInteger"), PositiveInteger(
41-
"positiveInteger"), NegativeInteger("negativeInteger"), Double("double"), Float("float"), Boolean("boolean"), Duration("duration"), DayTimeDuration("dayTimeDuration"), YearMonthDuration("yearMonthDuration"), DateTime(
42-
"dateTime"), DateTimeStamp(
41+
"positiveInteger"), NegativeInteger("negativeInteger"), Double("double"), Float("float"), Boolean("boolean"), Duration("duration"), DayTimeDuration("dayTimeDuration"), YearMonthDuration("yearMonthDuration"), Date(
42+
"date"), DateTime("dateTime"), DateTimeStamp(
4343
"dateTimeStamp"), GDay("gDay"), GMonth("gMonth"), GMonthDay("gMonthDay"), GYear("gYear"), GYearMonth("gYearMonth"), QName("qName"), None("none"), AnyType("anyType"), AnySimpleType("anySimpleType");
4444

4545
private String standardizedLiteral;

src/main/java/org/eclipse/basyx/submodel/metamodel/map/submodelelement/dataelement/property/valuetype/ValueTypeHelper.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,12 @@ public static ValueType getType(Object obj) {
9696
} else if (c == long.class || c == Long.class) {
9797
objectType = ValueType.Int64;
9898
} else if (c == BigInteger.class) {
99-
BigInteger tmp = (BigInteger) obj;
100-
if (tmp.compareTo(new BigInteger("0")) > 0) {
101-
objectType = ValueType.PositiveInteger;
102-
} else if (tmp.compareTo(new BigInteger("0")) < 0) {
103-
objectType = ValueType.NegativeInteger;
104-
} else {
105-
objectType = ValueType.Integer;
106-
}
107-
99+
objectType = handleBigInteger((BigInteger) obj);
108100
} else if (c == void.class || c == Void.class) {
109101
objectType = ValueType.None;
110102
} else if (c == boolean.class || c == Boolean.class) {
111103
objectType = ValueType.Boolean;
112104
} else if (c == float.class || c == Float.class) {
113-
// TODO C# deprecated due to new serialization
114105
objectType = ValueType.Float;
115106
} else if (c == double.class || c == Double.class) {
116107
objectType = ValueType.Double;
@@ -131,6 +122,16 @@ public static ValueType getType(Object obj) {
131122
return objectType;
132123
}
133124

125+
private static ValueType handleBigInteger(BigInteger integer) {
126+
if (integer.compareTo(new BigInteger("0")) > 0) {
127+
return ValueType.PositiveInteger;
128+
} else if (integer.compareTo(new BigInteger("0")) < 0) {
129+
return ValueType.NegativeInteger;
130+
} else {
131+
return ValueType.Integer;
132+
}
133+
}
134+
134135
/**
135136
* Map the PropertyValueType to Java type
136137
*
@@ -228,6 +229,7 @@ public static Object getJavaObject(Object value, ValueType objType) {
228229
case YearMonthDuration:
229230
target = Period.parse((String) value);
230231
break;
232+
case Date:
231233
case DateTime:
232234
case DateTimeStamp:
233235
case GDay:

src/main/java/org/eclipse/basyx/submodel/metamodel/map/submodelelement/operation/OperationVariable.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.eclipse.basyx.submodel.metamodel.api.qualifier.haskind.ModelingKind;
3131
import org.eclipse.basyx.submodel.metamodel.api.submodelelement.ISubmodelElement;
3232
import org.eclipse.basyx.submodel.metamodel.api.submodelelement.operation.IOperationVariable;
33+
import org.eclipse.basyx.submodel.metamodel.facade.SubmodelElementMapCollectionConverter;
3334
import org.eclipse.basyx.submodel.metamodel.facade.submodelelement.SubmodelElementFacadeFactory;
3435
import org.eclipse.basyx.submodel.metamodel.map.modeltype.ModelType;
3536
import org.eclipse.basyx.submodel.metamodel.map.qualifier.haskind.HasKind;
@@ -114,7 +115,19 @@ public void setValue(ISubmodelElement value) {
114115
logger.warn("Modeling kind of Operation variable was wrong and automatically changed to ModelingKind.TEMPLATE");
115116
HasKind.createAsFacade((Map<String, Object>) value).setKind(ModelingKind.TEMPLATE);
116117
}
117-
put(Property.VALUE, value);
118+
119+
Object valueToSet = preprocessValue(value);
120+
121+
put(Property.VALUE, valueToSet);
122+
123+
}
124+
125+
private Object preprocessValue(ISubmodelElement value) {
126+
if (value instanceof SubmodelElement) {
127+
return SubmodelElementMapCollectionConverter.smElementToMap((SubmodelElement) value);
128+
} else {
129+
return value;
130+
}
118131
}
119132

120133
@SuppressWarnings("unchecked")

src/main/java/org/eclipse/basyx/vab/protocol/http/connector/OAuth2ClientCredentialsBasedAuthorizationSupplier.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,28 @@
2424
******************************************************************************/
2525
package org.eclipse.basyx.vab.protocol.http.connector;
2626

27-
import java.text.ParseException;
28-
import java.util.Date;
29-
import java.util.HashSet;
30-
import java.util.Optional;
31-
import java.util.Set;
32-
import java.util.concurrent.atomic.AtomicReference;
33-
34-
import javax.ws.rs.client.Client;
35-
import javax.ws.rs.client.Entity;
36-
import javax.ws.rs.core.Form;
37-
import javax.ws.rs.core.Response;
38-
27+
import com.google.gson.JsonElement;
28+
import com.google.gson.JsonParseException;
29+
import com.google.gson.JsonParser;
30+
import com.nimbusds.jwt.JWT;
31+
import com.nimbusds.jwt.JWTParser;
3932
import org.apache.commons.lang3.StringUtils;
4033
import org.glassfish.jersey.client.JerseyClientBuilder;
4134
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
4235
import org.slf4j.Logger;
4336
import org.slf4j.LoggerFactory;
4437
import org.springframework.lang.Nullable;
4538

46-
import com.google.gson.JsonElement;
47-
import com.google.gson.JsonParser;
48-
import com.nimbusds.jwt.JWT;
49-
import com.nimbusds.jwt.JWTParser;
39+
import javax.ws.rs.client.Client;
40+
import javax.ws.rs.client.Entity;
41+
import javax.ws.rs.core.Form;
42+
import javax.ws.rs.core.Response;
43+
import java.text.ParseException;
44+
import java.util.Date;
45+
import java.util.HashSet;
46+
import java.util.Optional;
47+
import java.util.Set;
48+
import java.util.concurrent.atomic.AtomicReference;
5049

5150
/**
5251
* Supplier for Bearer Token based HTTP Authorization request header values
@@ -153,13 +152,26 @@ private JWT getFreshAccessToken() {
153152
}
154153

155154
private Response requestToken() {
156-
return this.client.target(this.tokenEndpoint).request().post(Entity.form(new Form().param("grant_type", "client_credentials").param("scope", String.join(SCOPE_DELIMITER, this.scopes))));
155+
Form form = new Form().param("grant_type", "client_credentials");
156+
157+
// leave out scope parameter if there are no scopes, which is valid according to
158+
// the RFC, otherwise the server might return an error
159+
if (!scopes.isEmpty()) {
160+
form = form.param("scope", String.join(SCOPE_DELIMITER, this.scopes));
161+
}
162+
163+
return this.client.target(this.tokenEndpoint).request().post(Entity.form(form));
157164
}
158165

159166
@SuppressWarnings("deprecation")
160167
private String getAccessTokenFromResponse(final Response response) {
161168
final String responseString = response.readEntity(String.class);
162-
final JsonElement responseEl = jsonParser.parse(responseString);
163-
return responseEl.getAsJsonObject().get("access_token").getAsString();
169+
try {
170+
final JsonElement responseEl = jsonParser.parse(responseString);
171+
return responseEl.getAsJsonObject().get("access_token").getAsString();
172+
} catch (final JsonParseException e) {
173+
logger.error("server did not return a parseable json but instead: {}", responseString);
174+
throw e;
175+
}
164176
}
165177
}

0 commit comments

Comments
 (0)