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.component.cxf.jaxrs;
019
020 import org.apache.camel.Processor;
021 import org.apache.camel.impl.DefaultConsumer;
022 import org.apache.cxf.endpoint.Server;
023 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
024
025 /**
026 * A Consumer of exchanges for a JAXRS service in CXF. CxfRsConsumer acts a CXF
027 * service to receive REST requests, convert them to a normal java object invocation,
028 * and forward them to Camel route for processing.
029 * It is also responsible for converting and sending back responses to CXF client.
030 */
031 public class CxfRsConsumer extends DefaultConsumer {
032 private Server server;
033
034 public CxfRsConsumer(CxfRsEndpoint endpoint, Processor processor) {
035 super(endpoint, processor);
036 CxfRsInvoker cxfRsInvoker = new CxfRsInvoker(endpoint, processor);
037 JAXRSServerFactoryBean svrBean = endpoint.createJAXRSServerFactoryBean();
038 svrBean.setInvoker(cxfRsInvoker);
039 server = svrBean.create();
040 }
041
042 @Override
043 protected void doStart() throws Exception {
044 super.doStart();
045 server.start();
046 }
047
048 @Override
049 protected void doStop() throws Exception {
050 server.stop();
051 super.doStop();
052 }
053
054 public Server getServer() {
055 return server;
056 }
057
058 }