Skip to content

Commit

Permalink
Jt400: possible missing resource in the native
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Apr 23, 2024
1 parent 90df987 commit a0d3fe1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.ListResourceBundle;
import java.util.regex.Pattern;

import com.ibm.as400.access.AS400;
Expand All @@ -29,6 +30,7 @@
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
Expand All @@ -41,6 +43,7 @@ class Jt400Processor {
private static final Logger LOG = Logger.getLogger(Jt400Processor.class);
private static final String FEATURE = "camel-jt400";
private static final DotName CONV_TABLE_NAME = DotName.createSimple(ConvTable.class.getName());
private static final DotName LIST_RESOURCE_BUNDLE_NAME = DotName.createSimple(ListResourceBundle.class.getName());

@BuildStep
FeatureBuildItem feature() {
Expand Down Expand Up @@ -86,6 +89,17 @@ void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses

}

@BuildStep
void resourceBundles(BuildProducer<NativeImageResourceBundleBuildItem> imageResourceBundles,
CombinedIndexBuildItem combinedIndex) {
IndexView index = combinedIndex.getIndex();

index.getAllKnownSubclasses(LIST_RESOURCE_BUNDLE_NAME).stream()
.filter(cl -> cl.name().toString().startsWith("com.ibm.as400"))
.map(c -> new NativeImageResourceBundleBuildItem(c.name().toString()))
.forEach(imageResourceBundles::produce);
}

@BuildStep
IndexDependencyBuildItem registerDependencyForIndex() {
return new IndexDependencyBuildItem("net.sf.jt400", "jt400", "java11");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.jt400.Jt400Component;
import org.apache.camel.component.jt400.Jt400Endpoint;
import org.eclipse.microprofile.config.inject.ConfigProperty;

Expand Down Expand Up @@ -169,13 +170,21 @@ public Response stopRoute(@PathParam("route") String routeName) throws Exception
}
boolean resp = context.getRouteController().getRouteStatus(routeName).isStopped();

//stop component to avoid CPF2451 Message queue REPLYMSGQ is allocated to another job.
Jt400Endpoint jt400Endpoint = context.getEndpoint(getUrlForLibrary(jt400MessageReplyToQueue), Jt400Endpoint.class);
jt400Endpoint.close();

return Response.ok().entity(resp).build();
}

@Path("/component/stopWrong")
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response stopComponent() throws Exception {
Jt400Component comp = context.getComponent("jt400", Jt400Component.class);
comp.close();
//this second call to close connection won't wprk, because the connection pool is already closing
//the call would need to read from a resource bundle therefore it covers existence of resource bundle in the native
comp.getConnectionPool().close();
return Response.ok().build();
}

@Path("/inquiryMessageSetExpected")
@POST
public void inquiryMessageSetExpected(String msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ public void testInquiryMessageQueue() throws Exception {
LOGGER.debug("testInquiryMessageQueue: reply message confirmed by peek: " + replyMsg);
}

/**
* Test for existence of resource bundle.
* If the bundle is not loaded properly, the close of connection pool would fail
* (see mor information in the resource method)
*
* @throws Exception
*/
@Test
public void testMissingResourceBundle() throws Exception {
//stop component and then stop connectionPool, which is already stoppingm therefore requires resourceBundle to show the failure reason
RestAssured.get("/jt400/component/stopWrong")
.then()
.statusCode(200);
}

@Test
public void testProgramCall() {
RestAssured.given()
Expand Down

0 comments on commit a0d3fe1

Please sign in to comment.