Showing posts with label JBoss AS 7.1.1. Show all posts
Showing posts with label JBoss AS 7.1.1. Show all posts

Thursday, January 29, 2015

JBoss7.1.1 Logging Runtime Change | JBoss AS 7.1.1 - Logging Configuration and Change at Runtime

Console Handler


Open standalone.xml and search for"<subsystem xmlns="urn:jboss:domain:logging:1.1".
For Console type handler, add the following:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
  <console-handler name="CONSOLE">
    <level name="INFO"/>
    <formatter>
      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
    </formatter>
  </console-handler>
  <logger category="com.arjuna">
    <level name="WARN"/>
  </logger>
  <root-logger>
    <level name="WARN"/>
    <handlers>
      <handler name="CONSOLE"/>
    </handlers>
  </root-logger>
</subsystem>

Periodic Rotating File Handler


Configure periodic rotating file handler in this way:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
  <periodic-rotating-file-handler name="FILE">
    <formatter>
      <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
    </formatter>
    <file relative-to="jboss.server.log.dir" path="server.log"/>
    <suffix value=".yyyy-MM-dd"/>
    <append value="true"/>
  </periodic-rotating-file-handler>
  <logger category="com.arjuna">
    <level name="WARN"/>
  </logger>
  <root-logger>
    <level name="WARN"/>
    <handlers>
      <handler name="CONSOLE"/>
    </handlers>
  </root-logger>
</subsystem>

Size Rotating File Handler


Configure file rotating file handler in this way:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
  <size-rotating-file-handler name="FILE">
    <formatter>
    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
    </formatter>
    <file relative-to="jboss.server.log.dir" path="server.log"/>
    <append value="true"/>
    <!-- size of a log file -->
    <rotate-size value="20M"/>
    <!-- no of log files to keep -->
    <max-backup-index value="50"/>
  </size-rotating-file-handl
  <logger category="com.arjuna">
    <level name="WARN"/>
  </logger>
  <root-logger>
    <level name="WARN"/>
    <handlers>
      <handler name="CONSOLE"/>
    </handlers>
  </root-logger>
</subsystem>

Change At Runtime


All these can be done at runtime without restarting JBoss. Check out the image below as a reference.






Create a Successful Online Store at Bigcommerce! Try it Free Now!

Tuesday, January 27, 2015

JBoss AS 7.1.1 - HornetQ UnsatisfiedLinkError

You will see this exception when you are running HornetQ in JBoss 7 with debug level log enabled:

FINE [org.hornetq.core.asyncio.impl.AsynchronousFileImpl]  HornetQAIO -> error loading the native library

java.lang.UnsatisfiedLinkError: no HornetQAIO in java.library.path

          at java.lang.ClassLoader.loadLibrary(Unknown Source) 

This however is expected and the log level is trace. This message tries to inform you that the libAIO layer will look for either libHornetQAIO.so, libHornetQAIO32.so or libHornetQAIO64.so on your LD_LIBRARY_PATH. and if it can't use either of those it will fall back to NIO.





Create a Successful Online Store at Bigcommerce! Try it Free Now!

Monday, January 26, 2015

JBoss AS 7.1.1 - Crypto Libreary Not Found Issue When Migration from JBoss 4.2.3

JBoss 7.1.1 Crypto Library Not Found Issue

When I was migrating an application from JBoss 4 (4.2.3) to JBoss 7 (7.1.1), I encountered an issue:

java.lang.ClassNotFoundException: com.sun.crypto.provider.SunJCE

JBoss 7.1.1 Crypto Library Not Found Solution

After some search on the Internet, I managed to find a solution. Steps:
  1. Create a directory modules/sun/jdk/main;
  2. Under 'main', create a file module.xml;
  3. Add the following content to the file.
<module xmlns="urn:jboss:module:1.1" name="sun.jdk">
<resources>
    <resource-root path="service-loader-resources"/>
</resources>
<dependencies>
    <system export="true">
        <paths>
            <path name="com/sun/crypto/provider"/>
            <path name="com/sun/script/javascript"/>
            <path name="com/sun/jndi/dns"/>
            <path name="com/sun/jndi/ldap"/>
            <path name="com/sun/jndi/url"/>
            <path name="com/sun/jndi/url/dns"/>
            <path name="com/sun/security/auth"/>
            <path name="com/sun/security/auth/login"/>
            <path name="com/sun/security/auth/module"/>
            <path name="sun/misc"/>
            <path name="sun/io"/>
            <path name="sun/nio"/>
            <path name="sun/nio/ch"/>
            <path name="sun/security"/>
            <path name="sun/security/krb5"/>
            <path name="sun/util"/>
            <path name="sun/util/calendar"/>
            <path name="sun/util/locale"/>
            <path name="sun/security/provider"/>
            <path name="META-INF/services"/>
        </paths>
        <exports>
            <include-set>
                <path name="META-INF/services"/>
            </include-set>
        </exports>
    </system>
</dependencies>

The tricky part is path name="com/sun/crypto/provider"/>, which instructs JBoss to load necessary crypto lib for you.



Create a Successful Online Store at Bigcommerce! Try it Free Now!

Saturday, January 24, 2015

JBoss7.1.1 JMS | JBoss AS 7.1.1 - JMS Configuration

This article summarizes the issues I encountered during migration of a JMS application
from JBoss 4.2.3 to 7.1.1.

