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.feature;
019
020 import java.util.logging.Logger;
021
022 import org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor;
023 import org.apache.cxf.Bus;
024 import org.apache.cxf.common.logging.LogUtils;
025 import org.apache.cxf.endpoint.Client;
026 import org.apache.cxf.endpoint.Server;
027 import org.apache.cxf.phase.Phase;
028
029 /**
030 * <p>
031 * MessageDataFormatFeature sets up the CXF endpoint interceptor for handling the
032 * Message in Message data format. Only the interceptors of these phases are
033 * <b>preserved</b>:
034 * </p>
035 * <p>
036 * In phases: {Phase.RECEIVE , Phase.INVOKE, Phase.POST_INVOKE}
037 * </p>
038 * <p>
039 * Out phases: {Phase.PREPARE_SEND, Phase.WRITE, Phase.SEND, Phase.PREPARE_SEND_ENDING}
040 * </p>
041 */
042 public class MessageDataFormatFeature extends AbstractDataFormatFeature {
043
044 private static final Logger LOG = LogUtils.getL7dLogger(MessageDataFormatFeature.class);
045 // filter the unused in phase interceptor
046 private static final String[] REMAINING_IN_PHASES = {Phase.RECEIVE , Phase.USER_STREAM,
047 Phase.INVOKE, Phase.POST_INVOKE};
048 // filter the unused in phase interceptor
049 private static final String[] REMAINING_OUT_PHASES = {Phase.PREPARE_SEND, Phase.USER_STREAM,
050 Phase.WRITE, Phase.SEND, Phase.PREPARE_SEND_ENDING};
051
052 @Override
053 public void initialize(Client client, Bus bus) {
054
055 removeInterceptorWhichIsOutThePhases(client.getInInterceptors(), REMAINING_IN_PHASES);
056 removeInterceptorWhichIsOutThePhases(client.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES);
057 client.getEndpoint().getBinding().getInInterceptors().clear();
058
059 removeInterceptorWhichIsOutThePhases(client.getOutInterceptors(), REMAINING_OUT_PHASES);
060 removeInterceptorWhichIsOutThePhases(client.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES);
061 client.getEndpoint().getBinding().getOutInterceptors().clear();
062 client.getEndpoint().getOutInterceptors().add(new RawMessageContentRedirectInterceptor());
063 }
064
065 @Override
066 public void initialize(Server server, Bus bus) {
067 // currently we do not filter the bus
068 // remove the interceptors
069 removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(), REMAINING_IN_PHASES);
070 removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES);
071
072 // Do not using the binding interceptor any more
073 server.getEndpoint().getBinding().getInInterceptors().clear();
074
075 removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getOutInterceptors(), REMAINING_OUT_PHASES);
076 removeInterceptorWhichIsOutThePhases(server.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES);
077
078 // Do not use the binding interceptor any more
079 server.getEndpoint().getBinding().getOutInterceptors().clear();
080 server.getEndpoint().getOutInterceptors().add(new RawMessageContentRedirectInterceptor());
081 }
082
083 @Override
084 protected Logger getLogger() {
085 return LOG;
086 }
087
088 }