WildFly 10远程EJB查找遇java.io.IOException: Connection reset by peer问题求助
Hey there, let's work through this connection reset error you're facing when trying to do a remote EJB lookup on WildFly 10. I've debugged similar issues a few times, so here are actionable steps to diagnose and fix the problem:
1. Complete Your Connection Configuration
Your code cuts off at the remote.connectionprovider.create.options.org.xnio... line, and this section is critical for establishing a valid connection to the server. Here's what you need to add to make the configuration complete:
private static Object lookup() throws Exception { Properties properties = new Properties(); properties.put("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming"); // Switch this to true to enable a dedicated EJB naming context (often fixes context initialization issues) properties.put("jboss.naming.client.ejb.context", "true"); properties.put("org.jboss.ejb.client.scoped.context", "true"); properties.put("endpoint.name", "client-endpoint"); // XNIO connection provider settings properties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false"); // Define your remote connection alias properties.put("remote.connections", "default"); // Replace with your WildFly server's actual IP/hostname properties.put("remote.connection.default.host", "your-server-ip"); // Use 8080 for HTTP remoting or 4447 for native remoting (check your server config) properties.put("remote.connection.default.port", "8080"); // Uncomment if your server requires authentication // properties.put("remote.connection.default.username", "ejb-user"); // properties.put("remote.connection.default.password", "ejb-password"); InitialContext context = new InitialContext(properties); // Replace with your EJB's actual JNDI name (check server logs for the correct binding) return context.lookup("java:global/your-app-name/your-ejb-class!com.your.package.YourRemoteInterface"); }
2. Verify WildFly Server Configuration
- Check Remote Connectors: Open your WildFly's
standalone.xml(ordomain.xmlfor domain mode) and ensure the remoting subsystem has a valid connector. Look for this section:
This enables HTTP-based remoting on port 8080 (matching the client config above). If you prefer native remoting, use a<subsystem xmlns="urn:jboss:domain:remoting:3.0"> <endpoint worker="default"/> <http-connector name="http-remoting-connector" connector-ref="default" security-realm="ApplicationRealm"/> </subsystem>remoting-connectoron port 4447. - Confirm EJB Deployment: Check the WildFly server logs for lines like
JNDI bindings for session bean named YourBean in deployment unit deployment "your-app.war". This will give you the exact JNDI name to use in your lookup code.
3. Rule Out Network/Firewall Issues
- Test Connectivity: Use
telnet your-server-ip 8080(or your configured port) from the client machine. If the connection fails, your firewall or network security group is blocking traffic to that port. Open the port on both the server's firewall and any intermediate networks. - Check Server Binding: Ensure WildFly isn't only bound to
localhost. Instandalone.xml, verify thedefaultsocket binding uses a public IP or0.0.0.0instead of127.0.0.1:<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}"> <socket-binding name="http" port="${jboss.http.port:8080}"/> <!-- Other bindings --> </socket-binding-group>
4. Validate Client Dependencies
Make sure your client project has the correct WildFly EJB client dependencies (no outdated JBoss AS jars!). For Maven, add this to your pom.xml:
<dependencyManagement> <dependencies> <dependency> <groupId>org.wildfly</groupId> <artifactId>wildfly-ejb-client-bom</artifactId> <version>10.1.0.Final</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.ejb-client</groupId> <artifactId>jboss-ejb-client</artifactId> </dependency> </dependencies>
5. Check for Additional Server-Side Errors
If the above steps don't fix it, look at the WildFly server logs (in standalone/log/server.log) for any errors when the client tries to connect. Common issues include:
- Invalid authentication credentials (if security is enabled)
- Missing EJB remote interface annotations
- Deployment failures of your EJB module
内容的提问来源于stack exchange,提问作者subbu royal

