/**
   * The application two can be called via lookup.
   *
   * <ul>
   *   <li>with the standard naming
   *       <i>ejb:apptwo/ejb//AppTwoBean!org.jboss.as.quickstarts.ejb.multi.server.app.AppTwo</i>
   *   <li><i>java:global/AliasAppTwo</i> the alias provided by the server configuration <b>this is
   *       not recommended</b>
   *   <li><i>java:comp/env/AppTwoAlias</i> the local alias provided by the ejb-jar.xml
   *       configuration
   * </ul>
   *
   * @param text Simple text for logging in the target servers logfile
   * @return A text with server details for demonstration
   */
  private String invokeAppTwo(String lookup, String text) throws NamingException {
    final AppTwo bean = (AppTwo) iCtx.lookup(lookup);

    // invoke on the bean
    final String appTwoResult = bean.invoke(text);

    LOGGER.info("AppTwo return : " + appTwoResult);
    return appTwoResult;
  }
  /**
   * Invoke the App2 with different ejb-client context. The server AppTwoA will be called with the
   * user quickuser1. The server AppTwoB will be called with the user quickuser2. Both invocations
   * are separate, there will no mix between. Also the outbound-connection is not used.
   *
   * @param text Simple text which will be logged at server side.
   * @return simple collection of the returned results
   */
  private String invokeAppTwo(String text) {
    AppTwo beanA = null;
    AppTwo beanB = null;

    final Properties ejbClientContextProps = new Properties();
    ejbClientContextProps.put("endpoint.name", "appMain->appTwoA_endpoint");
    // Property to enable scoped EJB client context which will be tied to
    // the JNDI context
    ejbClientContextProps.put("org.jboss.ejb.client.scoped.context", true);
    // Property which will handle the ejb: namespace during JNDI lookup
    ejbClientContextProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

    final String connectionName = "appTwoConnection";
    ejbClientContextProps.put(
        "remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
    // add the properties to connect the app-one host
    ejbClientContextProps.put("remote.connections", connectionName);
    ejbClientContextProps.put("remote.connection." + connectionName + ".host", "localhost");
    ejbClientContextProps.put("remote.connection." + connectionName + ".port", "4647");
    ejbClientContextProps.put("remote.connection." + connectionName + ".username", "quickuser1");
    ejbClientContextProps.put("remote.connection." + connectionName + ".password", "quick123+");

    Context iCtxA = null;
    try {
      iCtxA = new InitialContext(ejbClientContextProps);
      beanA =
          (AppTwo)
              iCtxA.lookup(
                  "ejb:jboss-ejb-multi-server-app-two/ejb//AppTwoBean!" + AppTwo.class.getName());
    } catch (NamingException e) {
      LOGGER.error("Could not create InitialContext('appTwoA')");
    }

    // change the necessary properties to call the other server
    ejbClientContextProps.put("endpoint.name", "appMain->appTwoB_endpoint");
    ejbClientContextProps.put("remote.connection." + connectionName + ".port", "5247");
    ejbClientContextProps.put("remote.connection." + connectionName + ".username", "quickuser2");
    ejbClientContextProps.put("remote.connection." + connectionName + ".password", "quick+123");
    Context iCtxB = null;
    try {
      iCtxB = new InitialContext(ejbClientContextProps);
      beanB =
          (AppTwo)
              iCtxB.lookup(
                  "ejb:jboss-ejb-multi-server-app-two/ejb//AppTwoBean!" + AppTwo.class.getName());
    } catch (NamingException e) {
      LOGGER.error("Could not create InitialContext('appTwoB')");
    }

    StringBuffer result = new StringBuffer(" appTwo loop(4 time A-B expected){");
    for (int i = 0; i < 4; i++) {
      // invoke on the bean
      String appResult = beanA.invokeSecured(text);
      if (i > 0) {
        result.append(", ");
      }
      result.append(appResult);
      appResult = beanB.invokeSecured(text);
      result.append(", ");
      result.append(appResult);
    }
    result.append("}");

    LOGGER.info("AppTwo (loop) returns : " + result);

    // should be closed and null the reference to close the connection
    saveContextClose(iCtxA);
    iCtxA = null;
    saveContextClose(iCtxB);
    iCtxB = null;

    return result.toString();
  }
Example #3
0
 public void callEJBAppTwoRemote() {
   LOOGER.info(
       "Try to invoke the remote AppTwo to log the given text and get the invocation results. Proxy="
           + twoApp);
   this.invocation.setResult(twoApp.invoke(this.invocation.getText()));
 }