Skip to content

Commit 21b6e77

Browse files
Fix ObjectMapper not picked up by conenctionProfilesManager
1 parent c4264f0 commit 21b6e77

File tree

7 files changed

+60
-198
lines changed

7 files changed

+60
-198
lines changed

pom.xml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
</build>
2727

2828
<repositories>
29-
<repository>
30-
<id>local-maven-repo</id>
31-
<url>file:///${project.basedir}/local-maven-repo</url>
32-
</repository>
3329
<repository>
3430
<id>jitpack.io</id>
3531
<url>https://jitpack.io</url>
@@ -68,9 +64,9 @@
6864
<version>${jersey.version}</version>
6965
</dependency>
7066
<dependency>
71-
<groupId>org.web3j</groupId>
72-
<artifactId>core</artifactId>
73-
<version>4.5.6</version>
67+
<groupId>org.glassfish.jersey.media</groupId>
68+
<artifactId>jersey-media-json-jackson</artifactId>
69+
<version>${jersey.version}</version>
7470
</dependency>
7571
<dependency>
7672
<groupId>com.github.TIHBS</groupId>
@@ -88,11 +84,7 @@
8884
<artifactId>jackson-core</artifactId>
8985
<version>${jackson.version}</version>
9086
</dependency>
91-
<dependency>
92-
<groupId>org.glassfish.jersey.media</groupId>
93-
<artifactId>jersey-media-json-jackson</artifactId>
94-
<version>${jersey.version}</version>
95-
</dependency>
87+
9688
<dependency>
9789
<groupId>org.apache.httpcomponents</groupId>
9890
<artifactId>httpclient</artifactId>
@@ -136,7 +128,7 @@
136128
<dependency>
137129
<groupId>org.junit.jupiter</groupId>
138130
<artifactId>junit-jupiter</artifactId>
139-
<version>RELEASE</version>
131+
<version>5.8.2</version>
140132
<scope>test</scope>
141133
</dependency>
142134
<dependency>

src/main/java/blockchains/iaas/uni/stuttgart/de/Permissions.java

Lines changed: 0 additions & 151 deletions
This file was deleted.

src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import java.util.List;
1313

1414
/********************************************************************************
15-
* Copyright (c) 2018 Institute for the Architecture of Application System -
15+
* Copyright (c) 2018-2023 Institute for the Architecture of Application System -
1616
* University of Stuttgart
1717
* Author: Ghareeb Falazi
18+
* Co-Author: Akshay Patel
1819
*
1920
* This program and the accompanying materials are made available under the
2021
* terms the Apache Software License 2.0
@@ -25,14 +26,19 @@
2526
@ApplicationPath("")
2627
public class Application extends ResourceConfig {
2728
public Application() {
29+
register(ObjectMapperProvider.class);
30+
register(JacksonFeature.class);
31+
packages("blockchains.iaas.uni.stuttgart.de");
32+
2833
// Required to load the plugins at startup
29-
BlockchainPluginManager blockchainPluginManager = BlockchainPluginManager.getInstance();
3034
if (Boolean.getBoolean("enablePluginsAtStart")) {
35+
BlockchainPluginManager blockchainPluginManager = BlockchainPluginManager.getInstance();
3136
blockchainPluginManager.startPlugins();
32-
}
33-
packages("blockchains.iaas.uni.stuttgart.de");
34-
register(ObjectMapperProvider.class);
35-
register(JacksonFeature.class);
37+
List<PluginWrapper> plugins = blockchainPluginManager.getPlugins(PluginState.STARTED);
3638

39+
for (PluginWrapper pluginWrapper : plugins) {
40+
blockchainPluginManager.registerConnectionProfileSubtypeClass(pluginWrapper.getPluginId());
41+
}
42+
}
3743
}
3844
}

src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2017 University of Stuttgart
2+
* Copyright 2017-2023 University of Stuttgart
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -33,13 +33,6 @@ public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
3333

3434
public ObjectMapperProvider() {
3535
defaultObjectMapper = createDefaultMapper();
36-
if (Boolean.getBoolean("enablePluginsAtStart")) {
37-
BlockchainPluginManager blockchainPluginManager = BlockchainPluginManager.getInstance();
38-
List<PluginWrapper> plugins = blockchainPluginManager.getPlugins(PluginState.STARTED);
39-
for (PluginWrapper pluginWrapper : plugins) {
40-
blockchainPluginManager.registerConnectionProfileSubtypeClass(defaultObjectMapper, pluginWrapper.getPluginId());
41-
}
42-
}
4336
}
4437

4538
@Override

src/main/java/blockchains/iaas/uni/stuttgart/de/connectionprofiles/ConnectionProfilesManager.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 Institute for the Architecture of Application System
2+
* Copyright (c) 2019-2023 Institute for the Architecture of Application System
33
* - University of Stuttgart
44
* Author: Ghareeb Falazi
55
* Co-author: Akshay Patel
@@ -17,14 +17,17 @@
1717
import java.nio.file.Path;
1818
import java.nio.file.Paths;
1919
import java.util.HashMap;
20+
import java.util.List;
2021
import java.util.Map;
2122

23+
import blockchains.iaas.uni.stuttgart.de.api.IAdapterExtension;
2224
import blockchains.iaas.uni.stuttgart.de.api.connectionprofiles.AbstractConnectionProfile;
2325
import com.fasterxml.jackson.core.JsonProcessingException;
2426
import com.fasterxml.jackson.core.type.TypeReference;
2527
import com.fasterxml.jackson.databind.ObjectMapper;
2628
import com.fasterxml.jackson.databind.ObjectReader;
2729
import com.fasterxml.jackson.databind.ObjectWriter;
30+
import com.fasterxml.jackson.databind.jsontype.NamedType;
2831
import org.slf4j.Logger;
2932
import org.slf4j.LoggerFactory;
3033

@@ -38,16 +41,12 @@ public class ConnectionProfilesManager {
3841
private static ConnectionProfilesManager instance;
3942
private ConnectionProfileListener listener;
4043

41-
private Map<String, AbstractConnectionProfile> connectionProfilesMap;
42-
private ObjectReader reader;
43-
private ObjectWriter writer;
44+
45+
private final Map<String, AbstractConnectionProfile> connectionProfilesMap;
46+
private static final ObjectMapper mapper = new ObjectMapper();
4447

4548
private ConnectionProfilesManager() {
4649
this.connectionProfilesMap = new HashMap<>();
47-
this.reader = new ObjectMapper().readerFor(new TypeReference<Map<String, AbstractConnectionProfile>>() {
48-
});
49-
this.writer = new ObjectMapper().writerFor(new TypeReference<Map<String, AbstractConnectionProfile>>() {
50-
});
5150
}
5251

5352
public Map<String, AbstractConnectionProfile> getConnectionProfiles() {
@@ -56,7 +55,9 @@ public Map<String, AbstractConnectionProfile> getConnectionProfiles() {
5655

5756

5857
public String getConnectionProfilesAsJson() throws JsonProcessingException {
59-
return this.writer.writeValueAsString(this.connectionProfilesMap);
58+
ObjectWriter writer = mapper.writerFor(new TypeReference<Map<String, AbstractConnectionProfile>>() {
59+
});
60+
return writer.writeValueAsString(this.connectionProfilesMap);
6061
}
6162

6263
/**
@@ -82,7 +83,9 @@ public void resetConnectionProfiles() {
8283

8384
public void loadConnectionProfilesFromFile(File file) {
8485
try {
85-
Map<String, AbstractConnectionProfile> newMap = this.reader.readValue(file);
86+
ObjectReader reader = mapper.readerFor(new TypeReference<Map<String, AbstractConnectionProfile>>() {
87+
});
88+
Map<String, AbstractConnectionProfile> newMap = reader.readValue(file);
8689
this.loadConnectionProfiles(newMap);
8790
} catch (IOException e) {
8891
log.error("Failed to load connection profiles from the file!", e);
@@ -91,6 +94,8 @@ public void loadConnectionProfilesFromFile(File file) {
9194

9295
public void loadConnectionProfilesFromJson(String jsonString) {
9396
try {
97+
ObjectReader reader = mapper.readerFor(new TypeReference<Map<String, AbstractConnectionProfile>>() {
98+
});
9499
Map<String, AbstractConnectionProfile> newMap = reader.readValue(jsonString);
95100
this.loadConnectionProfiles(newMap);
96101
} catch (IOException e) {
@@ -111,6 +116,10 @@ public void setListener(ConnectionProfileListener listener) {
111116
this.listener = listener;
112117
}
113118

119+
public static void registerConnectionProfileSubtypeClass(Class<? extends AbstractConnectionProfile> clazz, String typeName) {
120+
mapper.registerSubtypes(new NamedType(clazz, typeName));
121+
}
122+
114123
/**
115124
* Should only be used for testing purposes!
116125
*/

