JBoss Archive

How to change Default Ports in JBoss Application Server

These are the default ports in JBoss Application Server

TCP 1090 – RMI/JRMP socket for connecting to the JMX MBeanServer
TCP 1091 – RMI server socket
TCP 1099 – JNDI Service
TCP 1098 – RMI Port for JNDI Service
TCP 4446 – JBoss Remoting Connector
TCP 4712 – JBossTS Service
TCP 4713 – JBossTS Service
TCP 5445 – HornetQ JMS Service
TCP 5455 – HornetQ Netty port
TCP 5500 – JBoss Remoting
TCP 5501 – JBoss Remoting ssl
TCP 8009 – Web server AjpConnector
TCP 8080 – Web server HTTP Connector
TCP 8083 – Web services

To change the port, we need to edit the bindings-jboss-beans.xml present at the following location.

jboss-as\server\myserver1\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml

e.g. if we want to change the JNDI port, we need to update the port property for the Naming Service

 

 <!-- Naming Service -->
            <bean class="org.jboss.services.binding.ServiceBindingMetadata">
               <property name="serviceName">jboss:service=Naming</property>
               <property name="bindingName">Port</property>
               <property name="port">1999</property>
               <property name="description">The listening socket for the Naming service</property>
            </bean>

Ref :- https://community.jboss.org/wiki/ConfigurePorts

Topic Send and Topic Receive demo on JBoss Application Server

1 )Create a topic

Add the following in the \deploy\messaging\destinations-service.xml file

 

    <mbean code="org.jboss.jms.server.destination.TopicService"
      name="jboss.messaging.destination:service=Topic,name=Topic1"
      xmbean-dd="xmdesc/Topic-xmbean.xml">
	<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
	<depends>jboss.messaging:service=PostOffice</depends>
   </mbean>

2) Copy the TopicSend and TopicReceive programs to a folder.

TopicSend

import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
import javax.rmi.PortableRemoteObject;

public class TopicSend
{
// Defines the JNDI context factory.
public final static String JNDI_FACTORY=”org.jnp.interfaces.NamingContextFactory”;
// Defines the JMS connection factory.
public final static String JMS_FACTORY=”ConnectionFactory”;
// Defines the topic.
public final static String TOPIC=”/topic/Topic1″;

protected TopicConnectionFactory tconFactory;
protected TopicConnection tcon;
protected TopicSession tsession;
protected TopicPublisher tpublisher;
protected Topic topic;
protected TextMessage msg;

public void init(Context ctx, String topicName)
throws NamingException, JMSException
{
tconFactory = (TopicConnectionFactory)
PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY),
TopicConnectionFactory.class);
tcon = tconFactory.createTopicConnection();
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(topicName), Topic.class);
tpublisher = tsession.createPublisher(topic);
msg = tsession.createTextMessage();
tcon.start();
}

public void send(String message) throws JMSException {
msg.setText(message);
tpublisher.publish(msg);
}

public void close() throws JMSException {
tpublisher.close();
tsession.close();
tcon.close();
}

public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println(“Usage: java TopicSend jboss_url”);
return;
}
InitialContext ic = getInitialContext(args[0]);
TopicSend ts = new TopicSend();
ts.init(ic, TOPIC);
readAndSend(ts);
ts.close();
}

protected static void readAndSend(TopicSend ts)
throws IOException, JMSException
{
BufferedReader msgStream = new BufferedReader (new InputStreamReader(System.in));
String line=null;
do {
System.out.print(“Enter message (\”quit\” to quit): \n”);
line = msgStream.readLine();
if (line != null && line.trim().length() != 0) {
ts.send(line);
System.out.println(“JMS Message Sent: “+line+”\n”);
}
} while (line != null && ! line.equalsIgnoreCase(“quit”));
}

protected static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);

return new InitialContext(env);
}

}

TopicReceive

import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
import javax.rmi.PortableRemoteObject;

