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.camel.transport;
018
019 import javax.xml.ws.Endpoint;
020
021 import org.apache.cxf.Bus;
022 import org.apache.cxf.BusFactory;
023 import org.apache.cxf.bus.spring.SpringBusFactory;
024
025 public class Server {
026 Endpoint endpointA;
027 Endpoint endpointB;
028
029 public void prepare() throws Exception {
030 // setup the camel context for the camel transport
031 // START SNIPPET: e1
032 SpringBusFactory bf = new SpringBusFactory();
033 BusFactory.setDefaultBus(null);
034 Bus bus = bf.createBus("/org/apache/camel/example/camel/transport/CamelDestination.xml");
035 BusFactory.setDefaultBus(bus);
036 // END SNIPPET: e1
037 }
038
039 public void start() throws Exception {
040 // start the endpoints
041 System.out.println("Starting Server");
042 // START SNIPPET: e2
043 GreeterImpl implementor = new GreeterImpl();
044 implementor.setSuffix("EndpointA");
045 String address = "camel://direct:EndpointA";
046 endpointA = Endpoint.publish(address, implementor);
047
048 implementor = new GreeterImpl();
049 implementor.setSuffix("EndpointB");
050 address = "camel://direct:EndpointB";
051 endpointB = Endpoint.publish(address, implementor);
052 // END SNIPPET: e2
053 }
054
055 public void stop() {
056 if (endpointA != null) {
057 endpointA.stop();
058 }
059 if (endpointB != null) {
060 endpointB.stop();
061 }
062 }
063
064
065 public static void main(String args[]) throws Exception {
066 Server server = new Server();
067 server.prepare();
068 server.start();
069
070 System.out.println("Server ready...");
071
072 Thread.sleep(5 * 60 * 1000);
073 System.out.println("Server exiting");
074 server.stop();
075 System.exit(0);
076 }
077 }