An EJB remote client with JBoss 7 can be connected with the following three different approaches.
- jboss-ejb-client.properties.
- Setting property file through system property jboss.ejb.client.properties.file.path
- programmatically
The first two approaches can be found on the jboss documentation (https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI) and in the jboss quickstarts. The problems with those are:
- static nature
- useless in case of client specific security (username, password)
The solution for the last approach was very hard to find and time consuming. So here is my solution to make it work with a JBoss specific JBossClientContextBuilder. (Note: Do not forget the jboss-client.jar in your classpath).
IHelloBean.java
public interface IHelloBean {
String getHello();
}
HelloBean.java
@Stateless
@Remote(IHelloBean.class)
public class HelloBean implements IHelloBean
{
@Override
public String getHello()
{
return "Hello";
}
}
HelloClient.java
public class HelloClient
{
public static void main(String[] args) throws NamingException
{
final Context context = new JBossClientContextBuilder().build();
String lookupString = "ejb:/sectest/HelloBean!test.IHelloBean";
final IHelloBean helloBean = (IHelloBean) context.lookup(lookupString);
System.out.println("Hello: " + helloBean.getHello());
}
}
JBossClientContextBuilder.java
public class JBossClientContextBuilder {
private String port;
private String host;
private String user;
private String password;
private boolean noanonymous;
public JBossClientContextBuilder port(String port) {
this.port = port;
return this;
}
public JBossClientContextBuilder host(String host) {
this.host = host;
return this;
}
public JBossClientContextBuilder user(String user) {
this.user = user;
return this;
}
public JBossClientContextBuilder password(String password) {
this.password = password;
return this;
}
public JBossClientContextBuilder noanonymous(boolean noanonymous) {
this.noanonymous = noanonymous;
return this;
}
public Context build() throws NamingException {
Properties clientProp = new Properties();
clientProp
.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED",
"false");
clientProp.put("remote.connections", "default");
// Default 4447
clientProp.put("remote.connection.default.port", StringUtils.defaultIfEmpty(port, "4447"));
// Default 127.0.0.1
clientProp.put("remote.connection.default.host",
StringUtils.defaultIfEmpty(host, "127.0.0.1"));
if (!StringUtils.isEmpty(user)) {
clientProp.put("remote.connection.default.username", user);
}
if (!StringUtils.isEmpty(password)) {
clientProp.put("remote.connection.default.password", password);
}
if (noanonymous) {
clientProp
.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS",
"true");
clientProp
.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS",
"JBOSS-LOCAL-USER");
}
clientProp
.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT",
"false");
System.out.println(Arrays.deepToString(clientProp.entrySet().toArray(
new Map.Entry[0])));
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(
clientProp);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(
cc);
EJBClientContext.setSelector(selector);
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
return new InitialContext(props);
}
}
Dieser Kommentar wurde vom Autor entfernt.
AntwortenLöschenI really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in JBOSS, kindly contact us http://www.maxmunus.com/contact
AntwortenLöschenMaxMunus Offer World Class Virtual Instructor-led training on JBOSS. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
saurabh
MaxMunus
E-mail: saurabh@maxmunus.com
Skype id: saurabhmaxmunus
Ph:(0) 8553576305
http://www.maxmunus.com/
I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
AntwortenLöschenI know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
AntwortenLöschenpython Training in Chennai
python Training in Bangalore
python Training in Pune
Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
AntwortenLöschenpython training in bangalore
A good first place to search educational web template - TemplateMonster. You can find there free templates.
AntwortenLöschensuch a great word which you use in your article and article is amazing knowledge. thank you for sharing it.
AntwortenLöschenLooking for Software Training in Bangalore , learn from Softgen Infotech Software Courses on online training and classroom training. Join today!
I really like looking through an blog article that can make people think. Also, many thanks for allowing for me to comment!
AntwortenLöschenI love more useful this article. Thank you so much.
AntwortenLöschenPython Training in Chennai
Python Training in Bangalore
Python Training in Hyderabad
Python Training in Coimbatore
Python Training
python online training
python flask training
python flask online training
Very informative post.Check this Ethical Hacking
AntwortenLöschenThis post is so interactive and informative.keep update more information...
AntwortenLöschenSalesforce Training in Tambaram
Salesforce Training in Chennai
Perde Modelleri
AntwortenLöschenMOBİL ONAY
Türk Telekom Mobil Ödeme Bozdurma
nft nasıl alınır
Ankara evden eve nakliyat
Trafik sigortası
dedektor
Site Kurma
AŞK ROMANLARI