Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Enabling Byteman Script with Red Hat JBoss Fuse and AMQ - Part 2

January 18, 2018
Chandra Shekhar Pandey
Related topics:
JavaDeveloper ToolsMicroservices
Related products:
Streams for Apache KafkaRed Hat Fuse

Share:

    In my previous article, Enabling Byteman Script with Red Hat JBoss Fuse and AMQ - Part 1, we found a basic use-case for Byteman scripts with Red Hat JBoss Fuse or Red Hat JBoss AMQ. However, the log file was generated separately and only limited operations were possible. In this article I will show you how to use a Java helper class. By using Java, we get advanced operations to view or modify the content. Also, using java.util.logging allows us to log the statements to fuse.log, avoiding the creation of any other log file.

    Most of the steps are the same as my previous article, except for the Helper class. For completeness, I am including all the steps.

    1. Download Byteman binary from downloads.jboss.org/byteman. I download version 3.0.10.

    2. Extract it in the same machine where Red Hat JBoss Fuse exists.

    3. Once extracted, create a text file (byteman script) script.btm file at location /path/to/byteman-download-3.0.10. Here byteman-download-3.0.10 is in the folder created after extracting binary. Content of this script:

    HELPER com.myexample.helper.BytemanHelper
    RULE check authpassword
    CLASS org.apache.karaf.management.JaasAuthenticator
    METHOD authenticate(java.lang.Object)
    BIND msg = $1
    AT ENTRY
    IF TRUE
    DO
    helperMethod(msg);
    ENDRULE
    

    Points to note here.

    • We are using a helper class:
      com.myexample.helper.BytemanHelper.
    • This class is a simple java class which extends:
      org.jboss.byteman.rule.helper.Helper.
    • We have a method 'helperMethod' in this class, which we execute using this script.

    4. What we want to do here is have class:
    org.apache.karaf.management.JaasAuthenticator
    with method:
    public Subject authenticate(Object credentials).
    This method extracts the username and password from the credentials argument which is an Object type. In this method, the credentials are fetched from the String type.

    final String[] params = (String[]) credentials;

    In my previous article, I didn't find a way to achieve this using just the Byteman script.  Instead, I used a HELPER class so that using the Java provided utilities that I can modify or fetch details easily.

    5. Below is the content of BytemanHelper class. Here we have a helperMethod, which is invoked via Byteman script 'script.btm', which we created above. This method gets a String array from the Java Object and logs it.

    package com.myexample.helper;
    
    import java.util.logging.Logger;
    import org.jboss.byteman.rule.Rule;
    import org.jboss.byteman.rule.helper.Helper;
    
    public class BytemanHelper
    extends Helper
    {
    Logger logger;
    
    protected BytemanHelper(Rule rule)
    {
    super(rule);
    this.logger = Logger.getLogger(rule.getTriggerClass() + ":" + rule.getTriggerMethod());
    }
    
    public void helperMethod(Object object)
    {
    String[] params = (String[])object;
    this.logger.info("Byteman fetched username: " + params[0]);
    this.logger.info("Byteman fetched Password: " + params[1]);
    }
    }

     

    6. Now we have to create a Jar file with this class and the complete package structure. You can export the project as a Jar from your favorite IDE, I used Eclipse.  Or, you can easily create this from the terminal as well. Go to location of package in the project, I executed the following command within the src folder where my package com.myexample.helper exists.

    [cpandey@cpandey src]$ jar cvf BytemanFuseHelper.jar .

     

    7. Now edit ${karaf.home}/etc/config.properties and modify org.osgi.framework.bootdelegation property so that it also includes org.jboss.byteman package:

    org.osgi.framework.bootdelegation=org.apache.karaf.jaas.boot,org.apache.karaf.management.boot,sun.*,com.sun.*,javax.transaction,javax.transaction.*,javax.xml.crypto,javax.xml.crypto.*,org.apache.xerces.*,org.bouncycastle.*,com.ibm.security.*,org.apache.xalan.processor, org.jboss.byteman.*

     

    8. Now edit ${karaf.home}/bin/setenv (or setenv.bat for windows) and include JAVA_OPTS jvm argument as below. This argument refers to byteman jar and byteman script script.btm. Replace /path/to with path where byteman zip file is extracted.

    export JAVA_OPTS="-javaagent:/path/to/byteman-download-3.0.10/lib/byteman.jar=script:/path/to/byteman-download-3.0.10/script.btm,boot:/path/to/byteman-download-3.0.10/lib/byteman.jar,sys:/path/to/BytemanFuseHelper.jar -Dorg.jboss.byteman.verbose"

    Note: You have to add the path of the helper sys:/path/to/BytemanFuseHelper.jar jar as well with sys: prefix.

    9. To test, first start Red Hat JBoss Fuse using the start script:

    [cpandey@cpandey bin]$ pwd
    /path/to/jboss-fuse-6.3.0.redhat-310/bin
    [cpandey@cpandey bin]$ ./start

    10. Now start or stop the child container, check fuse.log in the root container where our modifications were done.

    11. Now check fuse.log. We should see the password entered in logs. We can now check that the user and password were updated.

    2018-01-01 12:22:33,429 | INFO | on(12)-127.0.0.1 | JaasAuthenticator:authenticate | - - | Byteman fetched username: admin
    2018-01-01 12:22:33,429 | INFO | on(12)-127.0.0.1 | JaasAuthenticator:authenticate | - - | Byteman fetched Password: cs1

     

    That's it, thank you for reading. I hope you now understand why we need a helper class and how it was different and better than the approach in my previous article.

    Last updated: January 19, 2018

    Recent Posts

    • Kubernetes MCP server: AI-powered cluster management

    • Unlocking the power of OpenShift Service Mesh 3

    • Run DialoGPT-small on OpenShift AI for internal model testing

    • Skopeo: The unsung hero of Linux container-tools

    • Automate certificate management in OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue