Helpful tips and tricks for JBoss.
- Set
JAVA_OPTS
:/etc/default/jboss-eap.conf
- Modified Accented Characters on REST calls: if your REST calls containing accented characters are being modified, add the following to your
standalone-full.xml
:
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="false"/>
</system-properties>
standalone-full.xml
:
<system-properties>
<property name="jboss.as.management.blocking.timeout" value="600"/>
</system-properties>
Stackoverflow provided a nice explanation on how to list all running REST end points in JBoss.
Simply add the following to your web.xml
:
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>org.jboss.resteasy.plugins.stats.RegistryStatsResource</param-value>
</context-param
Once JBoss is running, the URL follows this format: http://[hostname]:[port]/[context]/[api-path]/resteasy/registry
To generate a unique id to use in logging (for example in your server.log), do the following:
package org.my.personal.stuff;
import java.io.IOException;
import java.util.UUID;
import javax.servlet.ServletException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.valves.ValveBase;
import org.jboss.logging.Logger;
import org.jboss.logging.MDC;
public class MyJBossLogger extends ValveBase {
public static final String UID = "uid";
static String computeUid() {
return UUID.randomUUID().toString();
}
static ThreadLocal<String> setLoggingUid(final ThreadLocal<String> threadLocal, final String uid) {
threadLocal.set(uid);
return threadLocal;
}
static ThreadLocal<String> setupLogging(final String uid) {
MDC.put(UID, AndreasLoggingContext.setTransactionId(uid));
return setLoggingUid(new ThreadLocal<>(), uid);
}
static String cleanupUid(final ThreadLocal<String> theadLocal) {
final String retVal = threadLocal.get();
threadLocal.remove();
return retVal;
}
static void cleaupLogging(final ThreadLocal<String> theadLocal) {
MDC.remove(cleanupUid(threadLocal));
}
void invoke(final ThreadLocal<String> theadLocal, final Request request, final Response response) throws IOException, ServletException {
try {
getNext().invoke(request, response);
} finally {
cleaupLogging(theadLocal);
}
}
@Override
public void invoke(final Request request, final Response response) throws IOException, ServletException {
invoke(setupLogging(computeUid()), request, response);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>[your sub URL]</context-root>
<valve>
<class-name>org.my.personal.stuff.MyJBossLogger</class-name>
</valve>
</jboss-web>
...
<profile>
<subsystem xmlns="urn:jboss:domain:logging:1.3">
...
<console-handler name="CONSOLE">
...
<formatter>
<pattern-formatter pattern="..."e;%X{uid}"..."/>
...
</formatter>
...
</console>
...
</subsystem>
...
</profile>