Change semantic of DmfMessageConverter trustedPackages -> trustedPackages ext (#3144)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -9,8 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.amqp;
|
package org.eclipse.hawkbit.amqp;
|
||||||
|
|
||||||
import static org.eclipse.hawkbit.dmf.DmfMessageConverter.DMF_JSON_MODEL_PACKAGE;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -52,6 +50,7 @@ import org.springframework.context.annotation.PropertySource;
|
|||||||
import org.springframework.core.retry.RetryPolicy;
|
import org.springframework.core.retry.RetryPolicy;
|
||||||
import org.springframework.core.retry.RetryTemplate;
|
import org.springframework.core.retry.RetryTemplate;
|
||||||
import org.springframework.util.ErrorHandler;
|
import org.springframework.util.ErrorHandler;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
import tools.jackson.databind.json.JsonMapper;
|
import tools.jackson.databind.json.JsonMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,8 +98,12 @@ public class DmfApiConfiguration {
|
|||||||
@ConditionalOnMissingBean(name = "dmfMessageConverter") // override it if needed to add / edit trusted packages or need other customization
|
@ConditionalOnMissingBean(name = "dmfMessageConverter") // override it if needed to add / edit trusted packages or need other customization
|
||||||
public MessageConverter dmfMessageConverter(
|
public MessageConverter dmfMessageConverter(
|
||||||
final JsonMapper jsonMapper,
|
final JsonMapper jsonMapper,
|
||||||
@Value("${hawkbit.dmf.trusted-packages:" + DMF_JSON_MODEL_PACKAGE + "}") final String trustedPackages) {
|
@Value("${hawkbit.dmf.trusted-packages:}") final String trustedPackages) {
|
||||||
return new DmfMessageConverter(jsonMapper, Arrays.stream(trustedPackages.split(",")).map(String::trim).toArray(String[]::new));
|
return new DmfMessageConverter(
|
||||||
|
jsonMapper,
|
||||||
|
ObjectUtils.isEmpty(trustedPackages)
|
||||||
|
? new String[0]
|
||||||
|
: Arrays.stream(trustedPackages.split(",")).map(String::trim).toArray(String[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.dmf;
|
package org.eclipse.hawkbit.dmf;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.jspecify.annotations.NonNull;
|
import org.jspecify.annotations.NonNull;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
@@ -22,14 +25,33 @@ import tools.jackson.databind.json.JsonMapper;
|
|||||||
// empty payload is empty byte[] and not try to convert it to Object (which fail since it is not JSON)
|
// empty payload is empty byte[] and not try to convert it to Object (which fail since it is not JSON)
|
||||||
public class DmfMessageConverter extends JacksonJsonMessageConverter {
|
public class DmfMessageConverter extends JacksonJsonMessageConverter {
|
||||||
|
|
||||||
public static final String DMF_JSON_MODEL_PACKAGE = "org.eclipse.hawkbit.dmf.json.model";
|
private static final String DMF_JSON_MODEL_PACKAGE = "org.eclipse.hawkbit.dmf.json.model";
|
||||||
|
|
||||||
public DmfMessageConverter(final String... trustedPackages) {
|
/**
|
||||||
this(new JsonMapper(), trustedPackages);
|
* Constructor unsing default {@link JsonMapper}, i.e. <code>new JsonMapper()</code>
|
||||||
|
*
|
||||||
|
* @param trustedPackagesExt {@link DmfMessageConverter} always trust {@link #DMF_JSON_MODEL_PACKAGE}. If any additional packages
|
||||||
|
* shall be trusted provided here
|
||||||
|
*/
|
||||||
|
public DmfMessageConverter(final String... trustedPackagesExt) {
|
||||||
|
this(new JsonMapper(), trustedPackagesExt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DmfMessageConverter(final JsonMapper jsonMapper, final String... trustedPackages) {
|
/**
|
||||||
super(jsonMapper, trustedPackages.length == 0 ? new String[] { DMF_JSON_MODEL_PACKAGE } : trustedPackages);
|
* Constructor with specified {@link JsonMapper}
|
||||||
|
*
|
||||||
|
* @param jsonMapper the {@link JsonMapper} to use for conversion
|
||||||
|
* @param trustedPackagesExt {@link DmfMessageConverter} always trust {@link #DMF_JSON_MODEL_PACKAGE}. If any additional packages
|
||||||
|
* shall be trusted provided here
|
||||||
|
*/
|
||||||
|
public DmfMessageConverter(final JsonMapper jsonMapper, final String... trustedPackagesExt) {
|
||||||
|
super(
|
||||||
|
jsonMapper,
|
||||||
|
trustedPackagesExt == null || trustedPackagesExt.length == 0
|
||||||
|
? new String[] { DMF_JSON_MODEL_PACKAGE }
|
||||||
|
: Stream.concat(Stream.of(DMF_JSON_MODEL_PACKAGE), Arrays.stream(trustedPackagesExt))
|
||||||
|
.distinct()
|
||||||
|
.toArray(String[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user