Skip to content

Commit

Permalink
Merge pull request #2343 from telefonicaid/task/jdk_17
Browse files Browse the repository at this point in the history
fix errors to upgrade to JDK 17
  • Loading branch information
fgalan authored Feb 7, 2024
2 parents 3c8d596 + 3a82a74 commit 6812e81
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- 13
- 14
- 15
# - 16
# - 17
- 16
- 17
steps:
- name: Git checkout
uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
- [cygnus-ngsi] Upgrade mockito-core dep from 5.5.0 to 5.10.0
- [cygnus-ngsi-ld] Upgrade mockito-all 1.9.5 to mockito-core 5.10.0, httpcore from 4.3.1 to 4.4.16 and maven dependencies in general
- [cygnus-ngsi] Upgrade Java version from 1.11 to 1.17 in Dockerfile (#2297, #2304)
- [cygnus-common][cygnus-ngsi][cygnus-ngsi-ld] Upgrade in source code to support Java 17 build
- [cygnus-common] [Arcgis] All NGSI DateTime are translated to Millis from Epoch (esriFieldTypeDate) (#2339)
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.telefonica.iot.cygnus.management.PatternTypeAdapter;
import java.util.regex.Pattern;
import com.google.gson.GsonBuilder;

/**
*
* @author frb
*/
public final class NameMappingsHandlers {

private static final CygnusLogger LOGGER = new CygnusLogger(NameMappingsHandlers.class);

/**
Expand Down Expand Up @@ -69,7 +72,9 @@ private static NameMappings parseNameMappings(String jsonStr) {
} // if

// Parse the Json string
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();

try {
nameMappings = gson.fromJson(jsonStr, NameMappings.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2024 Telefonica Investigación y Desarrollo, S.A.U
*
* This file is part of fiware-cygnus (FI-WARE project).
*
* fiware-cygnus is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
* General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
* fiware-cygnus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License along with fiware-cygnus. If not, see
* http://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License please contact with iot_support at tid dot es
*/

package com.telefonica.iot.cygnus.management;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.regex.Pattern;

public class PatternTypeAdapter extends TypeAdapter<Pattern> {

@Override
public void write(JsonWriter out, Pattern pattern) throws IOException {
if (pattern == null) {
out.nullValue();
return;
}
out.value(pattern.pattern());
}

@Override
public Pattern read(JsonReader in) throws IOException {
String patternString = in.nextString();
return Pattern.compile(patternString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.telefonica.iot.cygnus.management;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.telefonica.iot.cygnus.backends.http.JsonResponse;
import com.telefonica.iot.cygnus.backends.orion.OrionBackendImpl;
Expand All @@ -26,8 +27,10 @@
import com.telefonica.iot.cygnus.containers.OrionEndpoint;
import com.telefonica.iot.cygnus.log.CygnusLogger;
import com.telefonica.iot.cygnus.utils.CommonConstants;
import com.telefonica.iot.cygnus.management.PatternTypeAdapter;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
Expand Down Expand Up @@ -117,7 +120,9 @@ public static void get(HttpServletRequest request, HttpServletResponse response)

// Get the endpoint string and parse it
String endpointStr = readPayload(request);
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
OrionEndpoint endpoint;

try {
Expand Down Expand Up @@ -276,7 +281,9 @@ public static void post(HttpServletRequest request, HttpServletResponse response
private static void postV1(String payload, String fiwareService, String fiwareServicePath,
HttpServletResponse response) throws IOException {
// Parse the payload
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
CygnusSubscriptionV1 cygnusSubscriptionv1;

try {
Expand Down Expand Up @@ -341,7 +348,9 @@ private static void postV1(String payload, String fiwareService, String fiwareSe
private static void postV2(String payload, String fiwareService, String fiwareServicePath,
HttpServletResponse response) throws IOException {
// Parse the payload
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
CygnusSubscriptionV2 cygnusSubscriptionv2;

try {
Expand Down
26 changes: 13 additions & 13 deletions cygnus-ngsi-ld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<dependencies>
<!-- Required for testing -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -32,7 +32,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.1</version>
<version>4.4.16</version>
</dependency>
<!-- Required for logging -->
<dependency>
Expand All @@ -54,7 +54,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.12.0</version>
</dependency>
<!-- Required by any agent -->
<dependency>
Expand All @@ -80,7 +80,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -91,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<version>3.5.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
Expand All @@ -101,7 +101,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<version>3.5.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assemblyCompile.xml</descriptor>
Expand All @@ -121,7 +121,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<version>3.1.0</version>
<executions>
<execution>
<phase>compile</phase>
Expand All @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.5.1</version>
<version>3.8.2</version>
<configuration>
<reportPlugins>
<plugin>
Expand All @@ -156,15 +156,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
<version>3.0.0</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.12</version>
<version>3.2.1</version>
<configuration>
<configLocation>telefonica_checkstyle.xml</configLocation>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
Expand All @@ -174,7 +174,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<version>3.5.0</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import java.util.regex.Pattern;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import org.json.JSONArray;
import org.json.JSONObject;

import com.telefonica.iot.cygnus.management.PatternTypeAdapter;

/**
*
Expand Down Expand Up @@ -141,7 +142,9 @@ public static class ContextElement {
* Constructor for Gson, a Json parser.
*/
public ContextElement(String contextElement) {
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
String cer = contextElement;
Map<String, Object> map = gson.fromJson(cer, new TypeToken<Map<String, JsonElement>>() {
}.getType());
Expand Down Expand Up @@ -238,4 +241,4 @@ public String toString() {

} // ContextElement

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.telefonica.iot.cygnus.handlers;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
Expand All @@ -27,7 +28,9 @@
import com.telefonica.iot.cygnus.log.CygnusLogger;
import com.telefonica.iot.cygnus.utils.CommonConstants;
import com.telefonica.iot.cygnus.utils.CommonUtils;
import com.telefonica.iot.cygnus.management.PatternTypeAdapter;
import java.io.BufferedReader;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -271,7 +274,9 @@ public List<Event> getEvents(javax.servlet.http.HttpServletRequest request) thro
// Parse the original data into a NotifyContextRequest object
JSONObject content = new JSONObject(data);
NotifyContextRequestLD notifyContextRequestLD = null;
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();

try {
notifyContextRequestLD = new NotifyContextRequestLD(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
package com.telefonica.iot.cygnus.sinks;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.telefonica.iot.cygnus.containers.NotifyContextRequestLD.ContextElement;
import com.telefonica.iot.cygnus.errors.*;
import com.telefonica.iot.cygnus.interceptors.NGSILDEvent;
import com.telefonica.iot.cygnus.log.CygnusLogger;
import com.telefonica.iot.cygnus.sinks.Enums.DataModel;
import com.telefonica.iot.cygnus.utils.CommonConstants;
import com.telefonica.iot.cygnus.utils.NGSIConstants;
import com.telefonica.iot.cygnus.management.PatternTypeAdapter;
import org.apache.flume.*;
import org.apache.flume.conf.Configurable;
import org.apache.log4j.MDC;
Expand All @@ -33,6 +35,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;

/**
*
Expand Down Expand Up @@ -497,7 +500,9 @@ private Status processNewBatches() {
} else {
// Event comes from file... original and mapped context elements must be re-created
String[] contextElementsStr = (new String(event.getBody())).split(CommonConstants.CONCATENATOR);
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
ContextElement originalCE = null;
ContextElement mappedCE = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package com.telefonica.iot.cygnus.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.telefonica.iot.cygnus.containers.NameMappings;
import com.telefonica.iot.cygnus.containers.NotifyContextRequestLD;
import java.util.HashMap;

import java.util.regex.Pattern;
import com.telefonica.iot.cygnus.interceptors.NGSILDEvent;
import com.telefonica.iot.cygnus.management.PatternTypeAdapter;
import org.apache.flume.Context;
import org.json.JSONObject;

Expand Down Expand Up @@ -98,7 +100,9 @@ public static Context createContextForOrion(String orionHost, String orionPort,
} // createContextForOrion

public static NotifyContextRequestLD createJsonNotifyContextRequestLD(String jsonStr) throws Exception {
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
return gson.fromJson(jsonStr, NotifyContextRequestLD.class);
} // createJsonNotifyContextRequest

Expand Down Expand Up @@ -132,7 +136,9 @@ public static NGSILDEvent createNGSIEventLD(String originalCEStr, String mappedC
* @throws java.lang.Exception
*/
public static NameMappings createJsonNameMappings(String jsonStr) throws Exception {
Gson gson = new Gson();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Pattern.class, new PatternTypeAdapter())
.create();
return gson.fromJson(jsonStr, NameMappings.class);
} // createJsonNameMappings

Expand Down
Loading

0 comments on commit 6812e81

Please sign in to comment.