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 org.apache.camel.loanbroker.webservice.version;
019    
020    
021    import org.apache.cxf.BusFactory;
022    import org.apache.cxf.frontend.ClientFactoryBean;
023    import org.apache.cxf.frontend.ClientProxyFactoryBean;
024    
025    /**
026     * The client that will invoke the loan broker service
027     */
028    
029    //START SNIPPET: client
030    public class Client {
031    
032        public LoanBrokerWS getProxy(String address) {
033            // Now we use the simple front API to create the client proxy
034            ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
035            ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
036            clientBean.setAddress(address);
037            clientBean.setServiceClass(LoanBrokerWS.class);
038            clientBean.setBus(BusFactory.getDefaultBus());
039            return (LoanBrokerWS) proxyFactory.create();
040        }
041    
042        public static void main(String[] args) {
043            Client client = new Client();
044            String result = null;
045            LoanBrokerWS loanBroker = client.getProxy(Constants.LOANBROKER_ADDRESS);
046            long startTime = System.currentTimeMillis();
047            result = loanBroker.getLoanQuote("Sequential SSN", 1000.54, 10);
048            long endTime = System.currentTimeMillis();
049            System.out.println("It takes " + (endTime - startTime) + " milliseconds to call the sequential loan broker service");
050            System.out.println(result);
051    
052            LoanBrokerWS paralleLoanBroker = client.getProxy(Constants.PARALLEL_LOANBROKER_ADDRESS);
053            startTime = System.currentTimeMillis();
054            result = paralleLoanBroker.getLoanQuote("Parallel SSN", 1000.54, 10);
055            endTime = System.currentTimeMillis();
056            System.out.println("It takes " + (endTime - startTime) + " milliseconds to call the parallel loan broker service");
057            System.out.println(result);
058        }
059    
060    }
061    //END SNIPPET: client