📄 servletrequesttooutputhandler.java
字号:
/* * $Id: ServletRequestToOutputHandler.java 12189 2008-06-27 14:57:32Z dfeist $ * -------------------------------------------------------------------------------------- * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */package org.mule.transport.http.transformers;import org.mule.api.MuleEvent;import org.mule.api.transformer.DiscoverableTransformer;import org.mule.api.transformer.TransformerException;import org.mule.api.transport.OutputHandler;import org.mule.transformer.AbstractTransformer;import org.mule.util.IOUtils;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import javax.servlet.http.HttpServletRequest;/** * Adds support for converting a {@link javax.servlet.http.HttpServletRequest} into an {@link org.mule.api.transport.OutputHandler} */public class ServletRequestToOutputHandler extends AbstractTransformer implements DiscoverableTransformer{ private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING; public ServletRequestToOutputHandler() { registerSourceType(HttpServletRequest.class); setReturnClass(OutputHandler.class); } //@Override public Object doTransform(final Object src, String encoding) throws TransformerException { return new OutputHandler() { public void write(MuleEvent event, OutputStream out) throws IOException { InputStream is = ((HttpServletRequest) src).getInputStream(); try { IOUtils.copyLarge(is, out); } finally { is.close(); } } }; } /** * If 2 or more discoverable transformers are equal, this value can be used to select the correct one * * @return the priority weighting for this transformer. This is a value between * {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}. */ public int getPriorityWeighting() { return priorityWeighting; } /** * If 2 or more discoverable transformers are equal, this value can be used to select the correct one * * @param weighting the priority weighting for this transformer. This is a value between * {@link #MIN_PRIORITY_WEIGHTING} and {@link #MAX_PRIORITY_WEIGHTING}. */ public void setPriorityWeighting(int weighting) { priorityWeighting = weighting; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -