Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joergsebis
Created August 31, 2017 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joergsebis/712d3c477e67729cf7a1b4836d076f57 to your computer and use it in GitHub Desktop.
Save joergsebis/712d3c477e67729cf7a1b4836d076f57 to your computer and use it in GitHub Desktop.
Wildfly 10+ Stateless Beans Changed Behaviour
package client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import counter.remote.CounterRemote;
public class Client {
public static void main(String[] args) {
try {
// Verbindungseinstellungen fuer den Wildfly AS
String JBOSS_CONTEXT="org.jboss.naming.remote.client.InitialContextFactory";
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
props.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
props.put(Context.SECURITY_PRINCIPAL, "sebauser");
props.put(Context.SECURITY_CREDENTIALS, "sebapass");
props.put("jboss.naming.client.ejb.context", true);
// Initial Context fuer Remote-Namensaufloesung
Context context = new InitialContext(props);
// Server-Objekt erstellen
//Lookup pattern: <app-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>
CounterRemote counterA = (CounterRemote)context.
lookup("StatefulExample/CounterBean!counter.remote.CounterRemote");
System.out.println(counterA.count());
counterA.increment();
counterA.increment();
counterA.increment();
counterA.increment();
System.out.println(counterA.count());
CounterRemote counterB = (CounterRemote)context.
lookup("StatefulExample/CounterBean!counter.remote.CounterRemote");
System.out.println(counterB.count());
counterB.increment();
counterB.increment();
counterA.increment();
counterA.increment();
System.out.println(counterA.count());
System.out.println(counterB.count());
// Aufraeumen
context.close();
} catch (NamingException e) {
System.out.println(e);
}
}
}
package counter;
import javax.ejb.Stateless;
import counter.remote.CounterRemote;
@Stateless
public class CounterBean implements CounterRemote {
private int count;
@Override
public int count() {
return count;
}
@Override
public int increment() {
return ++count;
}
@Override
public int reset() {
return (count = 0);
}
}
package counter.remote;
import javax.ejb.Remote;
@Remote
public interface CounterRemote {
public int count();
public int increment();
public int reset();
}
Wildfly 9 Stateless Bean:
0
0
0
0
0
Wildfly 10+11 Stateless Bean:
0
4
4
8
8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment