Skip to content

Commit

Permalink
Upgrade to Jakarta 10 and MicroProfile 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jwalcorn committed Apr 24, 2024
1 parent 7fdab3e commit a5462b7
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 86 deletions.
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,30 @@
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>8.0.0</version>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>4.1</version>
<version>6.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>3.6.1</version>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.20.0</version>
</dependency>
<dependency>
<groupId>io.jaegertracing</groupId>
Expand All @@ -73,7 +83,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.10</version>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -98,7 +108,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
<version>42.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -110,7 +120,7 @@
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
<version>8.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -135,7 +145,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<version>3.13.0</version>
<configuration>
<source>17</source>
<target>17</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2017-2021 IBM Corp, All Rights Reserved
Copyright 2023 Kyndryl, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,8 +38,8 @@
import javax.sql.DataSource;

//CDI 2.0
import javax.inject.Inject;
import javax.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.enterprise.context.RequestScoped;

//mpConfig 1.3
import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -53,39 +53,43 @@
import org.eclipse.microprofile.metrics.annotation.Counted;

//mpOpenTracing 1.3
import org.eclipse.microprofile.opentracing.Traced;
//import org.eclipse.microprofile.opentracing.Traced;

//mpOpenTelemetry
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;

//mpRestClient 1.3
import org.eclipse.microprofile.rest.client.inject.RestClient;

//Transactions
import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;
import jakarta.transaction.Transactional;
import jakarta.transaction.Transactional.TxType;

//JNDI 1.0
import javax.naming.InitialContext;
import javax.naming.NamingException;

//Servlet 4.0
import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

//JAX-RS 2.1 (JSR 339)
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.BadRequestException; //400 error
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.BadRequestException; //400 error
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.WebApplicationException;

@ApplicationPath("/")
@Path("/")
Expand Down Expand Up @@ -203,7 +207,7 @@ public Portfolio[] getPortfolios() throws SQLException {
@POST
@Path("/{owner}")
@Produces(MediaType.APPLICATION_JSON)
@Counted(name="portfolios", displayName="Stock Trader portfolios", description="Number of portfolios created in the Stock Trader application")
@Counted(name="portfolios", description="Number of portfolios created in the Stock Trader application")
@Transactional
// @RolesAllowed({"StockTrader"}) //Couldn't get this to work; had to do it through the web.xml instead :(
public Portfolio createPortfolio(@PathParam("owner") String owner, @QueryParam("accountID") String accountID) throws SQLException {
Expand Down Expand Up @@ -344,8 +348,9 @@ public Portfolio getPortfolio(@PathParam("owner") String owner, @QueryParam("imm
return portfolio;
}

@Traced
private Portfolio getPortfolioWithoutStocks(String owner) throws SQLException {
// @Traced
@WithSpan
private Portfolio getPortfolioWithoutStocks(@SpanAttribute("owner") String owner) throws SQLException {
Portfolio portfolio = null;

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017-2021 IBM Corp All Rights Reserved
Copyright 2017-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,10 +31,14 @@
import java.util.logging.Logger;

//mpOpenTracing 1.3
import org.eclipse.microprofile.opentracing.Traced;
//import org.eclipse.microprofile.opentracing.Traced;

//mpOpenTelemetry
import io.opentelemetry.instrumentation.annotations.WithSpan;
import io.opentelemetry.instrumentation.annotations.SpanAttribute;

//JSON-P 1.1 (JSR 353). This replaces my old usage of IBM's JSON4J (com.ibm.json.java.JSONObject)
import javax.json.JsonObject;
import jakarta.json.JsonObject;


public class PortfolioUtilities {
Expand All @@ -44,9 +49,9 @@ public class PortfolioUtilities {

/** Send a message to IBM Event Streams via the Kafka APIs */
/* TODO: Replace this with Emitter from mpReactiveMessaging 2.0 when it becomes available */
@Traced
void invokeKafka(Portfolio portfolio, String symbol, int shares, double commission, String kafkaAddress, String kafkaTopic) {
if ((kafkaAddress == null) || kafkaAddress.isEmpty()) {
@WithSpan
void invokeKafka(@SpanAttribute("portfolio") Portfolio portfolio, @SpanAttribute("symbol") String symbol, @SpanAttribute("shares") int shares, @SpanAttribute("commission") double commission, String kafkaAddress, String kafkaTopic) {
if ((kafkaAddress == null) || kafkaAddress.isEmpty()) {
logger.info("Kafka provider not configured, so not sending Kafka message about this stock trade");
return; //only do the following if Kafka is configured
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2017-2021 IBM Corp All Rights Reserved
Copyright 2017-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,14 +19,14 @@

import com.ibm.hybrid.cloud.sample.stocktrader.portfolio.json.Quote;

import javax.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.ApplicationScoped;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.Path;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2019 IBM Corp All Rights Reserved
Copyright 2019-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,10 +17,10 @@

package com.ibm.hybrid.cloud.sample.stocktrader.portfolio.dao;

import javax.enterprise.context.RequestScoped;
import jakarta.enterprise.context.RequestScoped;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.List;

import com.ibm.hybrid.cloud.sample.stocktrader.portfolio.json.Portfolio;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2019 IBM Corp All Rights Reserved
Copyright 2019-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,10 +17,10 @@

package com.ibm.hybrid.cloud.sample.stocktrader.portfolio.dao;

import javax.enterprise.context.RequestScoped;
import jakarta.enterprise.context.RequestScoped;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.List;

import com.ibm.hybrid.cloud.sample.stocktrader.portfolio.json.Stock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2019 IBM Corp All Rights Reserved
Copyright 2019-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +28,7 @@
import java.util.logging.Logger;

//CDI 2.0
import javax.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.ApplicationScoped;

//mpHealth 1.0
import org.eclipse.microprofile.health.HealthCheck;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2019 IBM Corp All Rights Reserved
Copyright 2019-2021 IBM Corp, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,7 +26,7 @@
import java.util.logging.Logger;

//CDI 2.0
import javax.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.ApplicationScoped;

//mpHealth 1.0
import org.eclipse.microprofile.health.HealthCheck;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2020-2021 IBM Corp, All Rights Reserved
Copyright 2023 Kyndryl, All Rights Reserved
Copyright 2023-2024 Kyndryl, All Rights Reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,20 +21,20 @@
import java.util.List;
import java.util.Iterator;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Id;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.json.JsonObject;
import javax.json.bind.annotation.JsonbTransient;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.persistence.Id;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.OneToMany;
import jakarta.json.JsonObject;
import jakarta.json.bind.annotation.JsonbTransient;

//JSON-P 1.0 (JSR 353). This replaces my old usage of IBM's JSON4J (com.ibm.json.java.JSONObject)
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import jakarta.json.Json;
import jakarta.json.JsonObjectBuilder;

@Entity
@Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.ibm.hybrid.cloud.sample.stocktrader.portfolio.json;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.Column;
import javax.persistence.ManyToOne;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Column;
import jakarta.persistence.ManyToOne;

@Entity
@Table
Expand Down
Loading

0 comments on commit a5462b7

Please sign in to comment.