From 69fcc6c9faf1326bfd2334cb22c157db984f171e Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Wed, 16 Oct 2024 22:15:38 +0530 Subject: [PATCH] fix(servlet): complete migration javax to jakarta Replace all `javax.*` dependencies with `jakarta.*` dependencies as Tomcat 11 completes the migration and servlets refuse to load. Did not migrate to latest jakarta-mail `2.1.3` as it throws error "No provider of jakarta.mail.util.StreamProvider was found". `2.0.1` is the latest version which works. Also, fix some compile warnings from Java 11. Signed-off-by: Gaurav Mishra --- backend/common/pom.xml | 6 +++++- .../java/org/eclipse/sw360/mail/MailUtil.java | 8 ++++---- .../sw360/components/ComponentServlet.java | 1 - .../fossology/rest/FossologyRestClient.java | 1 - backend/pom.xml | 6 +++--- .../sw360/projects/ProjectServlet.java | 4 +--- clients/client/pom.xml | 6 +++--- clients/http-support/pom.xml | 6 +++--- .../DatabaseConnectorCloudant.java | 2 +- .../DatabaseRepositoryCloudantClient.java | 2 +- pom.xml | 20 ++++++++++--------- rest/authorization-server/pom.xml | 5 +++-- ...Sw360CustomHeaderAuthenticationFilter.java | 2 +- ...360CustomHeaderAuthenticationProvider.java | 2 +- rest/resource-server/pom.xml | 11 +++------- .../Sw360DatabaseSanitationService.java | 6 +----- .../project/Sw360ProjectService.java | 2 +- .../release/Sw360ReleaseService.java | 10 ---------- .../vendor/Sw360VendorService.java | 8 ++------ 19 files changed, 44 insertions(+), 64 deletions(-) diff --git a/backend/common/pom.xml b/backend/common/pom.xml index 446488ccae..11bfa416a2 100644 --- a/backend/common/pom.xml +++ b/backend/common/pom.xml @@ -58,6 +58,10 @@ org.codehaus.plexus plexus-utils - + + jakarta.activation + jakarta.activation-api + ${jakarta.activation-api.version} + diff --git a/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java b/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java index 29ca213b10..5955c43eb3 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java +++ b/backend/common/src/main/java/org/eclipse/sw360/mail/MailUtil.java @@ -22,9 +22,9 @@ import org.eclipse.sw360.datahandler.thrift.projects.ClearingRequest; import org.eclipse.sw360.datahandler.thrift.users.User; -import javax.mail.*; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; +import jakarta.mail.*; +import jakarta.mail.internet.InternetAddress; +import jakarta.mail.internet.MimeMessage; import java.io.IOException; import java.util.Arrays; import java.util.IllegalFormatException; @@ -37,7 +37,7 @@ import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptySet; /** - * Provides the possiblity to send mail from SW360 + * Provides the possibility to send mail from SW360 * * @author birgit.heydenreich@tngtech.com */ diff --git a/backend/components/src/main/java/org/eclipse/sw360/components/ComponentServlet.java b/backend/components/src/main/java/org/eclipse/sw360/components/ComponentServlet.java index 5c2246ff8c..174be56449 100644 --- a/backend/components/src/main/java/org/eclipse/sw360/components/ComponentServlet.java +++ b/backend/components/src/main/java/org/eclipse/sw360/components/ComponentServlet.java @@ -14,7 +14,6 @@ import org.eclipse.sw360.projects.Sw360ThriftServlet; import java.io.IOException; -import java.net.MalformedURLException; /** * Thrift Servlet instantiation diff --git a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java index c6cf11f16e..b9b279e69d 100644 --- a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java +++ b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java @@ -103,7 +103,6 @@ public FossologyRestClient(ObjectMapper objectMapper, FossologyRestConfig restCo this.restConfig = restConfig; SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); - requestFactory.setBufferRequestBody(false); restTemplate.setRequestFactory(requestFactory); this.restTemplate = restTemplate; } diff --git a/backend/pom.xml b/backend/pom.xml index b8e5265e2d..b754835142 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -116,9 +116,9 @@ test - javax.mail - mail - 1.5.0-b01 + jakarta.mail + jakarta.mail-api + ${jakarta.mail-api.version} diff --git a/backend/projects/src/main/java/org/eclipse/sw360/projects/ProjectServlet.java b/backend/projects/src/main/java/org/eclipse/sw360/projects/ProjectServlet.java index cb2cdf73f7..089fc702ef 100644 --- a/backend/projects/src/main/java/org/eclipse/sw360/projects/ProjectServlet.java +++ b/backend/projects/src/main/java/org/eclipse/sw360/projects/ProjectServlet.java @@ -13,8 +13,6 @@ import org.apache.thrift.protocol.TCompactProtocol; import java.io.IOException; -import java.net.MalformedURLException; - /** * Thrift Servlet instantiation @@ -24,7 +22,7 @@ */ public class ProjectServlet extends Sw360ThriftServlet { - public ProjectServlet() throws MalformedURLException, IOException { + public ProjectServlet() throws IOException { // Create a service processor using the provided handler super(new ProjectService.Processor<>(new ProjectHandler()), new TCompactProtocol.Factory()); } diff --git a/clients/client/pom.xml b/clients/client/pom.xml index 704b57e823..e0e7216d5c 100644 --- a/clients/client/pom.xml +++ b/clients/client/pom.xml @@ -107,9 +107,9 @@ wiremock-jre8 - javax.servlet - javax.servlet-api - 4.0.1 + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} test diff --git a/clients/http-support/pom.xml b/clients/http-support/pom.xml index 3c406547c7..fc03df376a 100644 --- a/clients/http-support/pom.xml +++ b/clients/http-support/pom.xml @@ -79,9 +79,9 @@ test - javax.servlet - javax.servlet-api - 4.0.1 + jakarta.servlet + jakarta.servlet-api + ${jakarta.servlet-api.version} test diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java index ad3d705d7a..925bf2791c 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java @@ -398,7 +398,7 @@ public int getDocumentCount(@NotNull Class type, String viewName, String[ .db(this.dbName) .ddoc(type.getSimpleName()) .view(viewName) - .keys(Arrays.asList(keys)) + .keys(Collections.singletonList(keys)) .includeDocs(false) .group(true) .reduce(true) diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseRepositoryCloudantClient.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseRepositoryCloudantClient.java index 807e7b344d..a18fc9880f 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseRepositoryCloudantClient.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseRepositoryCloudantClient.java @@ -229,7 +229,7 @@ public Set queryForIds(String queryName, String key) { public Set queryForIdsAsComplexValue(String queryName, String... keys) { PostViewOptions query = connector.getPostViewQueryBuilder(type, queryName) - .keys(Arrays.asList(keys)).build(); + .keys(Collections.singletonList(keys)).build(); return queryForIds(query); } diff --git a/pom.xml b/pom.xml index e5213b1a31..de5f138382 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,7 @@ 21 21 + 21 21 21 UTF-8 @@ -115,8 +116,9 @@ 5.2.5 4.0.2 6.0.0 - 1.1.1 - 1.3.2 + 3.0.0 + 2.0.1 + 2.0.1 2.0.0 1.0 0.1.54 @@ -196,11 +198,10 @@ packageurl-java ${package-url.version} - - javax.annotation - javax.annotation-api - ${javax-annotation.version} + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation-api.version} com.google.guava @@ -352,9 +353,9 @@ ${httpclient5.version} - javax.activation - activation - 1.1.1 + jakarta.activation + jakarta.activation-api + ${jakarta.activation-api.version} com.google.code.gson @@ -662,6 +663,7 @@ ${java_source.version} ${java_target.version} + ${java_release.version} true diff --git a/rest/authorization-server/pom.xml b/rest/authorization-server/pom.xml index ea0f54dffe..33adeb3aad 100644 --- a/rest/authorization-server/pom.xml +++ b/rest/authorization-server/pom.xml @@ -110,8 +110,9 @@ jaxb-runtime - javax.annotation - javax.annotation-api + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation-api.version} org.springframework.restdocs diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java index 5201260342..ff2ae5fbca 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java @@ -11,7 +11,7 @@ import java.io.IOException; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.LogManager; diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java index ed6946aa23..df77d27855 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.Map; -import javax.annotation.PostConstruct; +import jakarta.annotation.PostConstruct; import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.LogManager; diff --git a/rest/resource-server/pom.xml b/rest/resource-server/pom.xml index 3c2762abde..613b4cc9a4 100644 --- a/rest/resource-server/pom.xml +++ b/rest/resource-server/pom.xml @@ -169,14 +169,9 @@ jaxb-runtime - javax.annotation - javax.annotation-api - ${javax-annotation.version} - - - javax.activation - activation - ${javax-activation.version} + jakarta.annotation + jakarta.annotation-api + ${jakarta.annotation-api.version} org.springframework.security.oauth.boot diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/databasesanitation/Sw360DatabaseSanitationService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/databasesanitation/Sw360DatabaseSanitationService.java index 9e0291b935..90f5630655 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/databasesanitation/Sw360DatabaseSanitationService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/databasesanitation/Sw360DatabaseSanitationService.java @@ -18,8 +18,6 @@ import java.util.List; import java.util.Map; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.protocol.TProtocol; @@ -33,7 +31,6 @@ import org.eclipse.sw360.datahandler.thrift.users.UserGroup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.security.access.AccessDeniedException; import org.springframework.stereotype.Service; @@ -44,7 +41,6 @@ @Slf4j @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class Sw360DatabaseSanitationService { - private static final Logger log = LogManager.getLogger(Sw360DatabaseSanitationService.class); @Value("${sw360.thrift-server-url:http://localhost:8080}") private String thriftServerUrl; @@ -81,7 +77,7 @@ public Map duplicateIdentifiers(User sw360User) throws TExceptio } else if (sw360Exp.getErrorCode() == 204) { throw new SW360Exception(sw360Exp.getMessage()).setErrorCode(204); } else { - log.error("No dulicate ids found: " + sw360Exp.getMessage()); + log.error("No duplicate ids found: {}", sw360Exp.getMessage()); } throw sw360Exp; } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java index 8e5f863adc..005449a57c 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/Sw360ProjectService.java @@ -77,7 +77,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import javax.annotation.PreDestroy; +import jakarta.annotation.PreDestroy; import java.util.ArrayList; import java.util.Collection; diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java index 515f0179b9..98a0dd7da4 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/release/Sw360ReleaseService.java @@ -35,15 +35,12 @@ import org.eclipse.sw360.datahandler.thrift.projects.Project; import org.eclipse.sw360.datahandler.thrift.projects.ProjectService; import org.eclipse.sw360.datahandler.thrift.users.User; -import org.eclipse.sw360.datahandler.thrift.vendors.VendorService; import org.eclipse.sw360.rest.resourceserver.Sw360ResourceServer; import org.eclipse.sw360.rest.resourceserver.attachment.Sw360AttachmentService; import org.eclipse.sw360.rest.resourceserver.core.AwareOfRestServices; import org.eclipse.sw360.rest.resourceserver.core.RestControllerHelper; import org.eclipse.sw360.rest.resourceserver.project.Sw360ProjectService; import org.eclipse.sw360.rest.resourceserver.license.Sw360LicenseService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.dao.DataIntegrityViolationException; @@ -51,14 +48,9 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.stereotype.Service; import org.springframework.util.FileCopyUtils; -import org.springframework.web.bind.annotation.ResponseStatus; -import com.google.common.collect.Sets; - -import static org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace; import static org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString; import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException; -import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -84,8 +76,6 @@ public class Sw360ReleaseService implements AwareOfRestServices { private final Sw360ProjectService projectService; private final Sw360LicenseService licenseService; - private final Logger log = LoggerFactory.getLogger(this.getClass()); - private static FossologyService.Iface fossologyClient; private static final String RESPONSE_STATUS_VALUE_COMPLETED = "Completed"; private static final String RESPONSE_STATUS_VALUE_FAILED = "Failed"; diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/vendor/Sw360VendorService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/vendor/Sw360VendorService.java index da599e613a..34bbce125a 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/vendor/Sw360VendorService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/vendor/Sw360VendorService.java @@ -12,14 +12,12 @@ import lombok.RequiredArgsConstructor; import org.apache.thrift.TException; -import org.apache.thrift.protocol.TCompactProtocol; -import org.apache.thrift.protocol.TProtocol; -import org.apache.thrift.transport.THttpClient; import org.apache.thrift.transport.TTransportException; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestStatus; import org.eclipse.sw360.datahandler.thrift.AddDocumentRequestSummary; import org.eclipse.sw360.datahandler.thrift.RequestStatus; +import org.eclipse.sw360.datahandler.thrift.ThriftClients; import org.eclipse.sw360.datahandler.thrift.users.User; import org.eclipse.sw360.datahandler.thrift.vendors.Vendor; import org.eclipse.sw360.datahandler.thrift.vendors.VendorService; @@ -131,9 +129,7 @@ public void deleteAllVendors(User sw360User) { } private VendorService.Iface getThriftVendorClient() throws TTransportException { - THttpClient thriftClient = new THttpClient(thriftServerUrl + "/vendors/thrift"); - TProtocol protocol = new TCompactProtocol(thriftClient); - return new VendorService.Client(protocol); + return new ThriftClients().makeVendorClient(); } public ByteBuffer exportExcel() throws TException {