Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.8.x] Jt400: possible missing resource in the native #6031

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,6 +41,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.jboss.logging.Logger;

Expand Down Expand Up @@ -157,4 +158,16 @@ public Response putMockResponse(
return Response.ok().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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public void testProgramCall() {
Matchers.containsString("par2")));
}

/**
* 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/mock/component/stopWrong")
.then()
.statusCode(200);
}

private void prepareMockReply(Jt400MockResource.ReplyType replyType,
Integer hashCode,
String senderInformation,
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
Loading