当前位置: 首页>>代码示例>>Java>>正文


Java RequestContext类代码示例

本文整理汇总了Java中org.apache.commons.fileupload.RequestContext的典型用法代码示例。如果您正苦于以下问题:Java RequestContext类的具体用法?Java RequestContext怎么用?Java RequestContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequestContext类属于org.apache.commons.fileupload包,在下文中一共展示了RequestContext类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileItemList

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
    if (!saveDir.isDirectory()) {
        saveDir.mkdir();
    }
    List<?> fileItems = null;
    RequestContext requestContext = new ServletRequestContext(request);
    if (FileUpload.isMultipartContent(requestContext)) {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setRepository(saveDir);
        factory.setSizeThreshold(fileSizeThreshold);
        ServletFileUpload upload = new ServletFileUpload(factory);
        fileItems = upload.parseRequest(request);
    }
    return fileItems;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:17,代码来源:UploadUtil.java

示例2: getFileItemList

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
/** 获取所有文本域 */
public static final List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
	if (!saveDir.isDirectory()) {
		saveDir.mkdir();
	}
	List<?> fileItems = null;
	RequestContext requestContext = new ServletRequestContext(request);
	if (FileUpload.isMultipartContent(requestContext)) {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setRepository(saveDir);
		factory.setSizeThreshold(fileSizeThreshold);
		ServletFileUpload upload = new ServletFileUpload(factory);
		fileItems = upload.parseRequest(request);
	}
	return fileItems;
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:17,代码来源:UploadUtil.java

示例3: getFileItemList

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
/** 获取所有文本域 */
public static List<?> getFileItemList(HttpServletRequest request, File saveDir) throws FileUploadException {
	if (!saveDir.isDirectory()) {
		saveDir.mkdir();
	}
	List<?> fileItems = null;
	RequestContext requestContext = new ServletRequestContext(request);
	if (FileUpload.isMultipartContent(requestContext)) {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setRepository(saveDir);
		factory.setSizeThreshold(fileSizeThreshold);
		ServletFileUpload upload = new ServletFileUpload(factory);
		fileItems = upload.parseRequest(request);
	}
	return fileItems;
}
 
开发者ID:haizicq,项目名称:osframe,代码行数:17,代码来源:UploadUtil.java

示例4: createRequestContext

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
/**
 * Creates a RequestContext needed by Jakarta Commons Upload.
 *
 * @param req the request.
 * @return a new request context.
 */
protected RequestContext createRequestContext(final HttpServletRequest req) {
    return new RequestContext() {
        public String getCharacterEncoding() {
            return req.getCharacterEncoding();
        }

        public String getContentType() {
            return req.getContentType();
        }

        public int getContentLength() {
            return req.getContentLength();
        }

        public InputStream getInputStream() throws IOException {
            InputStream in = req.getInputStream();
            if (in == null) {
                throw new IOException("Missing content in the request");
            }
            return req.getInputStream();
        }
    };
}
 
开发者ID:txazo,项目名称:struts2,代码行数:30,代码来源:JakartaMultiPartRequest.java

示例5: getRequestContext

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
public RequestContext getRequestContext(){
    return new RequestContext() {
        @Override
        public String getCharacterEncoding() {
            return charEncoding;
        }

        @Override
        public String getContentType() {
            return contentType;
        }

        @Override
        public int getContentLength() {
            return body.length;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return getBodyInputStream();
        }
    };
}
 
开发者ID:synchronoss,项目名称:nio-multipart,代码行数:24,代码来源:MultipartTestCases.java

示例6: createRequestContext

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
/**
 * Creates a RequestContext needed by Jakarta Commons Upload.
 *
 * @param req the HTTP request.
 * @return a new request context.
 */
private RequestContext createRequestContext(final HttpServletRequest req) {
    return new RequestContext() {
        @Override
        public String getCharacterEncoding() {
            return req.getCharacterEncoding();
        }

        @Override
        public String getContentType() {
            return req.getContentType();
        }

        @Override
        @Deprecated
        public int getContentLength() {
            return req.getContentLength();
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return req.getInputStream();
        }
    };
}
 
