-
-
Save joergsebis/712d3c477e67729cf7a1b4836d076f57 to your computer and use it in GitHub Desktop.
Wildfly 10+ Stateless Beans Changed Behaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package counter.remote; | |
import javax.ejb.Remote; | |
@Remote | |
public interface CounterRemote { | |
public int count(); | |
public int increment(); | |
public int reset(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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