protected String getPostContent(HttpServletRequest request, Map<String,FormDataItem> formItems) throws ContentTypes.InvalidContentTypeException, IOException { String content = null; ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, request.getContentType()); if (formParser.isMultipartContent(request)) { for (FormDataItem item : formParser.parse(request)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field // with field name as "request". It will contain the json request. Any further form // field or file item will not be parsed out, but will be exposed via getFormItem // method of RequestItem. if (!Strings.isNullOrEmpty(item.getContentType())) { ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES, item.getContentType()); } content = item.getAsString(); } else { formItems.put(item.getFieldName(), item); } } } else { content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); } return content; }
protected String getPostContent(HttpServletRequest request, Map<String,FormDataItem> formItems) throws ContentTypes.InvalidContentTypeException, IOException { String content = null; ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, request.getContentType()); if (formParser.isMultipartContent(request)) { for (FormDataItem item : formParser.parse(request)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field // with field name as "request". It will contain the json request. Any further form // field or file item will not be parsed out, but will be exposed via getFormItem // method of RequestItem. if (!StringUtils.isEmpty(item.getContentType())) { ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES, item.getContentType()); } content = item.getAsString(); } else { formItems.put(item.getFieldName(), item); } } } else { content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); } return content; }
protected String getPostContent(HttpServletRequest request, Map<String,FormDataItem> formItems) throws ContentTypes.InvalidContentTypeException, IOException { String content = null; ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, request.getContentType()); if (formParser.isMultipartContent(request)) { for (FormDataItem item : formParser.parse(request)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field // with field name as "request". It will contain the json request. Any further form // field or file item will not be parsed out, but will be exposed via getFormItem // method of RequestItem. if (!Strings.isNullOrEmpty(item.getContentType())) { ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES, item.getContentType()); } content = item.getAsString(); } else { formItems.put(item.getFieldName(), item); } } } else { content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); } return content; }
protected String getPostContent(HttpServletRequest request, Map<String,FormDataItem> formItems) throws ContentTypes.InvalidContentTypeException, IOException { String content = null; ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, request.getContentType()); if (formParser.isMultipartContent(request)) { for (FormDataItem item : formParser.parse(request)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field // with field name as "request". It will contain the json request. Any further form // field or file item will not be parsed out, but will be exposed via getFormItem // method of RequestItem. if (!Strings.isNullOrEmpty(item.getContentType())) { ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES, item.getContentType()); } content = item.getAsString(); } else { formItems.put(item.getFieldName(), item); } } } else { content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); } return content; }
protected String getPostContent(HttpServletRequest request, Map<String,FormDataItem> formItems) throws ContentTypes.InvalidContentTypeException, IOException { String content = null; ContentTypes.checkContentTypes(ALLOWED_CONTENT_TYPES, request.getContentType()); if (formParser.isMultipartContent(request)) { for (FormDataItem item : formParser.parse(request)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field // with field name as "request". It will contain the json request. Any further form // field or file item will not be parsed out, but will be exposed via getFormItem // method of RequestItem. if (!StringUtils.isEmpty(item.getContentType())) { ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES, item.getContentType()); } content = item.getAsString(); } else { formItems.put(item.getFieldName(), item); } } } else { content = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); } return content; }
private FormDataItem mockFormDataItem(String fieldName, String contentType, byte content[], boolean isFormField) throws IOException { InputStream in = new ByteArrayInputStream(content); FormDataItem formDataItem = mockControl.createMock(FormDataItem.class); expect(formDataItem.getContentType()).andStubReturn(contentType); expect(formDataItem.getSize()).andStubReturn((long) content.length); expect(formDataItem.get()).andStubReturn(content); expect(formDataItem.getAsString()).andStubReturn(new String(content)); expect(formDataItem.getFieldName()).andStubReturn(fieldName); expect(formDataItem.isFormField()).andStubReturn(isFormField); expect(formDataItem.getInputStream()).andStubReturn(in); return formDataItem; } }
private FormDataItem mockFormDataItem(String fieldName, String contentType, byte content[], boolean isFormField) throws IOException { InputStream in = new ByteArrayInputStream(content); FormDataItem formDataItem = mockControl.createMock(FormDataItem.class); expect(formDataItem.getContentType()).andStubReturn(contentType); expect(formDataItem.getSize()).andStubReturn((long) content.length); expect(formDataItem.get()).andStubReturn(content); expect(formDataItem.getAsString()).andStubReturn(new String(content)); expect(formDataItem.getFieldName()).andStubReturn(fieldName); expect(formDataItem.isFormField()).andStubReturn(isFormField); expect(formDataItem.getInputStream()).andStubReturn(in); return formDataItem; } }
private FormDataItem mockFormDataItem(String fieldName, String contentType, byte content[], boolean isFormField) throws IOException { InputStream in = new ByteArrayInputStream(content); FormDataItem formDataItem = mockControl.createMock(FormDataItem.class); expect(formDataItem.getContentType()).andStubReturn(contentType); expect(formDataItem.getSize()).andStubReturn((long) content.length); expect(formDataItem.get()).andStubReturn(content); expect(formDataItem.getAsString()).andStubReturn(new String(content)); expect(formDataItem.getFieldName()).andStubReturn(fieldName); expect(formDataItem.isFormField()).andStubReturn(isFormField); expect(formDataItem.getInputStream()).andStubReturn(in); return formDataItem; } }
private FormDataItem mockFormDataItem(String fieldName, String contentType, byte content[], boolean isFormField) throws IOException { InputStream in = new ByteArrayInputStream(content); FormDataItem formDataItem = mockControl.createMock(FormDataItem.class); expect(formDataItem.getContentType()).andStubReturn(contentType); expect(formDataItem.getSize()).andStubReturn((long) content.length); expect(formDataItem.get()).andStubReturn(content); expect(formDataItem.getAsString()).andStubReturn(new String(content)); expect(formDataItem.getFieldName()).andStubReturn(fieldName); expect(formDataItem.isFormField()).andStubReturn(isFormField); expect(formDataItem.getInputStream()).andStubReturn(in); return formDataItem; } }
private FormDataItem mockFormDataItem(String fieldName, String contentType, byte content[], boolean isFormField) throws IOException { InputStream in = new ByteArrayInputStream(content); FormDataItem formDataItem = mockControl.createMock(FormDataItem.class); expect(formDataItem.getContentType()).andStubReturn(contentType); expect(formDataItem.getSize()).andStubReturn((long) content.length); expect(formDataItem.get()).andStubReturn(content); expect(formDataItem.getAsString()).andStubReturn(new String(content)); expect(formDataItem.getFieldName()).andStubReturn(fieldName); expect(formDataItem.isFormField()).andStubReturn(isFormField); expect(formDataItem.getInputStream()).andStubReturn(in); return formDataItem; } }