001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package com.service.customer.client; 019 020 import java.util.List; 021 import java.util.Properties; 022 023 import javax.naming.Context; 024 import javax.naming.InitialContext; 025 026 import com.service.customer.ejb.CustomerInfo; 027 import com.service.customer.ejb.ProcessCustomerSessionRemote; 028 029 public class CustomerServiceClient { 030 031 public static void main(String[] args) { 032 Properties p = new Properties(); 033 p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); 034 p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201"); 035 try { 036 Context ic = new InitialContext(p); 037 038 ProcessCustomerSessionRemote processCustomer = (ProcessCustomerSessionRemote) ic.lookup("ProcessCustomerSessionBeanRemote"); 039 List<CustomerInfo> customerList = null; 040 customerList = processCustomer.findAllCustomers(); 041 if ( customerList == null || customerList.size() == 0) { 042 System.out.println("No customer information is available"); 043 } else { 044 System.out.println("-----------------------------------------------------------"); 045 System.out.println("Customer ID \tFull Name \tEmail Address \tInterests"); 046 for (int i = 0; i < customerList.size(); i ++) { 047 CustomerInfo customer = (CustomerInfo) customerList.get(i); 048 System.out.println(customer.getCustomerId() + " \t" + customer.getFullName() 049 + " \t" + customer.getEmailAddress() + " \t" + customer.getInterests()); 050 } 051 System.out.println("--------------------------------------------------------------"); 052 } 053 054 } catch (Exception e) { 055 e.printStackTrace(); 056 } 057 } 058 }