001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
003 * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
004 * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
005 * License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
010 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
011 * specific language governing permissions and limitations under the License.
012 */
013 package org.apache.camel.component.jbi;
014
015 import org.apache.camel.Endpoint;
016 import org.apache.camel.Processor;
017 import org.apache.camel.FailedToCreateProducerException;
018 import org.apache.commons.logging.Log;
019 import org.apache.commons.logging.LogFactory;
020 import org.apache.servicemix.common.ServiceUnit;
021 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
022
023 import javax.jbi.messaging.MessageExchange;
024 import javax.jbi.messaging.NormalizedMessage;
025 import javax.xml.namespace.QName;
026
027 /**
028 * A JBI endpoint which when invoked will delegate to a Camel endpoint
029 *
030 * @version $Revision: 426415 $
031 */
032 public class CamelJbiEndpoint extends ProviderEndpoint {
033 public static final QName SERVICE_NAME = new QName("http://activemq.apache.org/camel/schema/jbi", "endpoint");
034
035 private static final transient Log log = LogFactory.getLog(CamelJbiEndpoint.class);
036 private Endpoint camelEndpoint;
037 private JbiBinding binding;
038 private Processor camelProcessor;
039
040 public CamelJbiEndpoint(ServiceUnit serviceUnit, QName service, String endpoint, Endpoint camelEndpoint, JbiBinding binding, Processor camelProcessor) {
041 super(serviceUnit, service, endpoint);
042 this.camelProcessor = camelProcessor;
043 this.camelEndpoint = camelEndpoint;
044 this.binding = binding;
045 }
046
047 public CamelJbiEndpoint(ServiceUnit serviceUnit, Endpoint camelEndpoint, JbiBinding binding, Processor camelProcesso) {
048 this(serviceUnit, SERVICE_NAME, camelEndpoint.getEndpointUri(), camelEndpoint, binding, camelProcesso);
049 }
050
051 protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception {
052 if (log.isDebugEnabled()) {
053 log.debug("Received exchange: " + exchange);
054 }
055 JbiExchange camelExchange = new JbiExchange(camelEndpoint.getContext(), binding, exchange);
056 camelProcessor.process(camelExchange);
057 }
058
059 protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
060 if (log.isDebugEnabled()) {
061 log.debug("Received exchange: " + exchange);
062 }
063 /*
064 * ToDo
065 */
066 }
067 }