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.common.header;
018
019 import java.util.Arrays;
020 import java.util.Iterator;
021 import java.util.List;
022
023 import org.apache.camel.spi.HeaderFilterStrategy.Direction;
024 import org.apache.cxf.binding.soap.SoapBindingConstants;
025 import org.apache.cxf.binding.soap.SoapBindingFactory;
026 import org.apache.cxf.binding.soap.SoapHeader;
027 import org.apache.cxf.binding.soap.SoapVersion;
028 import org.apache.cxf.binding.soap.SoapVersionFactory;
029 import org.apache.cxf.headers.Header;
030 import org.slf4j.Logger;
031 import org.slf4j.LoggerFactory;
032
033 /**
034 * A {@link MessageHeaderFilter} to drop all SOAP headers.
035 *
036 * @version
037 */
038 public class SoapMessageHeaderFilter implements MessageHeaderFilter {
039 private static final Logger LOG = LoggerFactory.getLogger(SoapMessageHeaderFilter.class);
040
041 private static final List<String> ACTIVATION_NS =
042 Arrays.asList(SoapBindingConstants.SOAP11_BINDING_ID,
043 SoapBindingFactory.SOAP_11_BINDING,
044 SoapBindingFactory.SOAP_12_BINDING);
045
046 public List<String> getActivationNamespaces() {
047 return ACTIVATION_NS;
048 }
049
050 public void filter(Direction direction, List<Header> headers) {
051 // Treat both in and out direction the same
052 if (headers == null) {
053 return;
054 }
055
056 Iterator<Header> iterator = headers.iterator();
057 while (iterator.hasNext()) {
058 Header header = iterator.next();
059 LOG.trace("Processing header: {}", header);
060
061 if (!(header instanceof SoapHeader)) {
062 LOG.trace("Skipped header: {} since it is not a SoapHeader", header);
063 continue;
064 }
065
066 SoapHeader soapHeader = SoapHeader.class.cast(header);
067 for (Iterator<SoapVersion> itv = SoapVersionFactory.getInstance().getVersions(); itv.hasNext();) {
068 SoapVersion version = itv.next();
069
070 if (soapHeader.getActor() != null
071 && soapHeader.getActor().equals(version.getNextRole())) {
072 // dropping headers if actor/role equals to {ns}/role|actor/next
073 // cxf SoapHeader needs to have soap:header@relay attribute,
074 // then we can check for it here as well
075 LOG.trace("Filtered header: {}", header);
076 iterator.remove();
077 break;
078 }
079 }
080 }
081 }
082
083 }