BAEL-8874 Merge ejb projects
-Merged ejb and spring-ejb modules into spring-ejb
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.baeldung.ejb.client;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import com.baeldung.ejb.tutorial.HelloWorld;
|
||||
|
||||
public class EJBClient {
|
||||
|
||||
public EJBClient() {
|
||||
}
|
||||
|
||||
private Context context = null;
|
||||
|
||||
public String getEJBRemoteMessage() {
|
||||
EJBClient main = new EJBClient();
|
||||
try {
|
||||
// 1. Obtaining Context
|
||||
main.createInitialContext();
|
||||
// 2. Generate JNDI Lookup name and caste
|
||||
HelloWorld helloWorld = main.lookup();
|
||||
return helloWorld.getHelloWorld();
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
} finally {
|
||||
try {
|
||||
main.closeContext();
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HelloWorld lookup() throws NamingException {
|
||||
|
||||
// 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
|
||||
final String appName = "";
|
||||
final String moduleName = "spring-ejb-remote";
|
||||
final String distinctName = "";
|
||||
final String beanName = "HelloWorld";
|
||||
final String viewClassName = HelloWorld.class.getName();
|
||||
final String toLookup = String.format("ejb:%s/%s/%s/%s!%s", appName, moduleName, distinctName, beanName, viewClassName);
|
||||
return (HelloWorld) context.lookup(toLookup);
|
||||
}
|
||||
|
||||
public void createInitialContext() throws NamingException {
|
||||
Properties prop = new Properties();
|
||||
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
||||
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
|
||||
prop.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
|
||||
prop.put(Context.SECURITY_PRINCIPAL, "testUser");
|
||||
prop.put(Context.SECURITY_CREDENTIALS, "admin1234!");
|
||||
prop.put("jboss.naming.client.ejb.context", false);
|
||||
|
||||
context = new InitialContext(prop);
|
||||
}
|
||||
|
||||
public void closeContext() throws NamingException {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.ejb.wildfly;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TextApplication {
|
||||
|
||||
public static void main(String[] args) throws NamingException {
|
||||
TextProcessorRemote textProcessor = EJBFactory.createTextProcessorBeanFromJNDI("ejb:");
|
||||
System.out.print(textProcessor.processText("sample text"));
|
||||
}
|
||||
|
||||
private static class EJBFactory {
|
||||
|
||||
private static TextProcessorRemote createTextProcessorBeanFromJNDI(String namespace) throws NamingException {
|
||||
return lookupTextProcessorBean(namespace);
|
||||
}
|
||||
|
||||
private static TextProcessorRemote lookupTextProcessorBean(String namespace) throws NamingException {
|
||||
Context ctx = createInitialContext();
|
||||
final String appName = "";
|
||||
final String moduleName = "spring-ejb-remote";
|
||||
final String distinctName = "";
|
||||
final String beanName = TextProcessorBean.class.getSimpleName();
|
||||
final String viewClassName = TextProcessorRemote.class.getName();
|
||||
return (TextProcessorRemote) ctx.lookup(namespace + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
|
||||
}
|
||||
|
||||
private static Context createInitialContext() throws NamingException {
|
||||
Properties jndiProperties = new Properties();
|
||||
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
|
||||
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
||||
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||
jndiProperties.put("jboss.naming.client.ejb.context", true);
|
||||
return new InitialContext(jndiProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class SpringEjbClientApplication {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private String getFullName(Class classType) {
|
||||
String moduleName = "ejb-remote-for-spring/";
|
||||
String moduleName = "spring-ejb-remote/";
|
||||
String beanName = classType.getSimpleName();
|
||||
String viewClassName = classType.getName();
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
endpoint.name=client-endpoint
|
||||
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
|
||||
remote.connections=default
|
||||
remote.connection.default.host=127.0.0.1
|
||||
remote.connection.default.port=8080
|
||||
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
|
||||
remote.connection.default.username=myusername
|
||||
remote.connection.default.password=mypassword
|
||||
Reference in New Issue
Block a user