JAVA-12424 Renamed spring-ejb to spring-ejb-modules
This commit is contained in:
+70
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.springejbclient;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
|
||||
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringEjbClientApplication {
|
||||
|
||||
@Bean
|
||||
public Context context() throws NamingException {
|
||||
Properties jndiProps = new Properties();
|
||||
jndiProps.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
|
||||
jndiProps.put("jboss.naming.client.ejb.context", true);
|
||||
jndiProps.put("java.naming.provider.url", "http-remoting://localhost:8080");
|
||||
return new InitialContext(jndiProps);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HelloStatelessWorld helloStatelessWorld(Context context) throws NamingException {
|
||||
return (HelloStatelessWorld) context.lookup(this.getFullName(HelloStatelessWorld.class));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HelloStatefulWorld helloStatefulWorld(Context context) throws NamingException {
|
||||
return (HelloStatefulWorld) context.lookup(this.getFullName(HelloStatefulWorld.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private String getFullName(Class classType) {
|
||||
String moduleName = "spring-ejb-remote/";
|
||||
String beanName = classType.getSimpleName();
|
||||
String viewClassName = classType.getName();
|
||||
|
||||
return moduleName + beanName + "!" + viewClassName;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringEjbClientApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.springejbclient.endpoint;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
|
||||
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
|
||||
|
||||
@RestController
|
||||
public class HomeEndpoint {
|
||||
|
||||
private HelloStatelessWorld helloStatelessWorld;
|
||||
private HelloStatefulWorld helloStatefulWorld;
|
||||
|
||||
public HomeEndpoint(HelloStatelessWorld helloStatelessWorld, HelloStatefulWorld helloStatefulWorld) {
|
||||
this.helloStatelessWorld = helloStatelessWorld;
|
||||
this.helloStatefulWorld = helloStatefulWorld;
|
||||
}
|
||||
|
||||
@GetMapping("/stateless")
|
||||
public String getStateless() {
|
||||
return helloStatelessWorld.getHelloWorld();
|
||||
}
|
||||
|
||||
@GetMapping("/stateful")
|
||||
public String getStateful() {
|
||||
return helloStatefulWorld.getHelloWorld() + " called " + helloStatefulWorld.howManyTimes() + " times";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
server.port=8081
|
||||
|
||||
#logging.level.root=DEBUG
|
||||
@@ -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
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user