Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ibytecode.client;
- import java.util.Properties;
- import javax.naming.Context;
- import javax.naming.NamingException;
- import org.jboss.ejb.client.ContextSelector;
- import org.jboss.ejb.client.EJBClientConfiguration;
- import org.jboss.ejb.client.EJBClientContext;
- import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
- import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
- import com.ibytecode.business.HelloWorld;
- import com.ibytecode.businesslogic.HelloWorldBean;
- import com.ibytecode.clientutility.JNDILookupClass;
- public class EJBAppClientWithoutPropertiesFile {
- public static void main(String[] args) {
- final EJBClientConfiguration clientConfiguration = new PropertiesBasedEJBClientConfiguration(createClientConfigurationProperties());
- final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(clientConfiguration);
- // set the selector for use
- EJBClientContext.setSelector(contextSelector);
- HelloWorld bean = doLookup();
- System.out.println(bean.sayHello()); // 4. Call business logic
- }
- private static Properties createClientConfigurationProperties() {
- final Properties properties = new Properties();
- properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
- properties.put("remote.connections", "default");
- properties.put("remote.connection.default.host", "localhost");
- properties.put("remote.connection.default.port", "4447");
- properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
- // properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS","JBOSS-LOCAL-USER");
- //properties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
- return properties;
- }
- private static HelloWorld doLookup() {
- Context context = null;
- HelloWorld bean = null;
- try {
- // 1. Obtaining Context
- context = JNDILookupClass.getInitialContext();
- // 2. Generate JNDI Lookup name
- String lookupName = getLookupName();
- // 3. Lookup and cast
- bean = (HelloWorld) context.lookup(lookupName);
- } catch (NamingException e) {
- e.printStackTrace();
- }
- return bean;
- }
- private static String getLookupName() {
- /*
- * The app name is the EAR name of the deployed EJB without .ear suffix.
- * Since we haven't deployed the application as a .ear, the app name for
- * us will be an empty string
- */
- String appName = "";
- // The module name is the JAR name of the deployed EJB without the .jar
- // suffix.
- String moduleName = "HelloWorldSessionBean";
- /*
- * AS7 allows each deployment to have an (optional) distinct name. This
- * can be an empty string if distinct name is not specified.
- */
- String distinctName = "";
- // The EJB bean implementation class name
- String beanName = HelloWorldBean.class.getSimpleName();
- // Fully qualified remote interface name
- final String interfaceName = HelloWorld.class.getName();
- // Create a look up string name
- String name = "ejb:" + appName + "/" + moduleName + "/" + distinctName
- + "/" + beanName + "!" + interfaceName;
- return name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement