Coverage Report - org.mule.transport.http.transformers.ServletRequestToOutputHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
ServletRequestToOutputHandler
0%
0/9
N/A
0
ServletRequestToOutputHandler$1
0%
0/6
N/A
0
 
 1  
 /*
 2  
  * $Id: ServletRequestToOutputHandler.java 20321 2010-11-24 15:21:24Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.transport.http.transformers;
 11  
 
 12  
 import org.mule.api.MuleEvent;
 13  
 import org.mule.api.transformer.DiscoverableTransformer;
 14  
 import org.mule.api.transformer.TransformerException;
 15  
 import org.mule.api.transport.OutputHandler;
 16  
 import org.mule.transformer.AbstractTransformer;
 17  
 import org.mule.transformer.types.DataTypeFactory;
 18  
 import org.mule.util.IOUtils;
 19  
 
 20  
 import java.io.IOException;
 21  
 import java.io.InputStream;
 22  
 import java.io.OutputStream;
 23  
 
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 
 26  
 /**
 27  
  * Adds support for converting a {@link javax.servlet.http.HttpServletRequest} into an {@link org.mule.api.transport.OutputHandler}
 28  
  */
 29  
 public class ServletRequestToOutputHandler extends AbstractTransformer implements DiscoverableTransformer
 30  
 {
 31  0
     private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING;
 32  
 
 33  
     public ServletRequestToOutputHandler()
 34  0
     {
 35  0
         registerSourceType(DataTypeFactory.create(HttpServletRequest.class));
 36  0
         setReturnDataType(DataTypeFactory.create(OutputHandler.class));
 37  0
     }
 38  
 
 39  
     @Override
 40  
     public Object doTransform(final Object src, String encoding) throws TransformerException
 41  
     {
 42  0
             return new OutputHandler()
 43  0
             {
 44  
                 public void write(MuleEvent event, OutputStream out) throws IOException
 45  
                 {
 46  0
                     InputStream is = ((HttpServletRequest) src).getInputStream();
 47  
                     try
 48  
                     {
 49  0
                         IOUtils.copyLarge(is, out);
 50  
                     }
 51  
                     finally
 52  
                     {
 53  0
                         is.close();
 54  0
                     }
 55  0
                 }
 56  
             };
 57  
         }
 58  
 
 59  
     /**
 60  
      * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
 61  
      *
 62  
      * @return the priority weighting for this transformer. This is a value between
 63  
      *         {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
 64  
      */
 65  
     public int getPriorityWeighting()
 66  
     {
 67  0
         return priorityWeighting;
 68  
     }
 69  
 
 70  
     /**
 71  
      * If 2 or more discoverable transformers are equal, this value can be used to select the correct one
 72  
      *
 73  
      * @param weighting the priority weighting for this transformer. This is a value between
 74  
      *                  {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}.
 75  
      */
 76  
     public void setPriorityWeighting(int weighting)
 77  
     {
 78  0
         priorityWeighting = weighting;
 79  0
     }
 80  
 }