Category Archives: JBoss

Remove H2 JDBC-Driver from EAP6

To remove the H2 JDBC-driver from your EAP6 simply remove the relevant part from your standalone.xml:

<driver name="h2" module="com.h2database.h2">
  <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>

Or with cli:

/subsystem=datasources/jdbc-driver=h2:remove

 

Remove ExampleDS datasource in EAP6

To remove the ExampleDS datasource simply remove the relevant part from your standalone.xml:

<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
  <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
  <driver>h2</driver>
  <security>
    <user-name>sa</user-name>
    <password>sa</password>
  </security>
</datasource>

Or with cli:

/subsystem=datasources/data-source=ExampleDS:remove

 

Configure Aliases in EAP6

The default configuration states localhost and example.com as aliases. To change this you have to simply change or remove the specific parts of your virtual-server config in your standalone.xml:

<virtual-server name="default-host" enable-welcome-root="false">
  <alias name="localhost"/>
</virtual-server>

This would only be a single alias with value localhost (and disabled welcome root).

Or to change it with cli:

/subsystem=web/virtual-server=default-host:write-attribute(name=alias,value=["localhost"])

 

Disable welcome-root in EAP6

To remove the default welcome page your have to change your virtual server config in your standalone.xml to state enable-welcome-root=”false”:

<virtual-server name="default-host" enable-welcome-root="false">
  <alias name="localhost"/>
</virtual-server>

Or with cli:

/subsystem=web/virtual-server=default-host:write-attribute(name=enable-welcome-root,value=false)

 

Change SERVER header in EAP6

I found no way to remove the Server header in EAP6. But there is a way to change its content. Just add the folling config to your standalone.xml:

<system-properties>
  <property name="org.apache.coyote.http11.Http11Protocol.SERVER" value="foo"/>
</system-properties>

Or with cli:

/system-property=org.apache.coyote.http11.Http11Protocol.SERVER:add(value=foo)

Then your header just is Server: foo instead.

Remove X_POWERED_BY Header in JBoss EAP6

First you have to disable it in standalone.xml by adding jsp-configuration x-powered-by=”false”. Here the relevant part of my config:

<subsystem xmlns="urn:jboss:domain:web:1.5" default-virtual-server="default-host" native="false">
  <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
  <virtual-server name="default-host" enable-welcome-root="false">
    <alias name="localhost"/>
  </virtual-server>
  <configuration>
    <jsp-configuration x-powered-by="false"/>
  </configuration>
</subsystem>

Or with cli:

/subsystem=web/configuration=jsp-configuration:write-attribute(name=x-powered-by,value=false)

In a JSF application you have to add the following context param:

<context-param>
    <param-name>com.sun.faces.sendPoweredByHeader</param-name>
    <param-value>false</param-value>
</context-param>

Then start your server and the header should be gone.

Make your webapplication log debug messages under jboss

I often catch myself writing info-messages because jboss is configured to info-mode by default. By adding the following few lines you can make your application use debug mode:

<subsystem xmlns="urn:jboss:domain:logging:2.0">
  ...
  <!-- add begin -->
  <console-handler name="DEBUGCONSOLE">
    <level name="DEBUG" />
    <formatter>
      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%F:%L)  %s%E%n" />
    </formatter>
  </console-handler>
  <logger category="pm.mbo" use-parent-handlers="false">
    <level name="DEBUG" />
    <handlers>
      <handler name="DEBUGCONSOLE" />
    </handlers>
  </logger>
  <!-- add end -->
  ...
</subsystem>

Of course you have to change the category (your package name) in the logger. The snippet is from Wildfly 8.1. But it is the same approach for JBoss AS 7+.

Get rid of Wildfly/JBoss headers “Server” and “X-Powered-By”

If you don’t want to send these headers with every response you have to disable them in your configuration file (standalone.xml).

I just removed the following lines from my undertow subsystem (urn:jboss:domain:undertow:1.1):

<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
...
<response-header name="server-header" header-name="Server" header-value="WildFly/8"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>

After a server restart the headers were gone.

JBoss Login Configuration

Here a short example for a security-domain that has to be configured in the urn:jboss:domain:security subsystem:

<security-domain name="mysecuritydomain" cache-type="default">
  <authentication>
    <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
      <module-option name="dsJndiName" value="java:jboss/datasources/ExampleDS" />
      <module-option name="principalsQuery" value="select u.password from users u where u.name=?" />
      <module-option name="rolesQuery" value="select r.name as rolename, 'Roles' as rolegroup from users u, roles r, users_roles ur where ur.user_id=u.id and ur.role_id=r.id and u.name=?" />
      <module-option name="hashAlgorithm" value="SHA-256" />
      <module-option name="hashEncoding" value="base64" />
      <module-option name="hashCharset" value="UTF-8" />
    </login-module>
  </authentication>
</security-domain>

To use the domain in your application here an example jboss-web.xml descriptor:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd"
	version="6.0">
	<security-domain>mysecuritydomain</security-domain>
	<context-root>/example</context-root>
</jboss-web>

JBoss JDBC Module Creator

Every time I download a new jboss I have to add the needed jdbc module manually. And every time I have to look how the module.xml has to look like. So I decided to write a simple script that creates a module for PostgreSQL. with some configuration, it should be capable of creating every jdbc module you want. Just see the options it supports.

You can see my project at github: https://github.com/mbogner/jboss_module_creator

Here some instructions how to run it with default options:

[codesyntax lang=”bash”]

git clone https://github.com/mbogner/jboss_module_creator
cd jboss_module_creator
./jboss_module_creator.pl

[/codesyntax]