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 */
017package org.apache.camel.processor;
018
019import org.apache.camel.AsyncCallback;
020import org.apache.camel.AsyncProcessor;
021import org.apache.camel.Exchange;
022import org.apache.camel.Traceable;
023import org.apache.camel.support.ServiceSupport;
024import org.apache.camel.util.AsyncProcessorHelper;
025
026/**
027 * A processor which removes the property from the exchange
028 */
029public class RemovePropertyProcessor extends ServiceSupport implements AsyncProcessor, Traceable {
030    private final String propertyName;
031
032    public RemovePropertyProcessor(String propertyName) {
033        this.propertyName = propertyName;
034    }
035
036    public void process(Exchange exchange) throws Exception {
037        AsyncProcessorHelper.process(this, exchange);
038    }
039
040    @Override
041    public boolean process(Exchange exchange, AsyncCallback callback) {
042        try {
043            exchange.removeProperty(propertyName);
044        } catch (Exception e) {
045            exchange.setException(e);
046        }
047
048        callback.done(true);
049        return true;
050    }
051
052    @Override
053    public String toString() {
054        return "RemoveProperty(" + propertyName + ")";
055    }
056
057    public String getTraceLabel() {
058        return "removeProperty[" + propertyName + "]";
059    }
060
061    @Override
062    protected void doStart() throws Exception {
063        // noop
064    }
065
066    @Override
067    protected void doStop() throws Exception {
068        // noop
069    }
070}