Failed to connect to any server.
peter_jaxy Oct 7, 2015 10:26 AMI can't get remote access from my client to the server application.
My EjbRemoteClient.java:
package com.illucit.ejbremote;
import static javax.naming.Context.INITIAL_CONTEXT_FACTORY;
import static javax.naming.Context.PROVIDER_URL;
import static javax.naming.Context.URL_PKG_PREFIXES;
import java.util.Hashtable;
import java.util.Map;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.illucit.ejbremote.server.ExampleService;
import java.util.Properties;
/**
* Remote EJB Client.
*
*/
public class EjbRemoteClient {
/**
* Run example.
*
* @param args
* (not used)
*/
public static void main(String[] args) {
Context remotingContext;
try {
//Set jndi properties
Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL,"http-remoting://10.7.97.48:8080");
// username
jndiProperties.put(Context.SECURITY_PRINCIPAL, "ejbappuser");
// password
jndiProperties.put(Context.SECURITY_CREDENTIALS, "e3q5o-tbp");
// This is an important property to set if you want to do EJB invocations via the remote-naming project
jndiProperties.put("jboss.naming.client.ejb.context", true);
// create a context passing these properties
remotingContext = new InitialContext(jndiProperties);
} catch (NamingException e) {
System.err.println("Error setting up remoting context");
System.out.println(e.getMessage());
return;
}
// Syntax: ejb:${appName}/${moduleName}/${beanName}!${remoteView}
// appName = name of EAR deployment (or empty for single EJB/WAR
// deployments)
// moduleName = name of EJB/WAR deployment
// beanName = name of the EJB (Simple name of EJB class)
// remoteView = fully qualified remote interface class
String ejbUrl = "/ExampleService/ExampleService-ejb/ExampleServiceImpl!com.illucit.ejbremote.server.ExampleService";
ExampleService service;
try {
service = (ExampleService)remotingContext.lookup(ejbUrl);
} catch (NamingException e) {
System.err.println("Error resolving bean");
System.out.println(e.getMessage());
return;
} catch (ClassCastException e) {
System.err.println("Resolved EJB is of wrong type");
System.out.println(e.getMessage());
return;
}
// Call remote method with parameter
String toGreet = "World";
String exampleResult;
try {
exampleResult = service.greet(toGreet);
} catch (Exception e) {
System.err.println("Error accessing remote bean");
System.out.println(e.getMessage());
return;
}
// Hello World!
System.out.println("Example result: " + exampleResult);
// Retrieve result from EJB call
Map<Object, Object> systemProperties;
try {
systemProperties = service.getSystemProperties();
} catch (Exception e) {
System.err.println("Error accessing remote bean");
return;
}
System.out.println("Wildfly Home Dir: " + systemProperties.get("jboss.home.dir"));
}
}
I get the following error message:
Failed to connect to any server. Servers tried: [http-remoting://10.7.97.48:8080 (java.net.ConnectException: Connection refused: no further information)]
But I can connect to the wildfly server. If I type 10.7.97.48:8080 in my webbrowser, it appears the welcome page.
How can I find out, what It's wrong?