Skip to content

Instantly share code, notes, and snippets.

@jwmatthews
Created February 12, 2025 18:58
Show Gist options
  • Save jwmatthews/d6b3cf17c29cac8c4600ee72a65fe630 to your computer and use it in GitHub Desktop.
Save jwmatthews/d6b3cf17c29cac8c4600ee72a65fe630 to your computer and use it in GitHub Desktop.
Message-0
================================ System Message ================================
You are an experienced java developer, who specializes in migrating code from java-ee to quarkus
Message-1
================================ Human Message =================================
I will give you a java-ee file for which I want to take one step towards migrating to quarkus.
I will provide you with static source code analysis information highlighting an issue which needs to be addressed.
Fix all the issues described. Other problems will be solved in subsequent steps so it is unnecessary to handle them now.
Before attempting to migrate the code to quarkus reason through what changes are required and why.
Pay attention to changes you make and impacts to external dependencies in the pom.xml as well as changes to imports we need to consider.
Remember when updating or adding annotations that the class must be imported.
As you make changes that impact the pom.xml or imports, be sure you explain what needs to be updated.
After you have shared your step by step thinking, provide a full output of the updated file.
# Input information
## Input File
File name: "InventoryNotificationMDB.java"
Source file contents:
```java
package com.redhat.coolstore.service;
import com.redhat.coolstore.model.Order;
import com.redhat.coolstore.utils.Transformers;
import javax.inject.Inject;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import java.util.Hashtable;
import java.util.logging.Logger;
public class InventoryNotificationMDB implements MessageListener {
private static final int LOW_THRESHOLD = 50;
@Inject
private CatalogService catalogService;
@Inject
private Logger log;
private final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private final static String JMS_FACTORY = "TCF";
private final static String TOPIC = "topic/orders";
private TopicConnection tcon;
private TopicSession tsession;
private TopicSubscriber tsubscriber;
public void onMessage(Message rcvMessage) {
TextMessage msg;
{
try {
System.out.println("received message inventory");
if (rcvMessage instanceof TextMessage) {
msg = (TextMessage) rcvMessage;
String orderStr = msg.getBody(String.class);
Order order = Transformers.jsonToOrder(orderStr);
order.getItemList().forEach(orderItem -> {
int old_quantity = catalogService.getCatalogItemById(orderItem.getProductId()).getInventory().getQuantity();
int new_quantity = old_quantity - orderItem.getQuantity();
if (new_quantity < LOW_THRESHOLD) {
System.out.println("Inventory for item " + orderItem.getProductId() + " is below threshold (" + LOW_THRESHOLD + "), contact supplier!");
} else {
orderItem.setQuantity(new_quantity);
}
});
}
} catch (JMSException jmse) {
System.err.println("An exception occurred: " + jmse.getMessage());
}
}
}
public void init() throws NamingException, JMSException {
Context ctx = getInitialContext();
TopicConnectionFactory tconFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY), TopicConnectionFactory.class);
tcon = tconFactory.createTopicConnection();
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(TOPIC), Topic.class);
tsubscriber = tsession.createSubscriber(topic);
tsubscriber.setMessageListener(this);
tcon.start();
}
public void close() throws JMSException {
tsubscriber.close();
tsession.close();
tcon.close();
}
private static InitialContext getInitialContext() throws NamingException {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
env.put("weblogic.jndi.createIntermediateContexts", "true");
return new InitialContext(env);
}
}
```
## Issues
### incident 0
incident to fix: "References to JavaEE/JakartaEE JMS elements should be removed and replaced with their Quarkus SmallRye/Microprofile equivalents."
Line number: 7
# Output Instructions
Structure your output in Markdown format such as:
## Reasoning
Write the step by step reasoning in this markdown section. If you are unsure of a step or reasoning, clearly state you are unsure and why.
## Updated java File
```java
// Write the updated file in this section. If the file should be removed, make the content of the updated file a comment explaining it should be removed.
```
## Additional Information (optional)
If you have any additional details or steps that need to be performed, put it here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment