View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.ejb.multi.server;
18  
19  import java.util.Date;
20  import java.util.Properties;
21  import java.util.logging.Level;
22  import java.util.logging.Logger;
23  
24  import javax.naming.Context;
25  import javax.naming.InitialContext;
26  
27  import org.jboss.as.quickstarts.ejb.multi.server.app.MainApp;
28  import org.jboss.ejb.client.ContextSelector;
29  import org.jboss.ejb.client.EJBClientConfiguration;
30  import org.jboss.ejb.client.EJBClientContext;
31  import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
32  import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
33  
34  /**
35   * <p>
36   * A simple standalone application which uses the JBoss API to invoke the MainApp demonstration Bean.
37   * </p>
38   * <p>
39   * With the boolean property <i>UseScopedContext</i> the basic example or the example with the scoped-environment will be called.
40   * </p>
41   * 
42   * @author <a href="mailto:wfink@redhat.com">Wolf-Dieter Fink</a>
43   */
44  public class Client {
45  
46      /**
47       * @param args no args needed
48       * @throws Exception 
49       */
50      public static void main(String[] args) throws Exception {
51          // suppress output of client messages
52          Logger.getLogger("org.jboss").setLevel(Level.OFF);
53          Logger.getLogger("org.xnio").setLevel(Level.OFF);
54          
55          Properties p = new Properties();
56          p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
57          p.put("remote.connections", "one");
58          p.put("remote.connection.one.port", "4447");
59          p.put("remote.connection.one.host", "localhost");
60          p.put("remote.connection.one.username", "quickuser");
61          p.put("remote.connection.one.password", "quick-123");
62  
63          EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
64          ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
65          EJBClientContext.setSelector(selector);
66  
67          Properties props = new Properties();
68          props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
69          InitialContext context = new InitialContext(props);
70  
71          final boolean useScopedExample = Boolean.getBoolean("UseScopedContext");
72          final String rcal = "ejb:jboss-ejb-multi-server-app-main/ejb//" + (useScopedExample ? "MainAppSContextBean" : "MainAppBean") + "!" + MainApp.class.getName();
73          final MainApp remote = (MainApp) context.lookup(rcal);
74          final String result = remote.invokeAll("Client call at "+new Date());
75  
76          System.out.println("InvokeAll succeed: "+result);
77      }
78  
79  }