Home » synapse-1.2-src » org.apache.synapse.transport.vfs » [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   
   20   package org.apache.synapse.transport.vfs;
   21   
   22   import java.util.HashMap;
   23   import java.util.Hashtable;
   24   import java.util.Map;
   25   import java.util.StringTokenizer;
   26   
   27   import org.apache.axis2.transport.OutTransportInfo;
   28   import org.apache.commons.logging.Log;
   29   import org.apache.commons.logging.LogFactory;
   30   
   31   import com.sun.net.ssl.internal.www.protocol.https.Handler;
   32   
   33   /**
   34    * The VFS OutTransportInfo is a holder of information to send an outgoing message
   35    * (e.g. a Response) to a VFS destination. Thus at a minimum a reference to a
   36    * File URI (i.e. directory or a file) are held
   37    */
   38   public class VFSOutTransportInfo implements OutTransportInfo {
   39   
   40       private static final Log log = LogFactory.getLog(VFSOutTransportInfo.class);
   41   
   42       private String outFileURI = null;
   43       private String outFileName = null;
   44       private String contentType = null;
   45       private int maxRetryCount = 3;
   46       private long reconnectTimeout = 30000;
   47       private boolean append;
   48   
   49       VFSOutTransportInfo(String outFileURI) {
   50           if (outFileURI.startsWith(VFSConstants.VFS_PREFIX)) {
   51               this.outFileURI = outFileURI.substring(VFSConstants.VFS_PREFIX.length());
   52           } else {
   53               this.outFileURI = outFileURI;
   54           }
   55           
   56           Map properties = getProperties(outFileURI);
   57           if(properties.containsKey(VFSConstants.MAX_RETRY_COUNT)) {
   58             String strMaxRetryCount = (String) properties.get(VFSConstants.MAX_RETRY_COUNT);
   59               maxRetryCount = Integer.parseInt(strMaxRetryCount);
   60           }
   61           if(properties.containsKey(VFSConstants.RECONNECT_TIMEOUT)) {
   62             String strReconnectTimeout = (String) properties.get(VFSConstants.RECONNECT_TIMEOUT);
   63               reconnectTimeout = Long.parseLong(strReconnectTimeout) * 1000;
   64           }        
   65           if (properties.containsKey(VFSConstants.APPEND)) {
   66               String strAppend = (String)properties.get(VFSConstants.APPEND);
   67               append = Boolean.parseBoolean(strAppend);
   68           }
   69       }
   70   
   71       public void setContentType(String contentType) {
   72           this.contentType = contentType;
   73       }
   74   
   75       public String getOutFileURI() {
   76           return outFileURI;
   77       }
   78   
   79       public String getOutFileName() {
   80           return outFileName;
   81       }
   82   
   83       public int getMaxRetryCount() {
   84         return maxRetryCount;
   85       }
   86   
   87       public void setMaxRetryCount(int maxRetryCount) {
   88         this.maxRetryCount = maxRetryCount;
   89       }
   90   
   91       public long getReconnectTimeout() {
   92         return reconnectTimeout;
   93       }
   94   
   95       public void setReconnectTimeout(long reconnectTimeout) {
   96         this.reconnectTimeout = reconnectTimeout;
   97       }
   98       
   99       public boolean isAppend() {
  100           return append;
  101       }
  102   
  103       public void setAppend(boolean append) {
  104           this.append = append;
  105       }
  106   
  107       public static Map getProperties(String url) {
  108           Map h = new HashMap();
  109           int propPos = url.indexOf("?");
  110           if (propPos != -1) {
  111               StringTokenizer st = new StringTokenizer(url.substring(propPos + 1), "&");
  112               while (st.hasMoreTokens()) {
  113                   String token = st.nextToken();
  114                   int sep = token.indexOf("=");
  115                   if (sep != -1) {
  116                       h.put(token.substring(0, sep), token.substring(sep + 1));
  117                   } else {
  118                       continue; // ignore, what else can we do?
  119                   }
  120               }
  121           }
  122           return h;
  123       }
  124   }

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