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    package org.apache.camel.example.client;
018    
019    import org.apache.camel.example.server.Multiplier;
020    import org.springframework.context.ApplicationContext;
021    import org.springframework.context.support.ClassPathXmlApplicationContext;
022    
023    /**
024     * Client that uses Camel Spring Remoting for very easy integration with the server.
025     * <p/>
026     * Requires that the JMS broker is running, as well as CamelServer
027     */
028    public final class CamelClientRemoting {
029        private CamelClientRemoting() {
030            //Helper class
031        }
032    
033        // START SNIPPET: e1
034        public static void main(final String[] args) {
035            System.out.println("Notice this client requires that the CamelServer is already running!");
036    
037            ApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
038            // just get the proxy to the service and we as the client can use the "proxy" as it was
039            // a local object we are invoking. Camel will under the covers do the remote communication
040            // to the remote ActiveMQ server and fetch the response.
041            Multiplier multiplier = (Multiplier)context.getBean("multiplierProxy");
042    
043            System.out.println("Invoking the multiply with 33");
044            int response = multiplier.multiply(33);
045            System.out.println("... the result is: " + response);
046    
047            System.exit(0);
048        }
049        // END SNIPPET: e1
050    
051    }