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.appclient.acc.client; 18 19 import java.util.Arrays; 20 21 import javax.ejb.EJB; 22 23 import org.jboss.as.quickstarts.appclient.acc.client.interceptor.ClientInterceptor; 24 import org.jboss.as.quickstarts.appclient.server.ejb.StatelessSession; 25 import org.jboss.ejb.client.EJBClientContext; 26 import org.jboss.logging.Logger; 27 28 /** 29 * A simple EJB client to demonstrate the use of the JBoss application container 30 * to show that the injection will work for server EJB-beans. 31 * 32 * @author <a href="mailto:wfink@redhat.com">Wolf-Dieter Fink</a> 33 */ 34 public class Main { 35 private static final Logger LOG = Logger.getLogger(Main.class); 36 37 /** 38 * Use field injection for the EJB reference.<br/> 39 * <b>Notice that the application-container injection only works for 40 * static fields within the main class of the application</b><br/> 41 * See JSR316 (EE6 platform spec) chapter 5.2.5 . 42 */ 43 @EJB 44 private static StatelessSession slsb; 45 46 /** no instance necessary */ 47 private Main() { 48 } 49 50 /** 51 * @param args the command line arguments 52 */ 53 public static void main(String args[]) { 54 // Show that the client is started with arguments at command line 55 LOG.info("Main started " + ( args.length != 0 ? "with" : "without") + " arguments"); 56 if(args.length > 0) LOG.info(" " + Arrays.asList(args)); 57 58 // add an client side interceptor to provide the client machine name to the server application 59 EJBClientContext.getCurrent().registerInterceptor(0, new ClientInterceptor()); 60 LOG.info(slsb.getGreeting()); 61 slsb.invokeWithClientContext(); 62 } 63 }