All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.service.customer.client.CustomerServiceClient Maven / Gradle / Ivy

The newest version!
/**
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package com.service.customer.client;

import java.util.List;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import com.service.customer.ejb.CustomerInfo;
import com.service.customer.ejb.ProcessCustomerSessionRemote;

public class CustomerServiceClient {

    public static void main(String[] args) {
        Properties p = new Properties();
        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
        p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201");
        try {
            Context ic = new InitialContext(p);
            
            ProcessCustomerSessionRemote processCustomer = (ProcessCustomerSessionRemote) ic.lookup("ProcessCustomerSessionBeanRemote");
            List customerList = null;
            customerList = processCustomer.findAllCustomers();
            if ( customerList == null || customerList.size() == 0) {
                System.out.println("No customer information is available");
            } else {
                System.out.println("-----------------------------------------------------------");
                System.out.println("Customer ID \tFull Name \tEmail Address \tInterests");
                for (int i = 0; i < customerList.size(); i ++) {
                    CustomerInfo customer = (CustomerInfo) customerList.get(i);
                    System.out.println(customer.getCustomerId() + " \t" + customer.getFullName() 
                            + " \t" + customer.getEmailAddress() + " \t" + customer.getInterests());
                }
                System.out.println("--------------------------------------------------------------");
            }

            } catch (Exception e) {
                e.printStackTrace();
            }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy