Home » synapse-1.2-src » org.apache.synapse.transport.nhttp.util » [javadoc | source]

    1   /*
    2   *  Licensed to the Apache Software Foundation (ASF) under one
    3   *  or more contributor license agreements.  See the NOTICE file
    4   *  distributed with this work for additional information
    5   *  regarding copyright ownership.  The ASF licenses this file
    6   *  to you under the Apache License, Version 2.0 (the
    7   *  "License"); you may not use this file except in compliance
    8   *  with the License.  You may obtain a copy of the License at
    9   *
   10   *   http://www.apache.org/licenses/LICENSE-2.0
   11   *
   12   *  Unless required by applicable law or agreed to in writing,
   13   *  software distributed under the License is distributed on an
   14   *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15   *  KIND, either express or implied.  See the License for the
   16   *  specific language governing permissions and limitations
   17   *  under the License.
   18   */
   19   package org.apache.synapse.transport.nhttp.util;
   20   
   21   import org.apache.axis2.AxisFault;
   22   import org.apache.axis2.context.MessageContext;
   23   import org.apache.axis2.transport.MessageFormatter;
   24   import org.apache.axis2.transport.TransportUtils;
   25   import org.apache.commons.logging.Log;
   26   import org.apache.commons.logging.LogFactory;
   27   import org.apache.http.protocol.HTTP;
   28   
   29   import java.util.Map;
   30   
   31   /**
   32    * Factory for getting Decorator to Message Formatter . This decorator is needed when extending
   33    * message formatter  by adding decoration functionality
   34    */
   35   public class MessageFormatterDecoratorFactory {
   36   
   37       private static final Log log = LogFactory.getLog(MessageFormatterDecoratorFactory.class);
   38   
   39       private static final String GZIP_CODEC = "gzip";
   40   
   41       public static MessageFormatter createMessageFormatterDecorator(MessageContext msgContext) {
   42   
   43           if (msgContext == null) {
   44               throw new IllegalArgumentException("Message Context cannot be null");
   45           }
   46   
   47           try {
   48               // Get message formatter based on the content type
   49               MessageFormatter formatter = TransportUtils.getMessageFormatter(msgContext);
   50   
   51               Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
   52               if (o != null && o instanceof Map) {
   53                   Map headers = (Map) o;
   54   
   55                   String encode = (String) headers.get(HTTP.CONTENT_ENCODING);
   56                   if (encode != null) {
   57   
   58                       //If message  contains 'Accept-Encoding' header and  if it's value is 'qzip'
   59                       if (GZIP_CODEC.equals(encode)) {
   60                           formatter = new GzipMessageFormatterDecorator(formatter);
   61                       }
   62                       //if there are any type for 'Accept-Encoding' , those should go here
   63   
   64                   }
   65               }
   66               return formatter;
   67   
   68           } catch (AxisFault axisFault) {
   69               String msg = "Cannot find a suitable MessageFormatter : " + axisFault.getMessage();
   70               log.error(msg, axisFault);
   71           }
   72   
   73           return null;
   74   
   75       }
   76   }

Home » synapse-1.2-src » org.apache.synapse.transport.nhttp.util » [javadoc | source]