Skip to content

Commit

Permalink
Fixes #6889 - jt400 - disables GUI interaction for the native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Jan 7, 2025
1 parent ea53e35 commit b4f8847
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
import com.ibm.as400.access.NLSImplNative;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem;
import io.quarkus.deployment.builditem.*;
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;
import io.quarkus.gizmo.Gizmo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.logging.Logger;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

class Jt400Processor {

Expand Down Expand Up @@ -105,4 +106,59 @@ IndexDependencyBuildItem registerDependencyForIndex() {
return new IndexDependencyBuildItem("net.sf.jt400", "jt400", "java11");
}

@BuildStep
BytecodeTransformerBuildItem patchToolboxSignonHandler() {
return new BytecodeTransformerBuildItem.Builder()
.setClassToTransform("com.ibm.as400.access.ToolboxSignonHandler")
.setCacheable(true)
.setVisitorFunction((className, classVisitor) -> new ToolboxSignonHandlerClassVisitor(classVisitor)).build();
}

/**
* ToolboxSignonHandler starts GUI dialogues from several methods. This is not supported in the native.
* Unfortunately the method AS400.isGuiAvailable does not disable every call to dialogue.
* Two methods `handleSignon` and `handlePasswordChange` has to be removed (they does not contain any logic,
* just the GUI interaction)
*/
static class ToolboxSignonHandlerClassVisitor extends ClassVisitor {

private final Logger logger;

protected ToolboxSignonHandlerClassVisitor(ClassVisitor classVisitor) {
super(Gizmo.ASM_API_VERSION, classVisitor);

logger = Logger.getLogger("ToolboxSignonHandlerClassVisitor");
}

@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature,
String[] exceptions) {
MethodVisitor original = super.visitMethod(access, name, descriptor, signature, exceptions);
if ("handleSignon".equals(name) || "handlePasswordChange".equals(name)) {
logger.debug("GUI interaction enhancer for Quarkus: transforming " + name + " to avoid spawning dialogues");
// Replace the method body
return new MethodVisitor(Gizmo.ASM_API_VERSION, original) {
@Override
public void visitCode() {
super.visitCode();
// Load 'true' or `false` onto the stack and return
if ("handlePasswordChange".equals(name)) {
visitInsn(Opcodes.ICONST_0); // push false
} else {
visitInsn(Opcodes.ICONST_1); // push true
}
visitInsn(Opcodes.IRETURN); // return boolean from the method
}

@Override
public void visitMaxs(int maxStack, int maxLocals) {
// Max stack is 1 (for the boolean), locals can remain unchanged
super.visitMaxs(1, 0);
}
};
}
return original;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public boolean isInPasswordExpirationWarningDays() throws AS400SecurityException
//skip verification, because it cen end with GUi dialog
return false;
}

@Substitute
//workaround because of https://github.com/apache/camel-quarkus/issues/6889
synchronized void signon(boolean keepConnection) throws AS400SecurityException, IOException {
throw new RuntimeException("Signon is not supported in the native mode.");
}
}

//even if gui is turned off, the presence of code in Dialogs, which references awt object, causes the java.lang.Thread
Expand Down

0 comments on commit b4f8847

Please sign in to comment.