1. 2016-12-03 - Logrotate Java Application Logs; Tags: Logrotate Java Application Logs
    Loading...

    Logrotate Java Application Logs

    Running a professional Java EE application with JBoss EAP/Wildfly or any other application server involves a good housekeeping strategy for log files. Pay attention that most developers make the mistake to log information twice, hence in most scenarios the default texturation is kept. So the log information will be written into the console.log and server.log. Furthermore if you don’t use a files size rotator, the server.log will be rotated daily. The potential threat is, if you write the logs to separate SAN partition with limited disk space, you might crash the application, if he has no disk space left. To prevent this, one possibility is to use logrotate on Linux for the job.

    My applications run in the docker container. To prevent extreme disk usage, server.log and console.log is rotated when 2 GB is reached, 7 rotations mean that he keeps max 14 GB, after 3 days the log files are deleted.

    # file size rotation of server.log to prevent full disk space
    /var/log/docker/*/server.log {
            su root cinhtau
            # logrotate automatically by file size 2 GB
            size 2G
            create 0600 cinhtau cinhtau
            # keep only last 7 rotations
            rotate 7
            copytruncate
            compress
            missingok
            maxage 3
    }
    /var/log/docker/*/console.log {
            su root cinhtau
            # logrotate automatically by file size 2 GB
            size 2G
            create 0600 cinhtau cinhtau
            # keep only last 7 rotations
            rotate 7
            copytruncate
            compress
            missingok
            maxage 3
    }
    

    Regular daily rotated server logs are compressed and deleted after 3 days.

    # jboss server daily rotated logs
    /var/log/docker/*/server.log.????-??-?? {
        su root cinhtau
        compress
        nocreate
        nodateext
        ifempty
        missingok
        rotate 1
        size 0
        start 0
        lastaction
            # Remove rotated files older than 3 days
            find /var/log/docker -name 'server.log.????-??-??-??.0.gz' -mtime +3 -exec rm {} \;
        endscript
    }
    

    To run the texturation (filename docker_jboss)

    /usr/sbin/logrotate /etc/logrotate.d/docker_jboss
    

    To check if the file are rotated

    cat /var/lib/logrotate.status
    

    Lets look at an example. Following directory contains before logrotation:

    cinhtau@alpha:/var/log/docker/jboss# ls -l
    -rw-r--r-- 1 cinhtau cinhtau    3397 Dec  1 10:50 backupgc.log.current
    -rw-r--r-- 1 cinhtau cinhtau     356 Dec  2 10:42 fetrace.log
    -rw-r--r-- 1 cinhtau cinhtau    6754 Dec  2 12:47 gc.log.0.current
    -rw-r--r-- 1 cinhtau cinhtau 1240319 Dec  2 13:30 server.log
    -rw-rw-r-- 1 cinhtau cinhtau 7157923 Nov 29 23:57 server.log.2016-11-29
    -rw-rw-r-- 1 cinhtau cinhtau 4624286 Nov 30 15:54 server.log.2016-11-30
    -rw-r--r-- 1 cinhtau cinhtau 7510470 Dec  1 23:58 server.log.2016-12-01
    

    After log rotation:

    cinhtau@alpha:/var/log/docker/jboss# ls -l
    -rw-r--r-- 1 cinhtau cinhtau    3397 Dec  1 10:50 backupgc.log.current
    -rw-r--r-- 1 cinhtau cinhtau    6754 Dec  2 12:47 gc.log.0.current
    -rw-r--r-- 1 cinhtau cinhtau 1251043 Dec  2 13:46 server.log
    -rw-rw-r-- 1 cinhtau cinhtau  426809 Nov 29 23:57 server.log.2016-11-29.0.gz
    -rw-rw-r-- 1 cinhtau cinhtau  218025 Nov 30 15:54 server.log.2016-11-30.0.gz
    -rw-r--r-- 1 cinhtau cinhtau  405076 Dec  1 23:58 server.log.2016-12-01.0.gz
    

    An example for file size rotation.

    cinhtau@alpha:/var/log/docker/jboss# ll
    -rw-r--r-- 1 cinhtau cinhtau 215609425 Dec  2 14:02 server.log
    -rw-r--r-- 1 cinhtau cinhtau 315519951 Dec  2 13:55 server.log.1.gz
    -rw-rw-r-- 1 cinhtau cinhtau    143792 Nov 28 23:58 server.log.2016-11-28.0.gz
    -rw-rw-r-- 1 cinhtau cinhtau    177975 Nov 29 23:59 server.log.2016-11-29.0.gz
    -rw-rw-r-- 1 cinhtau cinhtau  35635494 Nov 30 23:59 server.log.2016-11-30.0.gz
    -rw-r--r-- 1 cinhtau cinhtau 206083051 Dec  1 23:59 server.log.2016-12-01.0.gz
    
  2. 2016-04-25 - Remove MaxPermSize warning from JBoss EAP; Tags: Remove MaxPermSize warning from JBoss EAP
    Loading...

    Remove MaxPermSize warning from JBoss EAP

    If you have JBoss EAP or Wildfly and you are using Java 8, you will receive in the logs, this warning:

    Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

    Java 8 eliminates above option, so the warning is ok. You can ignore it or remove it from the standalone.conf under $JBOSS/bin. To remove it, I will use awk to substitute the option with an empty string.

    The content of my demo file:

    vinh@foha03:~> cat standalone.test
    JAVA_OPTS="-Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true"
    

    The basic awk syntax:

    awk '{gsub("word", "");print}' input
    awk '{gsub("regex", "");print}' input > output
    
    vinh@foha03:~> awk '{gsub("-XX:MaxPermSize=256m ", "");print}' standalone.test
    JAVA_OPTS="-Xms1303m -Xmx1303m -Djava.net.preferIPv4Stack=true"
    

    To replace it with JBoss EAP standalone.conf

    JBOSS=/opt/jboss
    cp $JBOSS/bin/standalone.conf $JBOSS/bin/standalone-cfg.backup
    awk '{gsub("-XX:MaxPermSize=256m ", "");print}' $JBOSS/bin/standalone-cfg.backup > $JBOSS/bin/standalone.conf
    
  3. 2016-03-08 - Change System Properties for SSL Handling in JBoss EAP at runtime; Tags: Change System Properties for SSL Handling in JBoss EAP at runtime
    Loading...

    Change System Properties for SSL Handling in JBoss EAP at runtime

    Working with SSL you can pass all settings as arguments, or do it in the standalone.xml/domain.xml as System Properties. The advantage is you can alter them any time instead passing them as arguments. This post demonstrates how to deal with the essential SSL properties within JBoss by using the CLI.

    >-Djavax.net.debug=ssl -Djavax.net.ssl.keyStore=clientcertificate.p12 -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=$PASS -Djavax.net.ssl.trustStore=trusted_certs.jks -Djavax.net.ssl.trustStoreType=jks -Djavax.net.ssl.trustStorePassword=$PASS -Dhttps.protocols="TLSv1,TLSv1.1,TLSv1.2"

    Read System property

    [standalone@fo-prd02-dc1:12399 /] /system-property=javax.net.ssl.keyStore:read-resource
    {
        "outcome" => "success",
        "result" => {"value" => "/opt/six/fo/configuration/prod.jks"}
    }
    

    Change System property

    [standalone@fo-prd02-dc1:12399 /] /system-property=javax.net.ssl.keyStore:write-attribute(name=value, value="/opt/six/fo/configuration/prod_sl.jks")
    {"outcome" => "success"}
    

    Set logging and alter value

    [standalone@fo-prd02-dc1:12399 /] /system-property=javax.net.debug:add(value="ssl:handshake:verbose")
    {"outcome" => "success"}
    # Increase Logging level
    [standalone@fo-prd02-dc1:12399 /] /system-property=javax.net.debug:write-attribute(name=value, value="all")
    {"outcome" => "success"}
    

    Add System property for supported HTTPS protocols

    [standalone@fo-prd02-dc1:12399 /] /system-property=https.protocols:add(value="TLSv1,TLSv1.1,TLSv1.2")
    {"outcome" => "success"}
    
  4. 2016-03-05 - Bind JBoss EAP to subnet; Tags: Bind JBoss EAP to subnet
    Loading...

    Bind JBoss EAP to subnet

    Having multiple Network Interfaces (NICs) is especially at enterprise level servers very common. Having four network interfaces (bond0,..,bond0-2) the JBoss instance could bind to any interface. JBoss can be configured to bind to the subnet mask.

    Some information if you list the network interfaces:

    jboss@preprod:~/bin> ifconfig
    bond0     Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              inet addr:192.168.100.124  Bcast:192.168.100.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
              RX packets:2820418014 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2069442589 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:668733119792 (622.8 GiB)  TX bytes:1456413441469 (1.3 TiB)
    bond0:0   Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              inet addr:192.168.100.29  Bcast:192.168.100.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
    bond0:1   Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              inet addr:192.168.100.48  Bcast:192.168.100.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
    bond0:2   Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              inet addr:192.168.100.64  Bcast:192.168.100.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
    eth0      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
              RX packets:2212607915 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2069442567 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:632014707017 (588.6 GiB)  TX bytes:1456413439315 (1.3 TiB)
              Memory:92d20000-92d40000
    eth1      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
              UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
              RX packets:607810099 errors:0 dropped:0 overruns:0 frame:0
              TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:36718412775 (34.1 GiB)  TX bytes:2154 (2.1 KiB)
              Memory:92d60000-92d80000
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:266325455 errors:0 dropped:0 overruns:0 frame:0
              TX packets:266325455 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:59682164938 (55.5 GiB)  TX bytes:59682164938 (55.5 GiB)
    

    We have two physical network devices and four logical network devices. Login into the running JBoss instance with the CLI. I have written the command in a script.

    jboss@preprod:~/bin> ./jboss-cli.sh
    

    The basic part is to create a new interface, with a subnet-mask.

    [standalone@preprod:12399 /] /interface=external:add(subnet-match="192.168.100.0/16")
    {"outcome" => "success"}
    

    Next step is to assign the new interface to your existing socket binding.

    [standalone@preprod:12399 /] /socket-binding-group=standard-sockets:write-attribute(name=default-interface, value=external) {
        "outcome" => "success",
        "response-headers" => {
            "operation-requires-reload" => true,
            "process-state" => "reload-required"
        }
    }
    

    A restart is not necessary, but a reload is required to apply the changes.

    [standalone@preprod:12399 /] reload
    [standalone@preprod:12399 /] exit
    

    This will result in following log output message.

    JBAS014621: Multiple addresses or network interfaces matched the selection criteria for interface 'external'.
    Matching addresses: [/192.168.100.124, /192.168.100.29, /192.168.100.48, /192.168.100.64].
    Matching network interfaces: [bond0, bond0:0, bond0:1, bond0:2].
    The interface will use address /192.168.100.124 and network interface bond0.
    
  5. 2016-03-03 - Getting started with JBoss EAP Quickstarts; Tags: Getting started with JBoss EAP Quickstarts
    Loading...

    Getting started with JBoss EAP Quickstarts

    This post demonstrates how to setup the quickstart examples for the stable release JBoss EAP 6.4. The quickstart projects offer a variety of examples for the usage of Java EE 6 with JBoss.

    First of all, checkout the project from GitHub. Open the shell or gitbash on windows:

    $ git clone https://github.com/jboss-developer/jboss-eap-quickstarts.git
    Cloning into 'jboss-eap-quickstarts'...
    remote: Counting objects: 101739, done.
    remote: Compressing objects: 100% (33/33), done.
    remote: Total 101739 (delta 19), reused 4 (delta 4), pack-reused 101702
    Receiving objects: 100% (101739/101739), 48.58 MiB | 635.00 KiB/s, done.
    Resolving deltas: 100% (41761/41761), done.
    Checking connectivity... done.
    Checking out files: 100% (3198/3198), done.
    

    List tags

    vinnie@W30060 MINGW64 /c/dev/src/jboss-eap-quickstarts (7.0.x-develop)
    $ git tag
    1.0.0.Alpha2
    1.0.0.Alpha3
    1.0.0.M1
    1.0.0.M2
    1.0.0.M2b
    1.0.0.M2c
    1.0.0.M3
    1.0.0.M3b
    1.0.0.M4
    1.0.0.M5
    1.0.0.M6
    1.0.0.M7
    1.0.0.M8
    2.0.0.ER8
    6.2.0.Beta1
    6.2.0.GA
    6.3.0.GA
    6.4.0.GA
    6.4.0.develop
    7.0.0.CR1
    7.0.0.Final
    7.0.0.Final-subsystem
    7.0.1.Final-subsystem
    7.0.2.CR1
    7.0.2.CR1-javaee
    7.0.2.CR2
    7.0.2.CR3
    7.0.2.CR4
    7.1.0.Beta1
    7.1.0.Final
    7.1.1.CR1
    7.1.1.CR2
    7.1.1.Final
    7.1.2.M1
    EAP-6.2.0.ER4
    EAP_7.0.0.Beta1
    jdf-2.0.0.CR3
    jdf-2.0.0.Final
    jdf-2.0.0.M3
    jdf-2.1.0.Final
    jdf-2.1.1.Final
    jdf-2.1.2.Final
    jdf-2.1.5.Final
    jdf-2.1.6.Final
    jdf-2.1.7.Final
    jdf-2.1.8.Final
    jdf-2.1.9.Final
    jdf-eap6.1-initial-merge
    jdf-eap6.1-update2
    master-6.2.0.ER4
    master-6.2.0.ER5
    

    Update to dedicated release, tag: 6.4.0.GA for example

    vinnie@W30060 MINGW64 /c/dev/src/jboss-eap-quickstarts (7.0.x-develop)
    $ git checkout tags/6.4.0.GA
    Checking out files: 100% (3206/3206), done.
    Note: checking out 'tags/6.4.0.GA'.
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
      git checkout -b <new-branch-name>
    HEAD is now at 71a4719... Update versions for 6.4.0.GA release
    

    If you are working in a company network, you might add the proxy to the delivered settings.xml.

    <proxies>
    <proxy>
                <id>yourProxy</id>
                <active>true</active>
    <protocol>http</protocol>
                <username>vinh</username>
    <password>secret</password>
                <host>proxy.cinhtau.net</host>
    <port>8080</port>
                <nonProxyHosts>localhost| 127.0.0.*| 10.*| 192.168.*</nonProxyHosts>
            </proxy>
        </proxies>
    

    Read more at https://maven.apache.org/guides/mini/guide-proxies.html, if you have further questions about proxies with Apache Maven. Build the project with Apache Maven 3 and the settings.xml from RedHat and skip the tests. You may deactivate all active or default activated profiles, if you don’t met the requirement.

    mvn clean install -s settings.xml -Dmaven.test.skip=true
    

    After that you run or deploy the generated Java EE artifacts to the JBoss EAP 6.4.x versions. Have fun. If you want to start with a quick project setup, e.g. a simple web application (war)

    mvn archetype:generate \
     -DarchetypeGroupId=org.jboss.archetype.eap \
     -DarchetypeArtifactId=jboss-javaee6-webapp-ear-blank-archetype \
     -DarchetypeVersion=6.4.0.GA -s settings.xml
    
  6. 2016-03-02 - Filter messages in JBoss Logging; Tags: Filter messages in JBoss Logging
    Loading...

    Filter messages in JBoss Logging

    Working with Hibernate and Oracle DB 10 g lead to a massive amount of warnings on the logs. This post demonstrates how to filter these warnings, if they don’t apply to the situation, in JBoss EAP or Wildfly.

    WARN org.hibernate.loader.Loader - HHH000444: Encountered request for locking however dialect reports that database prefers locking be done in a separate select (follow-on locking); results will be locked after initial query execute
    

    See HHH-9097 for more details. To avoid the noise, you can setup JBoss EAP or Wildfly to filter this kind of messages. Run the CLI (command line interface):

    /subsystem=logging/console-handler=CONSOLE:write-attribute(name=filter-spec,value=not(match("HHH000444")))
    /subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name=filter-spec,value=not(match("HHH000444")))
    

    The first cli instruction will apply the filter in the console logger and the second for the periodic rotating file handler. See Filter Expressions for Logging for more details.

  7. 2016-02-03 - Remove console handler from root logger in JBoss/Wildfly; Tags: Remove console handler from root logger in JBoss/Wildfly
    Loading...

    Remove console handler from root logger in JBoss/Wildfly

    This post demonstrates how to remove log handlers at runtime in JBoss EAP 6.4.4 or Wildfly.

    If you haven’t cleanup the logging configuration in JBoss and your console.log is growing constantly, then you might have forgotten to remove the console handler in the root logger of the standalone.xml.

    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
        </handlers>
    </root-logger>
    

    To do it in runtime, log into the cli and just use this command:

    /subsystem=logging/root-logger=ROOT:remove-handler(name="CONSOLE")
    

    If you are using a logging profile named DEMO:

    /subsystem=logging/logging-profile=DEMO/root-logger=ROOT:remove-handler(name="CONSOLE")
    
  8. 2016-01-25 - Use netstat to check used ports of a process; Tags: Use netstat to check used ports of a process
    Loading...

    Use netstat to check used ports of a process

    This blog post demonstrates a small example how helpful netstat can be. netstat is capable to display all used ports of the user processes.

    Following command can be a life-saver

    netstat -tulpn
    

    Options explained:

    • -t = tcp
    • -u = udp
    • -l = listening
    • -p = program
    • -n = numeric

    Problem

    First of all, I have a Java EE application, that claims to run the management port 12099

    tan@server:~> ps -Af | grep demo
    tan 11182 10919  0 Jan19 ?        00:07:18 /opt/java/jdk1.8.0_51/bin/java -D[Standalone] -server -XX:+UseCompressedOops -verbose:gc -Xloggc:/var/log/jboss/demo_prd_1/log/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading -Xms1303m -Xmx1303m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.modules.policy-permissions=true -Dorg.jboss.boot.log.file=/var/log/jboss/demo_prd_1/log/server.log -Dlogging.configuration=file:/opt/demo_prd_1/configuration/logging.properties -jar /opt/jboss/jboss-eap-6.4.2/jboss-modules.jar -mp /opt/jboss/jboss-eap-6.4.2/modules -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=/opt/jboss/jboss-eap-6.4.2 -Djboss.server.base.dir=/opt/apps/demo_prd_1 -Djboss.server.base.dir=/opt/apps/demo_prd_1 -b=192.168.100.74 -Djboss.management.native.port=12099 -bmanagement=192.168.100.74 -Djboss.server.log.dir=/var/log/jboss/demo_prd_1/log -P /opt/apps/demo_prd_1/configuration/demo_prd_1.properties --server-config=standalone.xml
    

    Even the log is telling me, that this port is being used

    2016-01-19 05:29:16,069 INFO  [MSC service thread 1-8] [] [] [] [] [] (org.jboss.as) JBAS015899: JBoss EAP 6.4.2.GA (AS 7.5.2.Final-redhat-2) starting
    2016-01-19 05:29:16,074 DEBUG [MSC service thread 1-8] [] [] [] [] [] (org.jboss.as.config) Configured system properties:
            [Standalone] =
            ..
            jboss.management.native.port = 12099
            jboss.modules.dir = /opt/jboss/jboss-eap-6.4.2/modules
    

    Now I try to connect to the CLI to change the log level at runtime, if you haven’t setup JAVA_HOME properly, you can setup it accordingly with these commands

    tan@server:~> export JAVA_HOME=/opt/java/jdk1.8.0_51
    tan@server:~> export PATH=$PATH:$JAVA_HOME/bin
    tan@server:~> /opt/jboss/jboss-eap-6.4.2/bin/jboss-cli.sh --controller=192.168.100.74:12099 --connect
    org.jboss.as.cli.CliInitializationException: Failed to connect to the controller
    ..
    Caused by: org.jboss.as.cli.CommandLineException: The controller is not available at 192.168.100.74:12099
            ... 8 more
    Caused by: java.io.IOException: java.net.ConnectException: JBAS012174: Could not connect to remote://192.168.100.74:12099. The connection failed
            ... 11 more
    Caused by: java.net.ConnectException: JBAS012174: Could not connect to remote://192.168.100.74:12099. The connection failed
            ... 13 more
    Caused by: java.net.ConnectException: Connection refused
            ... 23 more
    

    WTF happened? The port should be ok.

    Check with netstat

    Now we can check with netstat which ports are used by process 11182.

    tan@server:~> netstat -tulpn | grep 11182
    (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
    tcp        0      0 10.152.48.74:12090          0.0.0.0:*                   LISTEN      11182/java
    tcp        0      0 10.152.48.74:13099          0.0.0.0:*                   LISTEN      11182/java
    tcp        0      0 10.152.48.74:8943           0.0.0.0:*                   LISTEN      11182/java
    tcp        0      0 10.152.48.74:12047          0.0.0.0:*                   LISTEN      11182/java
    tcp        0      0 10.152.48.74:12080          0.0.0.0:*                   LISTEN      11182/java
    

    Well we haven’t found 12099, but 13099! Now let’s check the login.

    tan@server:~> /opt/jboss/jboss-eap-6.4.2/bin/jboss-cli.sh --controller=192.168.100.74:13099 --connect
    [standalone@192.168.100.74:13099 /] /subsystem=logging/logger=net.cinhtau.net.dmr:write-attribute(name="level", value="INFO")
    {"outcome" => "success"}
    [standalone@192.168.100.74:13099 /] exit
    

    Check the console.log, that tells the truth

    tan@server:~/logs> cat console.log
    ..
    05:29:16,787 INFO  [org.jboss.as.remoting] (MSC service thread 1-45) JBAS017100: Listening on 192.168.100.74:12047
    ..
    05:29:16,908 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-27) JBWEB003001: Coyote HTTP/1.1 initializing on : http-/192.168.100.74:12080
    05:29:16,912 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-27) JBWEB003000: Coyote HTTP/1.1 starting on: http-/192.168.100.74:12080
    ..
    05:29:16,960 INFO  [org.jboss.as.remoting] (MSC service thread 1-14) JBAS017100: Listening on 192.168.100.74:13099
    
  9. 2016-01-19 - Change log level at runtime in JBoss EAP/Wildfly with CLI; Tags: Change log level at runtime in JBoss EAP/Wildfly with CLI
    Loading...

    Change log level at runtime in JBoss EAP/Wildfly with CLI

    This post demonstrates you how you can set the defined log levels of log categories (e.g. classname) and of the root logger in the standalone.xml. Same applies to the domain mode. Just add the profile name before the cli command. It was very useful, to correct the verbose output of a running application in production.

    In case you didn’t setup your java environment properly, a quick setup on the terminal:

    tan@cinhtau:~> export JAVA_HOME=/opt/java/jdk1.8.0_66
    tan@cinhtau:~> export PATH=$PATH:$JAVA_HOME/bin
    

    Start JBoss cli, replace hostname/IP and port according to your configuration

    tan@cinhtau:~> /opt/jboss/jboss-eap-6.4.4/bin/jboss-cli.sh --controller=192.168.14.74:12199 --connect
    

    Change log level of root logger, outcome is success, if applied successfully

    [standalone@192.168.14.74:12199 /] /subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="INFO")
    {"outcome" => "success"}
    

    If you are using a logging profile, add the logging profile in between.

    /subsystem=logging/logging-profile=DEMO/root-logger=ROOT:write-attribute(name="level", value="INFO")
    

    Change log level of log category, outcome is success, if applied successfully

    [standalone@192.168.14.74:12199 /] /subsystem=logging/logger=net.cinhtau.dmr:write-attribute(name="level", value="INFO")
    {"outcome" => "success"}
    

    Leave the CLI

    [standalone@192.168.14.74:12199 /] exit
    
  10. 2015-12-16 - Using the CLI in JBoss; Tags: Using the CLI in JBoss
    Loading...

    Using the CLI in JBoss

    This post describes the basic concepts of the JBoss command line interface. It may enhance the work with the CLI.

    Query the version of JBoss

    [standalone@localhost:9999 /] version
    JBoss Admin Command-line Interface
    JBOSS_HOME: C:\dev\app-server\jboss-eap-6.4
    JBoss AS release: 7.5.0.Final-redhat-21 "Janus"
    JBoss AS product: EAP 6.4.0.GA
    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_66
    java.version: 1.8.0_66
    java.vm.vendor: Oracle Corporation
    java.vm.version: 25.66-b17
    os.name: Windows 7
    os.version: 6.1
    

    List available JDBC drivers (as default the H2 database is shipped within).

    [standalone@localhost:9999 /] jdbc-driver-info
    NAME SOURCE
    h2   com.h2database.h2/main
    

    List content

    [standalone@localhost:9999 /] ls
    core-service                           management-minor-version=7
    deployment                             name=cinhtau
    deployment-overlay                     namespaces=[]
    extension                              process-type=Server
    interface                              product-name=EAP
    path                                   product-version=6.4.0.GA
    socket-binding-group                   profile-name=undefined
    subsystem                              release-codename=Janus
    system-property                        release-version=7.5.0.Final-redhat-21
    launch-type=STANDALONE                 running-mode=NORMAL
    management-major-version=1             schema-locations=[]
    management-micro-version=0             server-state=running
    

    You can traverse into the nodes

    [standalone@localhost:9999 /] ls
    core-service                           management-minor-version=7
    deployment                             name=cinhtau
    deployment-overlay                     namespaces=[]
    extension                              process-type=Server
    interface                              product-name=EAP
    path                                   product-version=6.4.0.GA
    socket-binding-group                   profile-name=undefined
    subsystem                              release-codename=Janus
    system-property                        release-version=7.5.0.Final-redhat-21
    launch-type=STANDALONE                 running-mode=NORMAL
    management-major-version=1             schema-locations=[]
    management-micro-version=0             server-state=running
    [standalone@localhost:9999 /] cd interface=
    management  public      unsecure
    [standalone@localhost:9999 /] cd interface=public
    [standalone@localhost:9999 interface=public]
    

    JBoss CLI supports auto-completion and command assist

    [standalone@localhost:9999 interface=public] /interface=public:read-
    read-attribute              read-operation-description
    read-children-names         read-operation-names
    read-children-resources     read-resource
    read-children-types         read-resource-description
    [standalone@localhost:9999 interface=public] /interface=public:read-operation-names
    {
        "outcome" => "success",
        "result" => [
            "add",
            "read-attribute",
            "read-children-names",
            "read-children-resources",
            "read-children-types",
            "read-operation-description",
            "read-operation-names",
            "read-resource",
            "read-resource-description",
            "remove",
            "resolve-internet-address",
            "undefine-attribute",
            "whoami",
            "write-attribute"
        ]
    }
    

    If you need information, what an operation does

    [standalone@localhost:9999 interface=public] /interface=public:read-operation-description (name="write-attribute")
    {
        "outcome" => "success",
        "result" => {
            "operation-name" => "write-attribute",
            "description" => "Sets the value of an attribute for the selected resource",
            "request-properties" => {
                "name" => {
                    "type" => STRING,
                    "description" => "The name of the attribute to set the value for under the selected resource",
                    "expressions-allowed" => false,
                    "required" => true,
                    "nillable" => false,
                    "min-length" => 1L,
                    "max-length" => 2147483647L
                },
                "value" => {
                    "type" => STRING,
                    "description" => "The value of the attribute to set the value for under the selected resource. May be null if the underlying model supports null values.",
                    "expressions-allowed" => false,
                    "required" => false,
                    "nillable" => true,
                    "min-length" => 1L,
                    "max-length" => 2147483647L
                }
            },
            "reply-properties" => {},
            "read-only" => false
        }
    }
    
  11. 2015-12-14 - Enable remote access for JBoss Web; Tags: Enable remote access for JBoss Web
    Loading...

    Enable remote access for JBoss Web

    This post demonstrates how to enable the remote access for JBoss in standalone mode. It includes several CLI commands to check the status at runtime. To apply the changes a restart is needed.

    List all interfaces

    [standalone@localhost:9999 /] :read-children-names(child-type=interface)
    {
        "outcome" => "success",
        "result" => [
            "management",
            "public",
            "unsecure"
        ]
    }
    

    The public interface is reponsible for the remote access. Below the output of the default configuration.

    [standalone@localhost:9999 /] /interface=public:read-resource(include-runtime=true)
    # or alternatively
    [standalone@localhost:9999 /] cd interface=public
    [standalone@localhost:9999 interface=public] :read-resource(include-runtime=true)
    {
        "outcome" => "success",
        "result" => {
            "any" => undefined,
            "any-address" => undefined,
            "any-ipv4-address" => undefined,
            "any-ipv6-address" => undefined,
            "inet-address" => expression "${jboss.bind.address:127.0.0.1}",
            "link-local-address" => undefined,
            "loopback" => undefined,
            "loopback-address" => undefined,
            "multicast" => undefined,
            "name" => "public",
            "nic" => undefined,
            "nic-match" => undefined,
            "not" => undefined,
            "point-to-point" => undefined,
            "public-address" => undefined,
            "resolved-address" => "127.0.0.1",
            "site-local-address" => undefined,
            "subnet-match" => undefined,
            "up" => undefined,
            "virtual" => undefined
        }
    }
    

    If you want to allow the access from any address (IPv4 and IPv6), you need to change the standalone.xml.

    <interface name="public">
                <!-- <inet-address value="${jboss.bind.address:127.0.0.1}"/> -->
                <any-address/>
    </interface>
    

    If you want to do it via CLI (will produce above result in the standalone.xml).

    [standalone@localhost:9999 interface=public] /interface=public:remove()
    {"outcome" => "success"}
    [standalone@localhost:9999 interface=public] /interface=public:add(any-address=true)
    {"outcome" => "success"}
    # restart required
    [standalone@localhost:9999 interface=public] shutdown --restart=true
    

    Since it is an default expression you may also start JBoss with following arguments

    ./standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 &
    

    If you want to bind it to a specific inet-address

    /interface=interfacename/:add(inet-address=192.168.0.2)
    # change it
    /interface=interfacename/:write(inet-address=192.168.100.2)
    

    See also RedHat JBoss Network and Port Configuration

  12. 2015-12-04 - List installed JDBC drivers in JBoss; Tags: List installed JDBC drivers in JBoss
    Loading...

    List installed JDBC drivers in JBoss

    This post demonstrates how to query at runtime, which JDBC drivers are available in JBoss EAP via the CLI.

    JBoss is shipped with the H2 database.

    [standalone@localhost:9999 /] /subsystem=datasources:installed-drivers-list
    {
        "outcome" => "success",
        "result" => [{
            "driver-name" => "h2",
            "deployment-name" => undefined,
            "driver-module-name" => "com.h2database.h2",
            "module-slot" => "main",
            "driver-datasource-class-name" => "",
            "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
            "driver-class-name" => "org.h2.Driver",
            "driver-major-version" => 1,
            "driver-minor-version" => 3,
            "jdbc-compliant" => true
        }]
    }
    
  13. 2015-11-26 - Change default log format of JBoss via CLI; Tags: Change default log format of JBoss via CLI
    Loading...

    Change default log format of JBoss via CLI

    This blog post demonstrates how to change the default log format of JBoss periodic file handler FILE. In the original state, it doesn’t log the date of the log entry. Using logstash with datetime matching, requires a date :-).

    Connect with the CLI to your JBoss installation. Check if the file handler is there:

    [standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
    {
        "outcome" => "success",
        "result" => {
            "append" => true,
            "autoflush" => true,
            "enabled" => true,
            "encoding" => undefined,
            "file" => {
                "relative-to" => "jboss.server.log.dir",
                "path" => "server.log"
            },
            "filter" => undefined,
            "filter-spec" => undefined,
            "formatter" => "%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
            "level" => "ALL",
            "name" => "FILE",
            "named-formatter" => "PATTERN",
            "suffix" => ".yyyy-MM-dd"
        }
    }
    

    Change the log format with

    /subsystem=logging/periodic-rotating-file-handler=FILE:write-attribute(name="formatter",value="%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n")
    

    Check the new defined log format

    [standalone@localhost:9999 /] /subsystem=logging/periodic-rotating-file-handler=FILE:read-resource
    {
        "outcome" => "success",
        "result" => {
            "append" => true,
            "autoflush" => true,
            "enabled" => true,
            "encoding" => undefined,
            "file" => {
                "relative-to" => "jboss.server.log.dir",
                "path" => "server.log"
            },
            "filter" => undefined,
            "filter-spec" => undefined,
            "formatter" => "%d{yyyy-MM-dd'T'HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
            "level" => "ALL",
            "name" => "FILE",
            "named-formatter" => undefined,
            "suffix" => ".yyyy-MM-dd"
        }
    }
    
  14. 2015-11-06 - Create logging profiles for Java EE applications on JBoss EAP; Tags: Create logging profiles for Java EE applications on JBoss EAP
    Loading...

    Create logging profiles for Java EE applications on JBoss EAP

    The reasons to use logging profiles: The use of logging profiles allows administrators to create logging configuration that are specific to one or more applications without affecting any other logging configuration. Because each profile is defined in the server configuration, the logging configuration can be changed without requiring that the affected applications be redeployed.

    Logging profiles are like additional logging subsystems. Each logging profile constists of three of the four notable parts listed above:

    • handler configurations
    • logger
    • and the root logger declarations.

    General steps:

    • Setup JBoss - create logging profile
    • Configure your Java EE app to use the created profile

    Setup JBoss

    Create a logging profile with CLI

    #  _                   _
    # | | ___   __ _  __ _(_)_ __   __ _
    # | |/ _ \ / _` |/ _` | | '_ \ / _` |
    # | | (_) | (_| | (_| | | | | | (_| |
    # |_|\___/ \__, |\__, |_|_| |_|\__, |
    #          |___/ |___/         |___/
    # create logging profile
    # root configuration path /subsystem=logging/logging-profile=DEMO
    # /subsystem=logging/logging-profile=DEMO:remove
    /subsystem=logging/logging-profile=DEMO:add
    /subsystem=logging/logging-profile=DEMO/ \
       periodic-rotating-file-handler=metrics:add( \
       file={ \
         "path"=>"metrics.log", \
         "relative-to"=>"jboss.server.log.dir" \
       }, \
       suffix=".yyyy-MM-dd", \
       append="true", \
       formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n", \
       autoflush="true")
    /subsystem=logging/logging-profile=DEMO/ \
        periodic-rotating-file-handler=metrics:write-attribute(name="level", value="DEBUG")
    # log category
    /subsystem=logging/logging-profile=DEMO/ \
        logger=de.test:add(level=DEBUG)
    /subsystem=logging/logging-profile=DEMO/ \
        logger=de.test:add-handler(name="metrics")
    # custom pattern
    /subsystem=logging/logging-profile=DEMO/ \
        pattern-formatter=stat-pattern:add( \
        pattern="A,%d{yyyy-MM-dd'T'HH:mm:ss.SSS} %m%n") /subsystem=logging/logging-profile=DEMO/ \
        periodic-rotating-file-handler=metrics:write-attribute(name=named-formatter, value=stat-pattern)
    #                  _     _
    #  _ __ ___   ___ | |_  | | ___   __ _  __ _  ___ _ __
    # | '__/ _ \ / _ \| __| | |/ _ \ / _` |/ _` |/ _ \ '__|
    # | | | (_) | (_) | |_  | | (_) | (_| | (_| |  __/ |
    # |_|  \___/ \___/ \__| |_|\___/ \__, |\__, |\___|_|
    #                                |___/ |___/
    # set level of root logger
    /subsystem=logging/logging-profile=DEMO/ \
        root-logger=ROOT:add
    /subsystem=logging/logging-profile=DEMO/ \
        root-logger=ROOT:write-attribute(name="level", value="DEBUG")
    /subsystem=logging/logging-profile=DEMO/ \
        root-logger=ROOT:root-logger-assign-handler(name="CONSOLE")
    /subsystem=logging/logging-profile=DEMO/ \
        root-logger=ROOT:root-logger-assign-handler(name="metrics")
    

    Configure your Java EE Application

    You can assign a logging profile to a deployment via the deployments manifest. Add a Logging-Profile entry to the MANIFEST. Create MANIFEST.MF

    Manifest-Version: 1.0
    Logging-Profile: DEMO
    

    Configure Maven to include manifest file

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <archive>
                <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
            </archive>
        </configuration>
    </plugin>
    
  15. 2015-11-04 - Add Oracle DB datasource to JBoss; Tags: Add Oracle DB datasource to JBoss
    Loading...

    Add Oracle DB datasource to JBoss

    This post demonstrates how to establish a data-source configuration for JBoss EAP with the Oracle DB.

    Dump the contents of the help command to help.txt

    [standalone@localhost:9999 /] data-source --help --properties > help.txt
    

    The contents

     --name                 - Required argument in commands which identifies the
                              instance to execute the command against.
     --share-prepared-statements  - (BOOLEAN,read-write) Whether to share prepared
                                    statements, i.e. whether asking for same
                            statement twice without closing uses the same underlying
                            prepared statement
     --driver-class         - (STRING,read-write) The fully qualified name of the
                              JDBC driver class
     --prepared-statements-cache-size  - (LONG,read-write) The number of prepared
                                         statements per connection in an LRU cache
     --spy                  - (BOOLEAN,read-write) Enable spying of SQL statements
     --password             - (STRING,read-write) Specifies the password used when
                              creating a new connection
     --max-pool-size        - (INT,read-write) The max-pool-size element specifies
                              the maximum number of connections for a pool. No more
                            connections will be created in each sub-pool
     --set-tx-query-timeout  - (BOOLEAN,read-write) Whether to set the query timeout
                               based on the time remaining until transaction
                            timeout. Any configured query timeout will be used if
                            there is no transaction
     --jndi-name            - (STRING,read-write) Specifies the JNDI name for the
                              datasource
     --url-delimiter        - (STRING,read-write) Specifies the delimiter for URLs
                              in connection-url for HA datasources
     --enabled              - (BOOLEAN,read-write) Specifies if the datasource
                              should be enabled. Note this attribute will not be
                            supported runtime in next versions.
     --connectable          - (BOOLEAN,read-write) Enable the use of CMR. This
                              feature means that a local resource can reliably
                            participate in an XA transaction.
     --blocking-timeout-wait-millis  - (LONG,read-write) The blocking-timeout-millis
                                       element specifies the maximum time, in
                            milliseconds, to block while waiting for a connection
                            before throwing an exception. Note that this blocks only
                            while waiting for locking a connection, and will never
                            throw an exception if creating a new connection takes an
                            inordinately long time
     --statistics-enabled   - (BOOLEAN,read-write) define if runtime statistics is
                              enabled or not.
     --pool-use-strict-min  - (BOOLEAN,read-write) Specifies if the min-pool-size
                              should be considered strictly
     --validate-on-match    - (BOOLEAN,read-write) The validate-on-match element
                              specifies if connection validation should be done when
                            a connection factory attempts to match a managed
                            connection. This is typically exclusive to the use of
                            background validation
     --transaction-isolation  - (STRING,read-write) Set the java.sql.Connection
                                transaction isolation level. Valid values are:
                            TRANSACTION_READ_UNCOMMITTED,
                            TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ,
                            TRANSACTION_SERIALIZABLE and TRANSACTION_NONE
     --jta                  - (BOOLEAN,read-write) Enable JTA integration
     --valid-connection-checker-class-name  - (STRING,read-write) An
                                              org.jboss.jca.adapters.jdbc.ValidConne
                            ctionChecker that provides an
                            isValidConnection(Connection) method to validate a
                            connection. If an exception is returned that means the
                            connection is invalid. This overrides the
                            check-valid-connection-sql element
     --allocation-retry-wait-millis  - (LONG,read-write) The allocation retry wait
                                       millis element specifies the amount of time,
                            in milliseconds, to wait between retrying to allocate a
                            connection
     --exception-sorter-properties  - (OBJECT,read-write) The exception sorter
                                      properties
     --background-validation-millis  - (LONG,read-write) The
                                       background-validation-millis element
                            specifies the amount of time, in milliseconds, that
                            background validation will run. Changing this value can
                            be done only on disabled datasource,  requires a server
                            restart otherwise
     --track-statements     - (STRING,read-write) Whether to check for unclosed
                              statements when a connection is returned to the pool,
                            result sets are closed, a statement is closed or return
                            to the prepared statement cache. Valid values are:
                            "false" - do not track statements, "true" - track
                            statements and result sets and warn when they are not
                            closed, "nowarn" - track statements but do not warn
                            about them being unclosed
     --use-fast-fail        - (BOOLEAN,read-write) Whether to fail a connection
                              allocation on the first try if it is invalid (true) or
                            keep trying until the pool is exhausted of all potential
                            connections (false)
     --flush-strategy       - (STRING,read-write) Specifies how the pool should be
                              flush in case of an error. Valid values are:
                            FailingConnectionOnly (default), IdleConnections and
                            EntirePool
     --stale-connection-checker-class-name  - (STRING,read-write) An
                                              org.jboss.jca.adapters.jdbc.StaleConne
                            ctionChecker that provides an
                            isStaleConnection(SQLException) method which if it
                            returns true will wrap the exception in an
                            org.jboss.jca.adapters.jdbc.StaleConnectionException
     --exception-sorter-class-name  - (STRING,read-write) An
                                      org.jboss.jca.adapters.jdbc.ExceptionSorter
                            that provides an isExceptionFatal(SQLException) method
                            to validate if an exception should broadcast an error
     --background-validation  - (BOOLEAN,read-write) An element to specify that
                                connections should be validated on a background
                            thread versus being validated prior to use. Changing
                            this value can be done only on disabled datasource,
                            requires a server restart otherwise.
     --check-valid-connection-sql  - (STRING,read-write) Specify an SQL statement to
                                     check validity of a pool connection. This may
                            be called when managed connection is obtained from the
                            pool
     --reauth-plugin-class-name  - (STRING,read-write) The fully qualified class
                                   name of the reauthentication plugin
                            implementation
     --allow-multiple-users  - (BOOLEAN,read-write) Specifies if multiple users will
                               access the datasource through the getConnection(user,
                            password) method and hence if the internal pool type
                            should account for that
     --url-selector-strategy-class-name  - (STRING,read-write) A class that
                                           implements
                            org.jboss.jca.adapters.jdbc.URLSelectorStrategy
     --user-name            - (STRING,read-write) Specify the user name used when
                              creating a new connection
     --use-ccm              - (BOOLEAN,read-write) Enable the use of a cached
                              connection manager
     --reauth-plugin-properties  - (OBJECT,read-write) The properties for the
                                   reauthentication plugin
     --driver-name          - (STRING,read-write) Defines the JDBC driver the
                              datasource should use. It is a symbolic name matching
                            the the name of installed driver. In case the driver is
                            deployed as jar, the name is the name of deployment unit
     --stale-connection-checker-properties  - (OBJECT,read-write) The stale
                                              connection checker properties
     --datasource-class     - (STRING,read-write) The fully qualified name of the
                              JDBC datasource class
     --idle-timeout-minutes  - (LONG,read-write) The idle-timeout-minutes elements
                               specifies the maximum time, in minutes, a connection
                            may be idle before being closed. The actual maximum time
                            depends also on the IdleRemover scan time, which is half
                            of the smallest idle-timeout-minutes value of any pool.
                            Changing this value can be done only on disabled
                            datasource, requires a server restart otherwise.
     --query-timeout        - (LONG,read-write) Any configured query timeout in
                              seconds. If not provided no timeout will be set
     --use-java-context     - (BOOLEAN,read-write) Setting this to false will bind
                              the datasource into global JNDI
     --valid-connection-checker-properties  - (OBJECT,read-write) The valid
                                              connection checker properties
     --min-pool-size        - (INT,read-write) The min-pool-size element specifies
                              the minimum number of connections for a pool
     --allocation-retry     - (INT,read-write) The allocation retry element
                              indicates the number of times that allocating a
                            connection should be tried before throwing an exception
     --security-domain      - (STRING,read-write) Specifies the security domain
                              which defines the javax.security.auth.Subject that are
                            used to distinguish connections in the pool
     --new-connection-sql   - (STRING,read-write) Specifies an SQL statement to
                              execute whenever a connection is added to the
                            connection pool
     --connection-url       - (STRING,read-write) The JDBC driver connection URL
     --use-try-lock         - (LONG,read-write) Any configured timeout for internal
                              locks on the resource adapter objects in seconds
     --pool-prefill         - (BOOLEAN,read-write) Should the pool be prefilled.
                              Changing this value can be done only on disabled
                            datasource, requires a server restart otherwise.
    

    Add driver modules

    #    _     _ _
    #   (_) __| | |__   ___
    #   | |/ _` | '_ \ / __|
    #   | | (_| | |_) | (__
    #  _/ |\__,_|_.__/ \___|
    # |__/
    #
    # install jdbc driver with i18n
    # module remove --name=com.oracle.jdbc6
    # module remove --name=com.oracle.orai18n
    module add --name=com.oracle.jdbc6 \
        --resources=${deploy.dir}/deploy/jdbc/ojdbc6-11203.jar \
        --dependencies=javax.api,javax.transaction.api
    module add --name=com.oracle.orai18n \
        --resources=${deploy.dir}/deploy/jdbc/orai18n-11203.jar
        --dependencies=com.oracle.jdbc6,javax.api,javax.transaction.api
    

    Add datasource

    #      _       _
    #   __| | __ _| |_ __ _ ___  ___  _   _ _ __ ___ ___
    #  / _` |/ _` | __/ _` / __|/ _ \| | | | '__/ __/ _ \
    # | (_| | (_| | || (_| \__ \ (_) | |_| | | | (_|  __/
    #  \__,_|\__,_|\__\__,_|___/\___/ \__,_|_|  \___\___|
    #
    /subsystem=datasources/jdbc-driver=oracle:add( \
        driver-name=oracle, \
        driver-module-name=com.oracle.jdbc6, \
        driver-xa-datasource-class-name=oracle.jdbc.driver.OracleDriver)
    # pool-name will be demo
    /subsystem=datasources/data-source=demo:add( \
        jta=true, \
        jndi-name=java:jboss/datasources/demo, \
        enabled=true, \
        use-java-context=true, \
        use-ccm=true, \
        connection-url=${jdbc.url}, \
        driver-name=oracle, \
        transaction-isolation=TRANSACTION_READ_COMMITTED, \
        min-pool-size=1, \
        max-pool-size=10, \
        pool-prefill=true, \
        flush-strategy=FailingConnectionOnly, \
        user-name=scott, \
        password=tiger, \
        check-valid-connection-sql="SELECT 1 FROM DUAL")
    
  16. 2015-10-25 - Create datasource for H2 in JBoss; Tags: Create datasource for H2 in JBoss
    Loading...

    Create datasource for H2 in JBoss

    This post demonstrates how to create a datasource for the H2 database in JBoss. This recipe can easily applied to any other database like Oracle DB, MySQL and PostgreSQL.

    First, check if the h2 database driver is available:

    [standalone@localhost:9999 /] /subsystem=datasources:installed-drivers-list
    {
        "outcome" => "success",
        "result" => [{
            "driver-name" => "h2",
            "deployment-name" => undefined,
            "driver-module-name" => "com.h2database.h2",
            "module-slot" => "main",
            "driver-datasource-class-name" => "",
            "driver-xa-datasource-class-name" => "org.h2.jdbcx.JdbcDataSource",
            "driver-class-name" => "org.h2.Driver",
            "driver-major-version" => 1,
            "driver-minor-version" => 3,
            "jdbc-compliant" => true
        }]
    }
    

    We add a datasource by this template

    data-source add \
       --name=DATASOURCE_NAME \
       --jndi-name=JNDI_NAME \
       --driver-name=DRIVER_NAME \
       --connection-url=CONNECTION_URL
    

    Use H2 as file and add custom settings within the connection-url. After the add, don’t forget to enable the new datasource.

    #      _       _
    #   __| | __ _| |_ __ _ ___  ___  _   _ _ __ ___ ___
    #  / _` |/ _` | __/ _` / __|/ _ \| | | | '__/ __/ _ \
    # | (_| | (_| | || (_| \__ \ (_) | |_| | | | (_|  __/
    #  \__,_|\__,_|\__\__,_|___/\___/ \__,_|_|  \___\___|
    #
    data-source add \
        --name=demo \
        --driver-name=h2 \
        --connection-url="jdbc:h2:demo;INIT=RUNSCRIPT FROM '~/tables.sql';DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE" \
        --jndi-name=java:jboss/datasources/demo \
        --user-name=admin \
        --password=geheim \
        --check-valid-connection-sql="SELECT 1"
    data-source enable --name=demo
    

    This will result in console.log

    16:48:49,991 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/demo]
    

    This will generate this section in the standalone.xml.

    <datasource jndi-name="java:jboss/datasources/demo" pool-name="demo" enabled="true">
    	<connection-url>jdbc:h2:demo;INIT=RUNSCRIPT FROM '~/tables.sql';DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE</connection-url>
    	<driver>h2</driver>
    	<security>
    		<user-name>admin</user-name>
    <password>geheim</password>
    	</security>
    	<validation>
    		<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
    	</validation>
    </datasource>
    

    check-valid-connection-sql is important! You provide the SQL statement used to validate the connection. The following is an example of how you might specify a SQL statement to validate a connection for Oracle:

    <check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
    

    For MySQL or PostgreSQL, you might specify the following SQL statement. This also works for the H2 database.

    <check-valid-connection-sql>select 1</check-valid-connection-sql>
    
  17. 2015-10-02 - Using variables in the CLI script; Tags: Using variables in the CLI script
    Loading...

    Using variables in the CLI script

    JBoss can use variables (passed as parameters) in the CLI script. This post describes the details behind it. If the parameter is not passed, it can used the given default.

    Expression

    Expressions can be used in the XML and CLI configuration. Usage of port-offset expression in standalone.xml

    <socket-binding-group name="standard-sockets" default-interface="public"
     port-offset="${jboss.socket.binding.port-offset:0}">
    

    ${jboss.socket.binding.port-offset:0} is a Beanshell expression which means, unless the jboss.socket.binding.port-offset is set, it evaluates to 0 so to standard sockets. To pass the property as argument

    standalone.sh -Djboss.socket.binding.port-offset=100
    

    Using properties file

    The parameters can also be passed in a properties file. JBoss provides the runtime argument for standalone and domain mode

    -P <url>
    -P=<url>
    --properties=<url>
    

    See also Reference of Switches and Arguments to pass at Server Runtime. Content of custom.properties

    test-port=17070
    

    The notation in the CLI script is "${test-port}". Start JBoss with properties file

    # short
    domain.sh -P=custom.properties
    # full
    domain.sh --properties=custom.properties
    

    Use expression in CLI

    Check with operation read-resource-description if expressions are allowed.

    Check expression capability

    If you want to use an expression, you should check if the expression capability is given.

    [domain@localhost:9999 /] /socket-binding-group="standard-sockets"/socket-binding="http":read-resource-description > C:\TEMP\jboss-out.txt
    

    This will give you this output (shortened)

    {
        "outcome" => "success",
        "result" => {
            "description" => "Configuration information for a socket.",
            "access-constraints" => {"sensitive" => {"socket-config" => {"type" => "core"}}},
            "attributes" => {
                "port" => {
                    "type" => INT,
                    "description" => "Number of the port to which the socket should be bound.",
                    "expressions-allowed" => true,
                    "nillable" => true,
                    "default" => 0,
                    "min" => 0L,
                    "max" => 65535L,
                    "access-type" => "read-write",
                    "storage" => "configuration",
                    "restart-required" => "all-services"
                },
         #...
    }
    

    For the port attribute "expressions-allowed" => true is the proof.

    Testing

    We create a new socket binding group and check if the port has an expression instead of the normal value.

    [domain@localhost:9999 /] /socket-binding-group="test-sockets":add(default-interface="public")
    {
        "outcome" => "success",
        "result" => undefined,
        "server-groups" => undefined
    }
    [domain@localhost:9999 /] /socket-binding-group="test-sockets"/socket-binding="http":add(port="${test-port:7070}")
    {
        "outcome" => "success",
        "result" => undefined,
        "server-groups" => undefined
    }
    [domain@localhost:9999 /] /socket-binding-group="test-sockets"/socket-binding="http":read-resource
    {
        "outcome" => "success",
        "result" => {
            "client-mappings" => undefined,
            "fixed-port" => false,
            "interface" => undefined,
            "multicast-address" => undefined,
            "multicast-port" => undefined,
            "name" => "http",
            "port" => expression "${test-port:7070}"
        }
    }
    
  18. 2015-09-04 - Using global variables in JNDI; Tags: Using global variables in JNDI
    Loading...

    Using global variables in JNDI

    Custom variables can be stored via JNDI over the naming subsystem in JBoss. Following example were executed for Java EE 6 and JBoss EAP 6.4.

    display help to add operation

    /subsystem=naming/binding=*:read-operation-description(name=add)
    

    add JNDI variable

    /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:add(binding-type=simple, value="/etc/metrics", type="java.lang.String")
    

    This JNDI variable can be used for resource injection.

    usage in Java

    @Resource(lookup="java:global/metrics/configuration/directory", type=String.class)
    private String configDir;
    

    read JNDI variable

    /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:read-resource
    

    remove JNDI variable

    /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:remove
    

    add variable and check

    [standalone@localhost:9999 /] /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:add(binding-type
    =simple, value="/etc/metrics", type="java.lang.String")
    {"outcome" => "success"}
    [standalone@localhost:9999 /] /subsystem=naming/binding=java\:global\/metrics\/configuration\/directory:read-resource
    {
     "outcome" => "success",
     "result" => {
     "binding-type" => "simple",
     "cache" => undefined,
     "class" => undefined,
     "environment" => undefined,
     "lookup" => undefined,
     "module" => undefined,
     "type" => "java.lang.String",
     "value" => "/etc/metrics"
     }
    }
    
  19. 2015-08-31 - Remove Logger in JBoss EAP 6.x, Wildfly configuration; Tags: Remove Logger in JBoss EAP 6.x, Wildfly configuration
    Loading...

    Remove Logger in JBoss EAP 6.x, Wildfly configuration

    For local testing, the logging is an essential tool. If you have to make changes to loggers, some conflicts arise. The easiest way is to remove the previous configuration. If you want to cleanup your previous logging, this article demonstrates the basic steps for a CLI script, that can be used for each test.

    This example removes a logger ( name ≡ CATEGORY) and the respective log handler.

    # =====================================
    #       _
    #   ___| | ___  __ _ _ __  _   _ _ __
    #  / __| |/ _ \/ _` | '_ \| | | | '_ \
    # | (__| |  __/ (_| | | | | |_| | |_) |
    #  \___|_|\___|\__,_|_| |_|\__,_| .__/
    #                               |_|
    # =====================================
    # /subsystem=logging/logger=CATEGORY:read-resource
    # /subsystem=logging/logger=CATEGORY:unassign-handler(name="HANDLER")
    # /subsystem=logging/logger=CATEGORY:remove
    # =====================================
    # HTTP pool logger
    if (outcome == success) of /subsystem=logging/logger=metrics-http-stat:read-resource
        /subsystem=logging/logger=metrics-http-stat:unassign-handler(name="METRICS")
        /subsystem=logging/logger=metrics-http-stat:remove
    end-if
    # ===================
    # remove file handler
    # ===================
    if (outcome == success) of /subsystem=logging/periodic-rotating-file-handler=METRICS:read-resource
        /subsystem=logging/periodic-rotating-file-handler=METRICS:remove
    end-if
    
    • The logger is checked, if true, we can remove it.
    • Before removal it has to be unassigned.
    • Remove the logger.
    • The final step is to remove the file handler.

    With read-resource you can always check if the resource exists. If you are unsure if can invoke read-resource-description. This command will list description of available attributes and childs.

    C:\jboss-eap-6.4\bin\jboss-cli.bat --connect --command="/subsystem=logging/periodic-rotating-file-handler=METRICS:read-resource-description" > output.txt
    

    See also

  20. 2015-08-10 - Configure separate log messages in JBoss; Tags: Configure separate log messages in JBoss
    Loading...

    Configure separate log messages in JBoss

    To configure JBoss to log certain messages of log category (class) is a simple way. This post illustrates two ways to achieve it.

    Adjust configuration file

    Editing the configuration file, e.g. standalone.xml for standalone mode, needs the JBoss instance not to be running.

    To log messages to another file, go to subsystem logging.

    <profile>
      <subsystem xmlns="urn:jboss:domain:logging:1.2">
    ..
    </profile>
    

    Add logger definition and binding within above section

    <periodic-rotating-file-handler name="MESSAGE_LOG" autoflush="true">
    <formatter>
    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <file relative-to="jboss.server.log.dir" path="message.log"/>
        <suffix value=".yyyy-MM-dd"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <!-- bind log category to above logger -->
    <logger category="net.cinhtau.adapter">
        <level name="DEBUG"/>
        <handlers>
            <handler name="MESSAGE_LOG"/>
        </handlers>
    </logger>
    

    Logger configuration as CLI script

    Configure the JBoss from CLI, needs a running JBoss instance.

    Add logger via CLI

    /subsystem=logging/periodic-rotating-file-handler=MESSAGE_LOG:add(
    		file={
    		  "path"=>"message.log",
    		  "relative-to"=>"jboss.server.log.dir"
    		},
    		suffix=".yyyy-MM-dd",
    		append="true",
    		formatter="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n",
    		autoflush="true")
    /subsystem=logging/logger=net.cinhtau.adapter:add(level=DEBUG, use-parent-handlers=false)
    /subsystem=logging/logger=net.cinhtau.adapter:assign-handler(name="MESSAGE_LOG")
    

    Check the folder log for your separate log file. For further details read for instance

  21. 2015-08-06 - Patch JBoss EAP installation; Tags: Patch JBoss EAP installation
    Loading...

    Patch JBoss EAP installation

    The patch command is a feature that was added in JBoss EAP 6.2. Following post demonstrates the patching process.

    The underlying JBoss has a port offset of 1. The JBoss instance should be running. Patch JBoss EAP 6.4.0 installation with the CLI

    tan@debian:/opt/jboss-patched/bin$ ./jboss-cli.sh --connect controller=localhost:10000
    [standalone@localhost:10000 /] patch apply /opt/jboss-eap-6.4.2-patch.zip
    {
        "outcome" : "success",
        "response-headers" : {
            "operation-requires-restart" : true,
            "process-state" : "restart-required"
        }
    }
    [standalone@localhost:10000 /] shutdown --restart=true
    [standalone@localhost:10000 /] quit
    
  22. 2015-08-05 - Enable management web console for JBoss/Wildfly; Tags: Enable management web console for JBoss/Wildfly
    Loading...

    Enable management web console for JBoss/Wildfly

    A fresh JBoss EAP installation, has no web console activated. It requires a management user for that. This article explains the basic steps how to activate the management web console.

    For demo purposes, configure simple passwords

    bk201@debian:/opt/jboss-eap-6.4/bin$ vim add-user.properties
    

    Allow simple demo passwords by changing REJECT to RELAX

    # Valid values: RELAX, WARN or REJECT
    # RELAX : Don't perform any strength checks on the password in both interactive and non-interactive mode
    # WARN : Display a message about the strength of the password. Ask confirmation if the password is weak in interactive mode
    # REJECT : Display a message about the strength of the password (if the password is weak, the user is not created).
    # Ask confirmation if the password is weak in interactive mode
    password.restriction=RELAX
    

    Add a management user for authentication to the management console

    bk201@debian:/opt/jboss-eap-6.4/bin$ ./add-user.sh
    What type of user do you wish to add?
     a) Management User (mgmt-users.properties)
     b) Application User (application-users.properties)
    (a): a
    Enter the details of the new user to add.
    Using realm 'ManagementRealm' as discovered from the existing property files.
    Username : admin
    The username 'admin' is easy to guess
    Are you sure you want to add user 'admin' yes/no? yes
    Password :
    Re-enter Password :
    What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]:
    About to add user 'admin' for realm 'ManagementRealm'
    Is this correct yes/no? yes
    Added user 'admin' to file '/opt/jboss-eap-6.4/standalone/configuration/mgmt-users.properties'
    Added user 'admin' to file '/opt/jboss-eap-6.4/domain/configuration/mgmt-users.properties'
    Added user 'admin' with groups  to file '/opt/jboss-eap-6.4/standalone/configuration/mgmt-groups.properties'
    Added user 'admin' with groups  to file '/opt/jboss-eap-6.4/domain/configuration/mgmt-groups.properties'
    Is this new user going to be used for one AS process to connect to another AS process?
    e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server EJB calls.
    yes/no? yes
    To represent the user add the following to the server-identities definition <secret value="YWRtaW4=" />
    

    If you open Console it should give you a prompt for authentication.

    Port forwarding

    Working in a virtual machine, and port forwarding requires to access from any other address. Bind management interface to any address

    <interfaces>
        <interface name="management">
            <any-address/>
        </interface>
        <interface name="public">
            <any-address/>
        </interface>
        <interface name="unsecure">
            <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
        </interface>
    </interfaces>
    

    By default (due to security reasons) JBoss binds only to localhost. If you want to access it via your hostname or IP, then you can edit the JBOSS_HOME/standalone/configuration/standalone.xml to change the “public” and “management” interfaces to point to the hostname of your system: Bind management interface to dedicated address

    <interfaces>
      <interface name="management">
        <inet-address value="${jboss.bind.address.management:192.168.1.100}"/>
      </interface>
      <interface name="public">
        <inet-address value="${jboss.bind.address:192.168.1.100}"/>
     </interface>
    </interfaces>
    
  23. 2015-07-06 - Add HyperSQL module to JBoss; Tags: Add HyperSQL module to JBoss
    Loading...

    Add HyperSQL module to JBoss

    This post explains how to create a hsqldb module for JBoss EAP.

    Admin CLI

    This CLI instruction will copy the JDBC jar into the created module folder. As dependencies the Java EE APIs are referenced.

    module add --name=org.hsqldb.jdbcDriver \
     --resources=C:\Daten\lib\hsqldb.jar \
     --dependencies=javax.api,javax.transaction.api
    

    Manual installation

    Create the following module for HSQLDB under JBOSS_HOME/modules

    +---org
          +----hsqldb
                    +-----main
                          module.xml
                          hsqldb.jar
    

    Contents of module.xml

    <module xmlns="urn:jboss:module:1.0" name="org.hsqldb">
      <resources>
        <resource-root path="hsqldb.jar"/>
      </resources>
      <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
      </dependencies>
    </module>
    

    Copy the hsqldb.jar in the folder main. Configuration: Add in standalone.xml following datasource

    <datasource jndi-name="java:/testHSQLMem" pool-name="testHSQLMem"
     enabled="true" use-java-context="true">
     <connection-url>jdbc:hsqldb:mem:test</connection-url>
     <driver>hsqldb</driver>
       <security>
        <user-name>sa</user-name>
    <password></password>
       </security>
    </datasource>
    ..
    <drivers>
     <driver name="hsqldb" module="org.hsqldb">
       <driver-class>org.hsqldb.jdbcDriver</driver-class>
     </driver>
    </drivers>
    
  24. 2015-07-06 - Show SQL statements in JBoss; Tags: Show SQL statements in JBoss
    Loading...

    Show SQL statements in JBoss

    Enable property in persistence.xml

    <persistence -unit name="myPU">
        <jta-data-source>java:/oracledb</jta-data-source>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"></property>
    <property name="showSql" value="true"></property>
        </properties>
    </persistence>

    Set level debug in logback.xml or logback-test.xml.

    <logger name="org.hibernate.SQL" level="DEBUG"></logger>
    

    If you have another logging framework, you might adapt it there. Commands for the JBoss cli

    /subsystem=logging/logger=org.hibernate.SQL:add
    /subsystem=logging/logger=org.hibernate.SQL:write-attribute(name="level", value="DEBUG")
    /subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="DEBUG")
    

    Steps explained:

    • Add logger for subsystem logging
    • Set (write) log level for above logger
    • Set root log level to debug (not mandatory)