我配置了我的JBoss AS7.1.1(standalone.xml)以接受遠程處理,但4447端口未打開。 我standalone.xml:JBoss AS7.1.1遠程處理
<subsystem xmlns="urn:jboss:domain:remoting:1.1">
<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
</subsystem>
<interfaces>
<interface name="mine">
<any-ipv4-address/>
</interface>
</interfaces>
<socket-binding-group name="standard-sockets" default-interface="mine" port-offset="${jboss.socket.binding.port-offset:0}">
<socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
<socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
<socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
<socket-binding name="ajp" port="8009"/>
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="messaging" port="5445"/>
<socket-binding name="messaging-throughput" port="5455"/>
<socket-binding name="osgi-http" interface="management" port="8090"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
<outbound-socket-binding name="mail-smtp">
<remote-destination host="localhost" port="25"/>
</outbound-socket-binding>
</socket-binding-group>
客戶端程序:
public class Homework4EJB3Client {
/**
* Looks up and returns the proxy to remote stateless calculator bean
*
* @return
* @throws NamingException
*/
private static IMailService lookupRemoteStatelessMessaging() throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put("jboss.naming.client.ejb.context", true);
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
// The app name is the application name of the deployed EJBs. This is typically the ear name
// without the .ear suffix. However, the application name could be overridden in the application.xml of the
// EJB deployment on the server.
// Since we haven't deployed the application as a .ear, the app name for us will be an empty string
final String appName = "";
// This is the module name of the deployed EJBs on the server. This is typically the jar name of the
// EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
// In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
// jboss-as-ejb-remote-app
final String moduleName = "Homework4Quartz";
// AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
// our EJB deployment, so this is an empty string
final String distinctName = "";
// The EJB name which by default is the simple class name of the bean implementation class
final String beanName = "MailService";
// the remote view fully qualified class name
final String viewClassName = "hu.infokristaly.homework.quartz.middle.service.IMailService";
// let's do the lookup
return (IMailService) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}
private static IMailService getIMailService() {
Properties clientProp = new Properties();
clientProp.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
clientProp.put("remote.connections", "default");
clientProp.put("remote.connection.default.port", "4447");
clientProp.put("remote.connection.default.host", "192.168.1.25");
clientProp.put("remote.connection.default.username", "quickstartUser");
clientProp.put("remote.connection.default.password", "quickstartPassword");
clientProp.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(clientProp);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);
final String appName = "";
final String moduleName = "Homework4Quartz";
final String distinctName = "";
final String beanName = "MailService";
final String viewClassName = "hu.infokristaly.homework.quartz.middle.service.IMailService";
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
IMailService result = null;
try {
Context ctx = new InitialContext(props);
result = (IMailService) ctx.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
try {
Object o = lookupRemoteStatelessMessaging();
//Object o = getIMailService();
if (o instanceof IMailService) {
String result = ((IMailService)o).getMail();
System.out.println(result);
((IMailService)o).sendMail();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我用jboss-ejb-client.properties:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=192.168.1.25
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=quickstartUser
remote.connection.default.password=quickstartPassword
在服務器端的Java代碼:
@Named
@Stateless
@Remote(IMailService.class)
public class MailService implements IMailService {
@Inject
private EntityManager em;
@Override
public void sendMail() {
System.out.println("EntityManager:"+em);
System.out.println("Mail sent");
}
@Override
public String getMail() {
return new String("Mail sent");
}
}
客戶端使用jboss-client.jar和服務器導出java:jboss/exported/Homework4Quartz/MailService!hu.infokristaly.homework.quartz.middle.service.IMailService接口。
所以,everithing是好的,如果我使用localhost作爲remote.connection.default.host,但未能如果我使用遠程IP
WARN: Could not register a EJB receiver for connection to remote://192.168.1.25:4447
java.lang.RuntimeException: Operation failed with status WAITING
at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:93)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)
at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:77)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:120)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at com.sun.proxy.$Proxy0.getMail(Unknown Source)
at hu.infokristaly.homework.ejb3client.Homework4EJB3Client.main(Homework4EJB3Client.java:100)
java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:Homework4Quartz,distinctname:] combination for invocation context [email protected]
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at com.sun.proxy.$Proxy0.getMail(Unknown Source)
at hu.infokristaly.homework.ejb3client.Homework4EJB3Client.main(Homework4EJB3Client.java:100)
而且我用的附加用戶(application-users.properties, quickstartUser,quickstartPassword,guest)。 如何在不同的機器上運行客戶端和服務器?