Here's something to get started.
Firstly, yes you can create new users via JMX.
For performing the same operations that the james cli offers you'll find
everything you need in james-server-cli-3.0-beta4.jar. Particular class
of interest is org.apache.james.cli.probe.impl.JmxServerProbe
To find this out take a look at the source of the james cli shell
script, it refers to the class org.apache.james.cli.ServerCmd
Depending on your remote connection, as JMX uses two ports, a registry
and server port you may want to lock down what those two ports are as
opposed to let server port be dynamically chosen... this can be a bit of
a hassle when working through firewalls.
One way to lock down the server port in james, change
conf/META-INF/org/apache/james/spring-server.xml
Out of the box JMX configuration in apache james 3.0-beta4
<!--
JMX Server
-->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="location" value="classpath:jmx.properties"/>
</bean>
<bean id="mbeanserver"
class="org.springframework.jmx.support.MBeanServerFactoryBean" >
<property name="locateExistingServerIfPossible" value="true"/>
<property name="registerWithFactory" value="true"/>
</bean>
<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFactoryBean"
depends-on="registry">
<property name="objectName" value="connector:name=rmi" />
*<property name="serviceUrl"
value="service:jmx:rmi://${jmx.address}/jndi/rmi://${jmx.address}:${jmx.port}/jmxrmi"
/>*
</bean>
<bean id="registry"
class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
*<property name="port" value="${jmx.port}" />*
<property name="serverSocketFactory"
ref="restrictedRmiSocketFactory"/>
<property name="clientSocketFactory"
ref="restrictedRmiSocketFactory"/>
</bean>
<bean id="restrictedRmiSocketFactory"
class="org.apache.james.util.RestrictingRMISocketFactory">
<constructor-arg value="${jmx.address}"/>
</bean>
Change the bold lines to the following.
<property name="serviceUrl"
value="service:jmx:rmi://${jmx.address}:${jmx.server.port}/jndi/rmi://${jmx.address}:${jmx.registry.port}/jmxrmi"
/>
<property name="port" value="${jmx.registry.port}" />
And in jmx.properties, change
jmx.address=
jmx.port=
To
jmx.address=
jmx.registry.port=
jmx.server.port=
Hope this helps
Thanks
Phillip
On 7/18/13 3:46 AM, Riley Scott wrote:
Hi,
We have a James 3 server running in our test lab. I need to add users remotely.
I need to create a Java app that will remotely connect to the James 3 server
and add users via JMX. Is this possible with JMX? If so, can you point me to
code samples / docs? Thanks.