public class TopicReceive implements MessageListener {

// Defines the JNDI context factory.
public final static String JNDI_FACTORY=”org.jnp.interfaces.NamingContextFactory”;
// Defines the JMS connection factory for the topic.
public final static String JMS_FACTORY=”ConnectionFactory”;
// Defines the topic.
public final static String TOPIC=”/topic/Topic1″;

private TopicConnectionFactory tconFactory;
private TopicConnection tcon;
private TopicSession tsession;
private TopicSubscriber tsubscriber;
private Topic topic;
private boolean quit = false;

/**
* Message listener interface.
* @param msg message
*/
public void onMessage(Message msg) {
try {
String msgText;

if (msg instanceof TextMessage) {
msgText = ((TextMessage)msg).getText();
} else {
msgText = msg.toString();
}

System.out.println(“JMS Message Received: “+ msgText );

if (msgText.equalsIgnoreCase(“quit”)) {
synchronized(this) {
quit = true;
this.notifyAll(); // Notify main thread to quit
}
}
} catch (JMSException jmse) {
System.err.println(“An exception occurred: “+jmse.getMessage());
}
}

public void init(Context ctx, String topicName)
throws NamingException, JMSException
{
tconFactory = (TopicConnectionFactory)
PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY),
TopicConnectionFactory.class);
tcon = tconFactory.createTopicConnection();
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic)
PortableRemoteObject.narrow(ctx.lookup(topicName),
Topic.class);
tsubscriber = tsession.createSubscriber(topic);
tsubscriber.setMessageListener(this);
tcon.start();
}

/**
* Closes JMS objects.
*
* @exception JMSException if JMS fails to close objects due to internal error
*/
public void close() throws JMSException {
tsubscriber.close();
tsession.close();
tcon.close();
}

public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println(“Usage: java TopicReceive jboss_url”);
return;
}
InitialContext ic = getInitialContext(args[0]);
TopicReceive tr = new TopicReceive();
tr.init(ic, TOPIC);

System.out.println(“JMS Ready To Receive Messages (To quit, send a \”quit\” message).”);

// Wait until a “quit” message has been received.
synchronized(tr) {
while (! tr.quit) {
try {
tr.wait();
} catch (InterruptedException ie) {}
}
}
tr.close();
}

private static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);

return new InitialContext(env);
}

}

 

3) Start your Jboss Server

D:\JBossEnterprisePlatform-5.1.1_New\jboss-eap-5.1\jboss-as\bin>run -c server1 -b 0.0.0.0

4) Open two command prompts, compile and run the two programs as follows.

C:\JBoss\LABS>set classpath=D:\JBossEnterprisePlatform-5.1.1_New\jboss-eap-5.1\jboss-as\client\*;.;
C:\JBoss\LABS>javac TopicReceive.java
C:\JBoss\LABS>java TopicReceive jnp://localhost:1099

C:\JBoss\LABS>set classpath=D:\JBossEnterprisePlatform-5.1.1_New\jboss-eap-5.1\jboss-as\client\*;.;
C:\JBoss\LABS>javac TopicSend.java
C:\JBoss\LABS>java TopicSend jnp://localhost:1099

You can have multiple receivers.

Please let us know if you face any issues.

Cheers!
Wonders Team

Changing default ports in Jboss

The Jboss port configuration is defined by the ServiceBindingManager service of JBoss.  There could be scenarios where you might want to change the default JBoss server ports. The Jboss Web Server by default runs on port 8080 and a set of other services run on a predefined set of ports which is specified in the server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml.

You can change the default ports in two ways.

1. Specifying as VM Parameter.

Start JBoss with the VM parameter jboss.service.binding.set set to either ports-defaultports-01,ports-02 etc. For example:

run -Djboss.service.binding.set=ports-01

 

2.Edit the ServiceBinding configuration file.

This requires to manually edit the server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml

Note: This file defines the default port bindings specified by “ports-default

<!– The name of the set of bindings to use for this server –>

<parameter>${jboss.service.binding.set:ports-default}</parameter>

You can change the default ports by any of the below values.

ports-01 : Has 100 as an offset port

ports-02 : Has 200 as an offset port

ports-03: Has 300 as an offset port.

A sample entry in the file would look like below.

**********************************************************************

 

<!-- The ports-default bindings are obtained by taking the base bindings and adding t0 to each port value  -->

<bean name="PortsDefaultBindings"  class="org.jboss.services.binding.impl.ServiceBindingSet">

<constructor>

<!--  The name of the set -->

<parameter>ports-default</parameter>

<!-- Default host name -->

<parameter>${jboss.bind.address}</parameter>

<!-- The port offset -->

<parameter>0</parameter>

<!-- Set of bindings to which the "offset by X" approach can't be applied -->

<parameter><null/></parameter>

</constructor>

</bean>

 

**********************************************************************

Now if you want to change the default ports specify the below entry.

 

<parameter>${jboss.service.binding.set:ports-01}</parameter>

 

Changing the configuration manually is a tedious process and requires some other xml files to be changed. However it is recommended to follow the first approach.

For more on Service Binding Manager, refer below link.

http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Web_Platform/5/html/Getting_Started_Guide/The_Service_Binding_Manager.html

Cheers,

Wonders Team. 🙂

JBoss Twiddle utility examples