src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainPluginManager.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/********************************************************************************
2-
* Copyright (c) 2022 Institute for the Architecture of Application System -
2+
* Copyright (c) 2022-2023 Institute for the Architecture of Application System -
33
* University of Stuttgart
44
* Author: Akshay Patel
5+
* Co-Author: Ghareeb Falazi
56
*
67
* This program and the accompanying materials are made available under the
78
* terms the Apache Software License 2.0
@@ -14,6 +15,7 @@
1415
import blockchains.iaas.uni.stuttgart.de.Constants;
1516
import blockchains.iaas.uni.stuttgart.de.api.IAdapterExtension;
1617

18+
import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager;
1719
import com.fasterxml.jackson.databind.ObjectMapper;
1820
import com.fasterxml.jackson.databind.jsontype.NamedType;
1921
import org.pf4j.DefaultPluginManager;
@@ -27,7 +29,9 @@
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
2931

32+
import javax.inject.Singleton;
3033
import java.nio.file.Path;
34+
import java.nio.file.Paths;
3135
import java.util.List;
3236

3337
public class BlockchainPluginManager{
@@ -38,6 +42,8 @@ public class BlockchainPluginManager{
3842
private static BlockchainPluginManager instance = null;
3943

4044
private BlockchainPluginManager() {
45+
String property = System.getProperty("pf4j.pluginsDir");
46+
Path PLUGINS_DIRECTORY = Paths.get(property);
4147
this.pluginManager = new DefaultPluginManager(Constants.PLUGINS_DIRECTORY) {
4248
//
4349
@Override
@@ -112,11 +118,11 @@ public PluginState getPluginState(String pluginId) {
112118
return pluginManager.getPlugin(pluginId).getPluginState();
113119
}
114120

115-
public void registerConnectionProfileSubtypeClass(ObjectMapper objectMapper, String pluginId) {
121+
public void registerConnectionProfileSubtypeClass(String pluginId) {
116122
List<IAdapterExtension> adapterExtensions = this.pluginManager.getExtensions(IAdapterExtension.class, pluginId);
117123
for (IAdapterExtension adapterExtension : adapterExtensions) {
118124
String namedType = adapterExtension.getConnectionProfileNamedType();
119-
objectMapper.registerSubtypes(new NamedType(adapterExtension.getConnectionProfileClass(), namedType));
125+
ConnectionProfilesManager.registerConnectionProfileSubtypeClass(adapterExtension.getConnectionProfileClass(), namedType);
120126
}
121127
}
122128
}

0 commit comments

Comments
 (0)