Configure Messaging and Remoting Modules

Refer to this article: http://blog.avisi.nl/2012/10/10/configuring-camel-to-use-hornetq-in-jboss-as-7.

RMI Port

if you previously used something like jnp://localhost:1099/, you need change it to remote://localhost:4447.

Handle Exception: javax.security.sasl.SaslException: 

Authentication failed: all available authentication mechanisms failed.
You need to add a user under Application Realm or remove the authentication by removing security-realm="ApplicationRealm" from
<subsystem xmlns="urn:jboss:domain:remoting:1.1">
           <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>
in your standalone.xml.

Handle Exception: javax.jms.JMSSecurityException

Unable to validate user: null
You need to set "security-enabled" to false in the standalone.xml.
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
     <hornetq-server>
         <security-enabled>false</security-enabled>
         ......
     </hornetq-server>
</subsystem>

Add System Properties

System properties can be added into standalone.xml.
<server>
<extensions>
</extensions>
<system-properties>
     <property name="propertyName" value="property value"/>
</system-properties>
</server>

Then, in your program, you can retrieve them using System.getProperty("propertyName").

Create JmsTemplate for Topics

<bean id="jmsTopicTemplate" class="org.springframework.jms.core.JmsTemplate">
   <constructor-arg ref="connectionFactory" />
   <property name="pubSubDomain" value="true"/>
</bean>

Summary of Dependent Libs

hornetq-core-2.2.13.Final.jar
hornetq-jms-2.2.13.Final.jar
jboss-remote-naming-1.0.2.Final.jar
netty-3.2.6.Final.jar
spreing-jms-3.2.5.RELEASE.jar

Check more details here.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

JBoss7.1.1 JSF | JBoss AS 7.1.1 - Use Alternative JSF Implementation

JBoss AS 7.1 ships with JSF 2.1.7 which causes NullPointerException at startTrackViewModifications(StateContext.java:172).
The workaround to overcome this is to use your own JSF implementation.
First, copy JSF API jar (e.g. jsf-api-2.1.16.jar) to ${jboss_home}/modules/javax/faces/api/main, and then edit module.xml to add
Similarly, copy JSF implementation jar to C:\jboss-as-7.1.1.Final\modules\com\sun\jsf-impl\main and edit module.xml.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Friday, January 23, 2015

JBoss7.1.1 Remoting JMX | JBoss AS 7.1.1 - Enable JMX

If you want to monitor if JBoss is running via JMX (Remoting JMX). This article is for you.

Update JBoss Configuration File for Remoting JMX

First, you need to add the following into $JBOSS_HOME/standalone/configuration/standalone.xml,
<server xmlns="urn:jboss:domain:1.2">
  <extensions>
    <extension module="org.jboss.as.jmx"/>
  </extensions>
  <profile>
    <subsystem xmlns="urn:jboss:domain:jmx:1.1">
      <show-model value="true"/>
      <remoting-connector/>
    </subsystem>
  </profile>
</server>
Then, run the server in the STANDALONE mode.

Dependent Jars for Maven or Normal Java Projects

Next, in your Maven project, add the following dependencies,
<dependency>
  <groupId>org.jboss.remotingjmx</groupId>
  <artifactId>remoting-jmx</artifactId>
  <version>1.0.2.Final</version>
</dependency>
<dependency>
  <groupId>org.jboss.marshalling</groupId>
  <artifactId>jboss-marshalling-river</artifactId>
  <version>1.3.11.GA</version>
</dependency>
<dependency>
  <groupId>org.jboss.sasl</groupId>
  <artifactId>jboss-sasl</artifactId>
  <version>1.0.0.Final</version>
</dependency>
<dependency>
  <groupId>org.jboss.xnio</groupId>
  <artifactId>xnio-nio</artifactId>
  <version>3.0.3.GA</version>
</dependency>
If the project is a basic Java project, add the following to the classpath:
remoting-jmx-1.0.2.Final.jar
jboss-logmanager-1.2.2.GA.jar
jboss-logging-3.1.0.GA.jar
jboss-marshalling-1.3.9.GA.jar
jboss-remoting-3.2.2.GA.jar
xnio-api-3.0.3.GA.jar
jboss-marshalling-river-1.3.11.GA.jar
jboss-sasl-1.0.0.Final.jar
xnio-nio-3.0.3.GA.jar
You can find the locations of these jars in $JBOSS_HOME/bin/jconsole.sh or jconsole.bat.

Keep in mind that JBoss does not use standard JMX and use its own remoting JMX instead. So make sure you have include the remoting jmx jars. The shortcoming for doing this is your project will depend on some JBoss jars.
AVG AntiVirus 2015

Code Snippet for JBoss Monitoring via JMX 

To test it, use the code snippet:
//the remoting JMX service URL; port 9999 is the default one.
String serverUrl = "service:jmx:remoting-jmx://localhost:9999";

JMXServiceURL url = new JMXServiceURL(serverUrl);

JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

//find the object to be monitored 
ObjectName objectName = new ObjectName("jboss.as:management-root=server");

//serverState has a couple of possible values, like running, starting, stopping and stopped.
Object response = mbsc.getAttribute(objectName, "serverState");

jmxc.close();


Create a Successful Online Store at Bigcommerce! Try it Free Now!