开发者ID:aspectran,项目名称:aspectran,代码行数:31,代码来源:CommonsMultipartFormDataParser.java

示例7: createRequestContext

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
private RequestContext createRequestContext(final HttpServletRequest req) {
    return new RequestContext() {
        public String getCharacterEncoding() {
            return req.getCharacterEncoding();
        }

        public String getContentType() {
            return req.getContentType();
        }

        public int getContentLength() {
            return req.getContentLength();
        }

        public InputStream getInputStream() throws IOException {
            return req.getInputStream();
        }
    };
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:20,代码来源:MonitoredMultiPartRequest.java

示例8: parseRequest

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
@Override
public List<FileItem> parseRequest(RequestContext ctx) throws FileUploadException {
    List<FileItem> items = super.parseRequest(ctx);
    String charset = ctx.getCharacterEncoding();

    for (FileItem fileItem : items) {
        if (fileItem instanceof AbstractFileItem) {
            ((AbstractFileItem) fileItem).setCharset(charset);
        }
    }

    return items;
}
 
开发者ID:solmix,项目名称:wmix,代码行数:14,代码来源:ServletFileUpload.java

示例9: getParameterMap

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
private MultipleEntryHashMap getParameterMap(RequestContext request,
                                             String charSetEncoding)
        throws FileUploadException {

    MultipleEntryHashMap parameterMap = new MultipleEntryHashMap();

    List items = parseRequest(request);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        DiskFileItem diskFileItem = (DiskFileItem)iter.next();

        boolean isFormField = diskFileItem.isFormField();

        Object value;
        try {
            if (isFormField) {
                value = getTextParameter(diskFileItem, charSetEncoding);
            } else {
                value = getFileParameter(diskFileItem);
            }
        } catch (Exception ex) {
            throw new FileUploadException(ex.getMessage());
        }
        parameterMap.put(diskFileItem.getFieldName(), value);
    }

    return parameterMap;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:29,代码来源:MultipartFormDataBuilder.java

示例10: parseRequest

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
private static List parseRequest(RequestContext requestContext)
        throws FileUploadException {
    // Create a factory for disk-based file items
    FileItemFactory factory = new DiskFileItemFactory();
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    // Parse the request
    return upload.parseRequest(requestContext);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:10,代码来源:MultipartFormDataBuilder.java

示例11: writeMultipart

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
@Test
public void writeMultipart() throws Exception {
	MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
	parts.add("name 1", "value 1");
	parts.add("name 2", "value 2+1");
	parts.add("name 2", "value 2+2");
	parts.add("name 3", null);

	Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
	parts.add("logo", logo);

	// SPR-12108
	Resource utf8 = new ClassPathResource("/org/springframework/http/converter/logo.jpg") {
		@Override
		public String getFilename() {
			return "Hall\u00F6le.jpg";
		}
	};
	parts.add("utf8", utf8);

	Source xml = new StreamSource(new StringReader("<root><child/></root>"));
	HttpHeaders entityHeaders = new HttpHeaders();
	entityHeaders.setContentType(MediaType.TEXT_XML);
	HttpEntity<Source> entity = new HttpEntity<Source>(xml, entityHeaders);
	parts.add("xml", entity);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	this.converter.setMultipartCharset(UTF_8);
	this.converter.write(parts, new MediaType("multipart", "form-data", UTF_8), outputMessage);

	final MediaType contentType = outputMessage.getHeaders().getContentType();
	assertNotNull("No boundary found", contentType.getParameter("boundary"));

	// see if Commons FileUpload can read what we wrote
	FileItemFactory fileItemFactory = new DiskFileItemFactory();
	FileUpload fileUpload = new FileUpload(fileItemFactory);
	RequestContext requestContext = new MockHttpOutputMessageRequestContext(outputMessage);
	List<FileItem> items = fileUpload.parseRequest(requestContext);
	assertEquals(6, items.size());
	FileItem item = items.get(0);
	assertTrue(item.isFormField());
	assertEquals("name 1", item.getFieldName());
	assertEquals("value 1", item.getString());

	item = items.get(1);
	assertTrue(item.isFormField());
	assertEquals("name 2", item.getFieldName());
	assertEquals("value 2+1", item.getString());

	item = items.get(2);
	assertTrue(item.isFormField());
	assertEquals("name 2", item.getFieldName());
	assertEquals("value 2+2", item.getString());

	item = items.get(3);
	assertFalse(item.isFormField());
	assertEquals("logo", item.getFieldName());
	assertEquals("logo.jpg", item.getName());
	assertEquals("image/jpeg", item.getContentType());
	assertEquals(logo.getFile().length(), item.getSize());

	item = items.get(4);
	assertFalse(item.isFormField());
	assertEquals("utf8", item.getFieldName());
	assertEquals("Hall\u00F6le.jpg", item.getName());
	assertEquals("image/jpeg", item.getContentType());
	assertEquals(logo.getFile().length(), item.getSize());

	item = items.get(5);
	assertEquals("xml", item.getFieldName());
	assertEquals("text/xml", item.getContentType());
	verify(outputMessage.getBody(), never()).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:74,代码来源:FormHttpMessageConverterTests.java

示例12: writeMultipartOrder

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
@Test
public void writeMultipartOrder() throws Exception {
	MyBean myBean = new MyBean();
	myBean.setString("foo");

	MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
	parts.add("part1", myBean);

	HttpHeaders entityHeaders = new HttpHeaders();
	entityHeaders.setContentType(MediaType.TEXT_XML);
	HttpEntity<MyBean> entity = new HttpEntity<MyBean>(myBean, entityHeaders);
	parts.add("part2", entity);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	this.converter.setMultipartCharset(UTF_8);
	this.converter.write(parts, new MediaType("multipart", "form-data", UTF_8), outputMessage);

	final MediaType contentType = outputMessage.getHeaders().getContentType();
	assertNotNull("No boundary found", contentType.getParameter("boundary"));

	// see if Commons FileUpload can read what we wrote
	FileItemFactory fileItemFactory = new DiskFileItemFactory();
	FileUpload fileUpload = new FileUpload(fileItemFactory);
	RequestContext requestContext = new MockHttpOutputMessageRequestContext(outputMessage);
	List<FileItem> items = fileUpload.parseRequest(requestContext);
	assertEquals(2, items.size());

	FileItem item = items.get(0);
	assertTrue(item.isFormField());
	assertEquals("part1", item.getFieldName());
	assertEquals("{\"string\":\"foo\"}", item.getString());

	item = items.get(1);
	assertTrue(item.isFormField());
	assertEquals("part2", item.getFieldName());

	// With developer builds we get: <MyBean><string>foo</string></MyBean>
	// But on CI server we get: <MyBean xmlns=""><string>foo</string></MyBean>
	// So... we make a compromise:
	assertThat(item.getString(),
			allOf(startsWith("<MyBean"), endsWith("><string>foo</string></MyBean>")));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:FormHttpMessageConverterTests.java

示例13: getHttpRequestData

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
private EBMSMessageHistoryRequestData getHttpRequestData() throws Exception
{
	// Check content Type
	String contentType 	= monitor.getContentType();
	
	if(contentType == null){
			System.out.println((monitor==null?"Null Monitor":"Monitor not null"));
			System.out.println("Lengeth " + monitor.getContentLength());
			Assert.fail("Null Content");
	}
	
	String mediaType 	= contentType.split(";")[0];		
	assertEquals("Invalid content type", "text/xml", mediaType);
	
	// Check the multi-part content.
	// Make a request context that bridge the content from our monitor to FileUpload library.    
	RequestContext rc = new RequestContext(){
		public String 		getCharacterEncoding()	{ return "charset=utf-8"; }
		public int 			getContentLength()		{ return monitor.getContentLength(); }
		public String 		getContentType()		{ return monitor.getContentType(); }
		public InputStream 	getInputStream()		{ return monitor.getInputStream(); }
	};
	
	
	BufferedReader bReader = 
					new BufferedReader(new InputStreamReader(monitor.getInputStream()));
	
	String strLine = "";
	do{
		strLine = bReader.readLine();
	}while(!strLine.contains("SOAP-ENV"));
	
	MimeHeaders header = new MimeHeaders();		
	header.addHeader("Content-Type", "text/xml");
	
	SOAPMessage msg = MessageFactory.newInstance().createMessage(
			header, new ByteArrayInputStream(strLine.getBytes()));
	
	EBMSMessageHistoryRequestData data = new EBMSMessageHistoryRequestData();
	data.setMessageId(getElementValue(msg.getSOAPBody(), "tns:messageId"));
	data.setMessageBox(getElementValue(msg.getSOAPBody(), "tns:messageBox"));
	data.setStatus(getElementValue(msg.getSOAPBody(), "tns:status"));
	data.setService(getElementValue(msg.getSOAPBody(), "tns:service"));
	data.setAction(getElementValue(msg.getSOAPBody(), "tns:action"));
	data.setConversationId(getElementValue(msg.getSOAPBody(), "tns:conversationId"));
	data.setCpaId(getElementValue(msg.getSOAPBody(), "tns:cpaId"));
	return data;
}
 
开发者ID:cecid,项目名称:hermes,代码行数:49,代码来源:EBMSMessageHistoryQuerySenderTest.java

示例14: processUpload

import org.apache.commons.fileupload.RequestContext; //导入依赖的package包/类
public void processUpload(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {
    String hasHotDeployment =
            (String) configContext.getAxisConfiguration().getParameterValue("hotdeployment");
    String hasHotUpdate =
            (String) configContext.getAxisConfiguration().getParameterValue("hotupdate");
    req.setAttribute("hotDeployment", (hasHotDeployment.equals("true")) ? "enabled"
            : "disabled");
    req.setAttribute("hotUpdate", (hasHotUpdate.equals("true")) ? "enabled" : "disabled");
    RequestContext reqContext = new ServletRequestContext(req);

    boolean isMultipart = ServletFileUpload.isMultipartContent(reqContext);
    if (isMultipart) {

        try {
            //Create a factory for disk-based file items
            FileItemFactory factory = new DiskFileItemFactory();
            //Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);
            List<?> items = upload.parseRequest(req);
            // Process the uploaded items
            Iterator<?> iter = items.iterator();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
                if (!item.isFormField()) {

                    String fileName = item.getName();
                    String fileExtesion = fileName;
                    fileExtesion = fileExtesion.toLowerCase();
                    if (!(fileExtesion.endsWith(".jar") || fileExtesion.endsWith(".aar"))) {
                        req.setAttribute("status", "failure");
                        req.setAttribute("cause", "Unsupported file type " + fileExtesion);
                    } else {

                        String fileNameOnly;
                        if (fileName.indexOf("\\") < 0) {
                            fileNameOnly =
                                    fileName.substring(fileName.lastIndexOf("/") + 1, fileName
                                            .length());
                        } else {
                            fileNameOnly =
                                    fileName.substring(fileName.lastIndexOf("\\") + 1, fileName
                                            .length());
                        }

                        File uploadedFile = new File(serviceDir, fileNameOnly);
                        item.write(uploadedFile);
                        req.setAttribute("status", "success");
                        req.setAttribute("filename", fileNameOnly);
                    }
                }
            }
        } catch (Exception e) {
            req.setAttribute("status", "failure");
            req.setAttribute("cause", e.getMessage());

        }
    }
    renderView("upload.jsp", req, res);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:61,代码来源:AdminAgent.java


注:本文中的org.apache.commons.fileupload.RequestContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。