The below post describes some common usage scenarios of the twiddle JBoss command line utility.

JBoss provides a simple command line tool that allows for interaction with a remote JMX server instance. This tool is called twiddle (for twiddling bits via JMX) and is located in the bin directory of the distribution. Twiddle is a command execution tool, not a general command shell.

Twiddle utility is located in $JBOSS_HOME/bin directory.

You can refer a good read on Twiddle basics from the below link.

http://weblogic-wonders.com/weblogic/2010/12/22/jboss-command-line-utility-twiddle/

Twiddle commands to read the information.

Getting Server Information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:type=ServerInfo"

Getting Global JNDI Information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss:service=JNDIView"

Getitng Jboss Logging Information

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:type=Log4jService,service=Logging"

Getting Thread Pool information:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin get "jboss.system:service=ThreadPool"

Twiddle commands to execute operations.

Deploying an application:

twiddle.bat -s jnp://localhost:1099  --user=admin --password=admin invoke "jboss.system:service=MainDeployer" deploy "file:\D:\TestApp.war"

Re-Deploying an application:

twiddle.bat -s jnp://localhost:1099  --user=admin --password=admin invoke "jboss.system:service=MainDeployer" redeploy "file:\D:\TestApp.war"

Un-Deploying an application:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:service=MainDeployer" undeploy "file:\D:\TestApp.war"

Capturing Thread Dumps:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadDump

List the thread CPU utilization

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadCpuUtilization
NOTE: The output is in table format, you can redirect the output in a html page for better viewing.
G:\jboss-eap-5.1\jboss-as\bin>twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=ServerInfo" listThreadCpuUtilization>> c:\out.html

Listing the memory pools:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:type=ServerInfo" listMemoryPools true

Changing logging levels to Debug

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin  invoke "jboss.system:type=Log4jService,service=Logging" setLoggerLevel org.apache debug

Stopping a  DataSource:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss:service=Hypersonic,database=localDB"  stop

Starting a DataSource:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss:service=Hypersonic,database=localDB"  start

Stopping the server:

twiddle.bat -s jnp://localhost:1099 --user=admin --password=admin invoke "jboss.system:type=Server" shutdown

Some of the other JMX services that can be used as below.

•             jboss:type=Service,name=SystemProperties     -   enables you to view the system properties

•             jboss:service=JNDIView -                                                 enables you to view the contents of JNDI

•             jboss.system:type=Log4jService,service=Logging -  enable you to change log levels

•             jboss.system:service=ThreadPool -                             enables you to change the thread pool

•             jboss.system:type=Server -                                            provides information about the server

•             jboss.system:type=ServerConfig -                            provides information about the server

•             jboss.system:type=ServerInfo -                                provides information about the server

References:

http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.2/html/Server_Configuration_Guide/Connecting_to_the_JMX_Server-Command_Line_Access_to_JMX.html

Cheers,

Wonders Team 🙂

Thread Dumps in JBoss

The below article shows about capturing the Thread Dumps for JBoss Application Server in event of any server hangs or to diagnose any  performance bottlenecks using the JBoss Server Utilities.

Using JMX Console:

JMX-Console application is deployed on to the JBoss Application Server by default  and you can access the same using the below URL.

http://<HOST>:<PORT>/jmx-console/

NOTE: If the jmx-console prompts for the user credentials, use the default username/ password pair i.e. admin / admin.

1. Login into the JMX-Console.

Navigate to the  jboss.system object from the left panel –> Click on the ServerInfo MBean from the right panel.

Alternative to this navigation, you can directly go to the required MBean by typing in jboss.system:* in the filter criteria of the JMX console.

3. This would show all the server details like memory, chip architecture , ActiveThreadCount , HostAddress etc.

Navigate to the bottom of the page and click on the listThreadDump operation –>  Invoke.

4.  This would generate the thread dumps for analysis as shown below.

Using Twiddle:

1. Open command prompt.

2. Navigate to the $JBOSS_HOME/bin  directory.

NOTE: Make sure the JAVA_HOME is already set.

3. Execute the below command.

twiddle.bat –server jnp://<Host>:<Port> invoke  “jboss.system:type=ServerInfo”     listThreadDump

For ex:

twiddle.bat –server jnp://localhost:1299 invoke  “jboss.system:type=ServerInfo”     listThreadDump

Refer the below post for further understanding o f JBoss Twiddle Utility.

http://weblogic-wonders.com/weblogic/2010/12/22/jboss-command-line-utility-twiddle/

References:

http://community.jboss.org/wiki/Twiddle

Cheers,

Wonders Team. 🙂