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 java.util.Map;
020    
021    import org.apache.cxf.message.Exchange;
022    
023    /**
024     * An strategy interface for implementing binding between CXF {@link Exchange} 
025     * and Camel {@link org.apache.camel.Exchange}.  
026     * 
027     * Assumptions: CxfProducer and CxfConsumer set {@link #DataFormat} and 
028     * {@link org.apache.cxf.service.model.BindingOperationInfo} 
029     * in Camel Exchange property before calling into these methods.  
030     * 
031     * @version $Revision: 15280 $
032     * @since 2.0
033     */
034    public interface CxfBinding {
035        
036        /**
037         * <p>
038         * Populate a CXF Exchange from a Camel Exchange.  The resulted CXF Exchange is an 
039         * <b>outgoing request</b> to be sent to CXF server.  This method is called by 
040         * {@link CxfProducer#process(org.apache.camel.Exchange)} to process a Camel Exchange
041         * for invoking an CXF web service operation.  Note that information is populated
042         * to CXF Exchange and the request context, which are passed as arguments to the 
043         * CXF API's Client.invoke() method.  The arguments to the web service operation
044         * are extracted from the Camel IN message body by CxfProducer.
045         * </p>
046         * 
047         * <p>
048         * Exchange is passed in this direction: Camel route => CxfProducer => <b>apply this
049         * binding method </b>=> CXF server
050         * </p>
051         * 
052         * @param cxfExchange exchange to be populated
053         * @param camelExchange exchange that contains a request
054         * @param requestContext a map contains request contexts.  <b>This parameter must not
055         * be null</b>.  The Client.invoke() method does not allow caller to
056         * pass in a CXF Message.  The request context are copied to the CXF Message by the
057         * Client.invoke() method.  This is how caller can set properties on the CXF message.  
058         * 
059         */
060        void populateCxfRequestFromExchange(Exchange cxfExchange,
061                org.apache.camel.Exchange camelExchange,
062                Map<String, Object> requestContext);
063    
064        /**
065         * <p>
066         * Populate a Camel Exchange from a CXF Exchange, which is a an <b>incoming response</b>
067         * from a CXF server.  This method is called by {@link CxfProducer} after it makes an 
068         * invocation to the Client.invoke() method.  It calls this method to translate the 
069         * CXF response message to Camel message. 
070         * </p>
071         * 
072         * <p>
073         * Exchange is passed in this direction: Camel route <= <b>apply this binding method</b>
074         * <= CxfProducer <= CXF Server
075         * </p>
076         * @param camelExchange exchanged to be populated 
077         * @param cxfExchange exchange that contains a response
078         * @param responseContext map contains response context from CXF
079         */
080        void populateExchangeFromCxfResponse(org.apache.camel.Exchange camelExchange,
081                Exchange cxfExchange, Map<String, Object> responseContext);
082      
083        /**
084         * <p>
085         * Populate a Camel Exchange from a CXF Exchange, which is an <b>incoming request</b> 
086         * from a CXF client.  This method is called by {@link CxfConsumer} to handle a 
087         * CXF request arrives at an endpoint.  It translates a CXF request to a Camel
088         * Exchange for Camel route to process the exchange.
089         * </p>  
090         * 
091         * <p>
092         * Exchange is passed in this direction: CXF Endpoint => CxfConsumer => <b>apply this
093         * binding method </b> => Camel route
094         * </p>
095         * @param cxfExchange CXF exchange that contains a request
096         * @param camelExchange Camel exchange to be populated
097         */
098        void populateExchangeFromCxfRequest(Exchange cxfExchange,
099                org.apache.camel.Exchange camelExchange);
100        
101    
102        /**
103         * <p>
104         * Populate a CXF Exchange from a Camel Exchange.  The resulted CXF Exchange is an 
105         * <b>outgoing response</b> to be sent back to the CXF client.  This method is called 
106         * by {@link CxfConsumer} to translate a Camel Exchange to a CXF response Exchange.
107         * </p>
108         * 
109         * <p>
110         * Exchange is passed in this direction: CXF Endpoint <= <b>apply this binding method</b>
111         * <= CxfConsumer <= Camel route
112         * </p>
113         * @param camelExchange Camel exchange that contains an out message
114         * @param cxfExchange CXF exchange to be populated
115         */
116        void populateCxfResponseFromExchange(org.apache.camel.Exchange camelExchange,
117                Exchange cxfExchange);
118    
119        /**
120         * <p>
121         * Extract the message headers which key are start from javax.xml.ws* from the
122         * CXF exchange's inMessage, and put these headers into the context
123         * </p>
124         * 
125         * 
126         * @param cxfExchange CXF exchange to be populated
127         * @param context The map which used to store the message headers
128         */
129        void extractJaxWsContext(Exchange cxfExchange, Map<String, Object> context);
130        
131        /**
132         * <p>
133         * Copy the javax.xml.ws* headers into cxfExchange's outMessage, 
134         * if the cxfExchange has no outMessage, skip this copy
135         * </p>
136         * 
137         * @param cxfExchange CXF exchange to be populated
138         * @param context The map which used to store the message headers
139         */
140        void copyJaxWsContext(Exchange cxfExchange, Map<String, Object> context);
141    
142    }