You are on page 1of 10

PU – JB7 RMI

1
1. Configuration

1.1 Jboss configuration

PU server (standalone.xml or standalone-full.xml)

Add a security realm if none allready exists (“EJBRealm” in our example).

Change the default “remoting-connector” from:

2
to:

Check the default remote port value (this value + jb port offset = rmi port)

Ensure that the server startup script gives an unique node name for this instance (need if the pu server and the client
server are on the same machine.

Example startup script for “std-tst” instance:

3
Client server (standalone.xml or standalone-full.xml)

Add a security realm for the comunication with the PU server (“PUEjbSecurityRealm” in our example), this is required to
create the comunication bean.

We can see that a default encoded (base64) password is required.

Change the default “remoting-connector” from:

to:

4
We can see that we need also a default username (in our case “andrea”) for the comunication bean. This and the
password are used for the first time to check and settup the communication bean.

Check the default remote port value:

And update it setting the port (to: pu offser +remotr port = 4547):

5
1.2 PU - Project deploy process

Ant tasks: deploy-all, pu-rmi-jar.

deploy-all

Create and deploy “profilazioniUtente.ear”.

pu-rmi-jar

Create pu rmi jar (“pu-rmi.jar” - the only pu dependency needed for RMI).

6
1.3 Client project configuration

Classpath dependencies
<!-- RMI -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/ejb-client/main/jboss-ejb-client-1.0.5.Final.jar"/> <!-- handles all
client utilities -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/logging/main/jboss-logging-3.1.0.GA.jar" /> <!-- logs activities -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/logmanager/main/jboss-logmanager-1.2.2.GA.jar" />
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/apache/log4j/main/log4j-1.2.16.jar" />
<classpathentry kind="var" path="JBOSS7_HOME/modules/javax/ejb/api/main/jboss-ejb-api_3.1_spec-1.0.1.Final.jar"/>
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/marshalling/main/jboss-marshalling-1.3.11.GA.jar" /> <!-- makes soap
packets, xml dom trees -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/remoting3/main/jboss-remoting-3.2.3.GA.jar" /> <!-- open/close sockets
-->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/xnio/main/xnio-api-3.0.3.GA.jar"/> <!-- modifies socket I/O -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/sasl/main/jboss-sasl-1.0.0.Final.jar" /> <!-- username/password
challenge/response -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/javax/transaction/api/main/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/> <!--
moves transaction states -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/xnio/nio/main/xnio-nio-3.0.3.GA.jar" /> <!-- implementation of modifying
socket I/O -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/marshalling/river/main/jboss-marshalling-river-1.3.11.GA.jar" /> <!--
"river" implementation of making soap packets, xml dom trees -->
<classpathentry kind="var" path="JBOSS7_HOME/modules/org/jboss/remote-naming/main/jboss-remote-naming-1.0.2.Final.jar"/>

<!-- PU -->
<classpathentry kind="lib" path="server/lib/ditech/pu/pu-rmi.jar"/>

Helper methods

Method for context lookup:


private Context getLookupContext(String username, String password) {

String profileRmiHost = ConfigClientManager.getInstance().getConfigParamValue(CommConstants.CLIENT_MODULE_MORE,


CommConstants.CLIENT_MODULE_PARAMETRI, CommConstants.PARAM_PROFILE_RMI_HOST);

if (StringUtils.isEmpty(profileRmiHost)) {
throw new RuntimeException("Missing value for configuration param:" + CommConstants.PARAM_PROFILE_RMI_HOST
+ "!");
}

7
String profileRmiPort = ConfigClientManager.getInstance().getConfigParamValue(CommConstants.CLIENT_MODULE_MORE,
CommConstants.CLIENT_MODULE_PARAMETRI, CommConstants.PARAM_PROFILE_RMI_PORT);

if (StringUtils.isEmpty(profileRmiPort)) {
throw new RuntimeException("Missing value for configuration param:" + CommConstants.PARAM_PROFILE_RMI_PORT
+ "!");
}

final Properties jndiProperties = new Properties();


/*setup the ejb: namespace URL factory*/
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put("jboss.naming.client.ejb.context", "true");

/* Add the properties to connect the pu host */


final String connectionName = "pu-connection";
jndiProperties.put("remote.connections", connectionName);
jndiProperties.put("remote.connection." + connectionName + ".host", profileRmiHost);
jndiProperties.put("remote.connection." + connectionName + ".port", profileRmiPort);
jndiProperties.put("remote.connection." + connectionName + ".username", username);
jndiProperties.put("remote.connection." + connectionName + ".password", password);

try {
final Context context = new InitialContext(jndiProperties);
return context;
} catch (NamingException e) {
e.printStackTrace();
throw new CommRuntimeException(CommExceptionCodeConstants.PROFILAZIONE_UTENTE_NON_RAGGIUNGIBILE);
}
}

private Context getLookupContext(UtenteDTO utente) {

if (utente == null) {
throw new MissingArgumentException("utente is missing");
}

return getLookupContext(utente.getUserName(), utente.getPassword());


}

Method for closing the context:

private void closeLookupContext(final Context context) {


if (context != null) {
try {
logger.info("close Context " + context.getEnvironment().get("endpoint.name"));
context.close();
} catch (NamingException e) {

8
logger.error("InitialContext can not be closed", e);
}
}
}

Method for facade retrieval:

/**
* Looks up and returns the proxy to remote stateless pu bean
*
* @return
* @throws NamingException
*/
private ProfilazioniUtenteFacadeRemote lookupPUFacadeRemote(final Context context) {

try {
/*
* The app name is the application name of the deployed EJBs. This
* is typically the ear name without the .ear suffix. However, the
* application name could be overridden in the application.xml of
* the EJB deployment on the server.
*/
final String appName = "profilazioniUtente";
/*
* This is the module name of the deployed EJBs on the server. This
* is typically the jar name of the EJB deployment, without the .jar
* suffix, but can be overridden via the ejb-jar.xml
*/
final String moduleName = "profilazioniUtenteEJB";
/*
* AS7 allows each deployment to have an (optional) distinct name.
* We haven't specified a distinct name for our EJB deployment, so
* this is an empty string
*/
final String distinctName = "";
/*
* The EJB name which by default is the simple class name of the
* bean implementation class
*/
final String beanName = "ProfilazioniUtenteFacadeEndpointService";
/* The remote view fully qualified class name */
final String viewClassName = ProfilazioniUtenteFacadeRemote.class.getName();
/* Do the lookup */
return (ProfilazioniUtenteFacadeRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/"
+ distinctName + "/" + beanName + "!" + viewClassName);
} catch (NamingException e) {
e.printStackTrace();

9
throw new CommRuntimeException(CommExceptionCodeConstants.PROFILAZIONE_UTENTE_NON_RAGGIUNGIBILE);
}
}

PU rmi method call example:

public UserProfileDTO getUserProfile(UtenteDTO utente) throws RemoteException, ProfilazioniUtenteException {


Context context = getLookupContext(utente);
try {
ProfilazioniUtenteFacadeRemote puFacade = lookupPUFacadeRemote(context);
return puFacade.getUserProfile();
} finally {
closeLookupContext(context);
}
}

10

You might also like