title: Migration to Wildfly 21 from JBoss AS7.2
body: <p>We are currently migrating our JBoss App-Server to Wildfly V21. We used this code to create an initial context to a cluster that uses our own LoadBalancer.</p>
  <p><strong>Old JBoss Code:</strong></p>
  <pre><code>        Properties env = new Properties();
          env.put(&quot;remote.clusters&quot;, &quot;ejb&quot;);
          env.put(&quot;remote.cluster.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS&quot;, &quot;false&quot;);
          env.put(&quot;remote.cluster.ejb.connect.options.org.xnio.Options.SSL_ENABLED&quot;, &quot;false&quot;);
          env.put(&quot;jboss.naming.client.ejb.context&quot;, &quot;true&quot;);
          env.put(&quot;remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED&quot;, &quot;false&quot;);
          env.put(&quot;deployment.node.selector&quot;, &quot;our.packege.to.own.RandomServerSelector&quot;);
  
          StringBuilder connections = new StringBuilder();
          int counter = 0;
          for (String hostAndPort : hostAndPortList) {
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.username&quot;, user);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.password&quot;, pwd);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.host&quot;, hostAndPort.split(&quot;:&quot;)[0]);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.port&quot;, hostAndPort.split(&quot;:&quot;)[1]);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS&quot;, &quot;false&quot;);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS&quot;,
                  &quot;JBOSS-LOCAL-USER&quot;);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT&quot;, &quot;false&quot;);
              env.put(&quot;remote.connection.s&quot; + counter + &quot;.connect.timeout&quot;, &quot;2000&quot;);
  
              // see https://community.jboss.org/thread/205784?start=15&amp;tstart=180 /
              // https://issues.jboss.org/browse/EJBCLIENT-52
              env.put(&quot;remote.connection.s&quot; + counter + &quot;connect.options.org.jboss.remoting3.RemotingOptions.HEARTBEAT_INTERVAL&quot;,
                  &quot;300000&quot;);
  
              // fill connections list
              if (connections.length() &gt; 0) {
                  connections.append(&quot;,&quot;);
              }
              connections.append(&quot;s&quot; + counter);
  
              // prepare for next server
              counter++;
          }
  
          // connections-list
          env.put(&quot;remote.connections&quot;, connections.toString());
  
          EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(env);
          ContextSelector&lt;EJBClientContext&gt; selector = new ConfigBasedEJBClientContextSelector(cc);
          EJBClientContext.setSelector(selector);
  
          // create the initial context
          Properties p = new Properties();
          p.put(Context.URL_PKG_PREFIXES, &quot;org.jboss.ejb.client.naming&quot;); 
          _initialContext = new InitialContext(p);
  </code></pre>
  <p>For Wildfly 21 this do not works anymore so i spent a lot of time to find a way that works. Now i found the right implmentation for the legacy behavior. My Question is how must be the call implemented with remote+http (Context.PROVIDER_URL)</p>
  <p><strong>Current Code that works in legacy mode:</strong></p>
  <pre><code>        Properties env = new Properties();
          env.put(&quot;remote.clusters&quot;, &quot;ejb&quot;);
          env.put(&quot;remote.cluster.ejb.username&quot;, user);
          env.put(&quot;remote.cluster.ejb.password&quot;, pwd);
  
          env.put(&quot;remote.cluster.ejb.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS&quot;, &quot;false&quot;);
          env.put(&quot;remote.cluster.ejb.connect.options.org.xnio.Options.SSL_ENABLED&quot;, &quot;false&quot;);
  
          env.put(&quot;deployment.node.selector&quot;, &quot;path.to.our.RandomServerSelector&quot;);
  
          env.put(&quot;remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED&quot;, &quot;false&quot;);
  
          StringBuilder connections = new StringBuilder();
  
          int sCount = 0;
          for (String host : hostsAndPorts) {
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.username&quot;, user);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.password&quot;, pwd);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.host&quot;, host.split(&quot;:&quot;)[0]);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.port&quot;, host.split(&quot;:&quot;)[1]);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS&quot;,
                  &quot;false&quot;);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS&quot;,
                  &quot;JBOSS-LOCAL-USER&quot;);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT&quot;,
                  &quot;false&quot;);
              env.put(&quot;remote.connection.s&quot; + sCount + &quot;.connect.timeout&quot;, &quot;2000&quot;);
              // fill connections list
              if (connections.length() &gt; 0) {
                  connections.append(&quot;,&quot;);
              }
              connections.append(&quot;s&quot; + sCount);
              // prepare for next server
              sCount++;
          }
  
          // connections-list
          env.put(&quot;remote.connections&quot;, connections.toString());
          env.put(&quot;jboss.naming.client.ejb.context&quot;, true);
          
          
          JBossEJBProperties ejbProperties = JBossEJBProperties.fromProperties(&quot;ejb-client.properties&quot;, env);
          JBossEJBProperties.getContextManager().setGlobalDefault(ejbProperties);
  
          env = new Properties();
          env.put(Context.URL_PKG_PREFIXES, &quot;org.jboss.ejb.client.naming&quot;);
          return new InitialContext(env);
  </code></pre>