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.component.cxf; 018 019 import org.apache.camel.Processor; 020 import org.apache.camel.impl.DefaultConsumer; 021 import org.apache.cxf.endpoint.ServerImpl; 022 import org.apache.cxf.frontend.ServerFactoryBean; 023 import org.apache.cxf.message.Message; 024 025 /** 026 * A consumer of exchanges for a service in CXF 027 * 028 * @version $Revision: 563665 $ 029 */ 030 public class CxfInvokeConsumer extends DefaultConsumer<CxfExchange> { 031 protected CxfInvokeEndpoint cxfEndpoint; 032 private ServerImpl server; 033 034 public CxfInvokeConsumer(CxfInvokeEndpoint endpoint, Processor processor) { 035 super(endpoint, processor); 036 this.cxfEndpoint = endpoint; 037 } 038 039 @Override 040 protected void doStart() throws Exception { 041 super.doStart(); 042 // TODO we need to add custom cxf message observer and wire the 043 // incomingCxfMessage method. Also, custom cxf interceptors are 044 // needed in order to object SOAP/XML message. Currently, the 045 // CXF service invoker will invoke the service class. 046 if (server != null) { 047 // start a cxf service 048 ServerFactoryBean svrBean = new ServerFactoryBean(); 049 svrBean.setAddress(getEndpoint().getEndpointUri()); 050 svrBean.setServiceClass(Class.forName(cxfEndpoint.getProperty(CxfConstants.IMPL))); 051 svrBean.setBus(cxfEndpoint.getBus()); 052 053 server = (ServerImpl)svrBean.create(); 054 server.start(); 055 } 056 } 057 058 @Override 059 protected void doStop() throws Exception { 060 if (server != null) { 061 server.stop(); 062 server = null; 063 } 064 super.doStop(); 065 } 066 067 // TODO this method currently is not being called. 068 protected void incomingCxfMessage(Message message) { 069 try { 070 CxfExchange exchange = cxfEndpoint.createExchange(message); 071 getProcessor().process(exchange); 072 } catch (Exception e) { 073 // TODO: what do do if we are getting processing errors from camel? 074 // Shutdown? 075 e.printStackTrace(); 076 } 077 } 078 }