Skip to content

Commit

Permalink
fix(servlet): complete migration javax to jakarta
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
GMishx authored and heliocastro committed Oct 17, 2024
1 parent 5deda24 commit 69fcc6c
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 64 deletions.
6 changes: 5 additions & 1 deletion backend/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>

<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>${jakarta.activation-api.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [email protected]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.eclipse.sw360.projects.Sw360ThriftServlet;

import java.io.IOException;
import java.net.MalformedURLException;

/**
* Thrift Servlet instantiation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<version>${jakarta.mail-api.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.apache.thrift.protocol.TCompactProtocol;

import java.io.IOException;
import java.net.MalformedURLException;


/**
* Thrift Servlet instantiation
Expand All @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions clients/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
<artifactId>wiremock-jre8</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet-api.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions clients/http-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet-api.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public <T> int getDocumentCount(@NotNull Class<T> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public Set<String> queryForIds(String queryName, String key) {

public Set<String> queryForIdsAsComplexValue(String queryName, String... keys) {
PostViewOptions query = connector.getPostViewQueryBuilder(type, queryName)
.keys(Arrays.asList(keys)).build();
.keys(Collections.singletonList(keys)).build();
return queryForIds(query);
}

Expand Down
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<!-- Build version properties -->
<java_source.version>21</java_source.version>
<java_target.version>21</java_target.version>
<java_release.version>21</java_release.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -115,8 +116,9 @@
<httpcore5.version>5.2.5</httpcore5.version>
<jakarta-xml-bind.version>4.0.2</jakarta-xml-bind.version>
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
<javax-activation.version>1.1.1</javax-activation.version>
<javax-annotation.version>1.3.2</javax-annotation.version>
<jakarta.annotation-api.version>3.0.0</jakarta.annotation-api.version>
<jakarta.activation-api.version>2.0.1</jakarta.activation-api.version>
<jakarta.mail-api.version>2.0.1</jakarta.mail-api.version>
<jaxen.version>2.0.0</jaxen.version>
<jcip-annotations.version>1.0</jcip-annotations.version>
<jcraft.version>0.1.54</jcraft.version>
Expand Down Expand Up @@ -196,11 +198,10 @@
<artifactId>packageurl-java</artifactId>
<version>${package-url.version}</version>
</dependency>
<!-- javax.annotation: java 11 compatibility -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation.version}</version>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation-api.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -352,9 +353,9 @@
<version>${httpclient5.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>${jakarta.activation-api.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down Expand Up @@ -662,6 +663,7 @@
<configuration>
<source>${java_source.version}</source>
<target>${java_target.version}</target>
<release>${java_release.version}</release>
<parameters>true</parameters>
</configuration>
</plugin>
Expand Down
5 changes: 3 additions & 2 deletions rest/authorization-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation-api.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions rest/resource-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,9 @@
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${javax-activation.version}</version>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta.annotation-api.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -81,7 +77,7 @@ public Map<String, Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,22 @@
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;
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
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;
Expand All @@ -84,8 +76,6 @@ public class Sw360ReleaseService implements AwareOfRestServices<Release> {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 69fcc6c

Please sign in to comment.