本文整理汇总了Java中org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest类的典型用法代码示例。如果您正苦于以下问题:Java DefaultMultipartHttpServletRequest类的具体用法?Java DefaultMultipartHttpServletRequest怎么用?Java DefaultMultipartHttpServletRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultMultipartHttpServletRequest类属于org.springframework.web.multipart.support包,在下文中一共展示了DefaultMultipartHttpServletRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upload
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; //导入依赖的package包/类
@PostMapping("file")
public String upload(@RequestParam("file") MultipartFile file, MultipartRequest multipartRequest) {
System.out.println(file);
DefaultMultipartHttpServletRequest request = (DefaultMultipartHttpServletRequest) multipartRequest;
String fileName = request.getParameter("fileName");
StringBuilder stringBuilder = new StringBuilder("fileName" + " : " + fileName);
try {
InputStream inputStream = file.getInputStream();
InputStreamReader in = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(in);
bufferedReader.lines().forEach(stringBuilder::append);
IOUtils.closeQuietly(inputStream, in, bufferedReader);
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
示例2: addImage
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; //导入依赖的package包/类
@RequestMapping(value = IMAGES, method = POST)
public String addImage(@RequestParam("image") MultipartFile file, DefaultMultipartHttpServletRequest request, Locale locale) throws IOException {
// NOTE: Checking user rights and CSRF-Token needs to be done here because HttpUserService gains
// NOTE org.eclipse.jetty.server.Request which is not able to handle parameters at multipartrequests
User currentUser = userService.getCurrentUser(false);
if (!currentUser.isOm()) {
throw new AccessDeniedException("Om rights required");
}
userService.verifyCSRFToken(request);
imageFinder.validateAndSaveFile(file);
return redirectWithMessage(request.getHeader("Referer"), RequestMessage.EDITOR_UPLOAD_IMAGE, request);
}
示例3: runReporting
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; //导入依赖的package包/类
@RequestMapping(value = "/runReporting", method = RequestMethod.POST)
@ResponseBody
public void runReporting(final HttpServletRequest req, final HttpServletResponse resp) {
logger.info("Start processing the run reporting web service");
String respStr = WebServiceUtil.EMPTY_STRING;
try {
if (req instanceof DefaultMultipartHttpServletRequest) {
InputStream instream = null;
final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) req;
final MultiValueMap<String, MultipartFile> fileMap = multiPartRequest.getMultiFileMap();
for (final String fileName : fileMap.keySet()) {
final MultipartFile multiPartFile = multiPartRequest.getFile(fileName);
instream = multiPartFile.getInputStream();
final Source source = XMLUtil.createSourceFromStream(instream);
final ReportingOptions option = (ReportingOptions) batchSchemaDao.getJAXB2Template().getJaxb2Marshaller()
.unmarshal(source);
final String installerPath = option.getInstallerPath();
if (installerPath == null || installerPath.isEmpty() || !installerPath.toLowerCase().contains("build.xml")) {
respStr = "Improper input to server. Installer path not specified or it does not contain the build.xml path.";
} else {
logger.info("synchronizing the database");
reportingService.syncDatabase(installerPath);
break;
}
}
} else {
respStr = "Improper input to server. Expected multipart request. Returning without processing the results.";
}
} catch (final XmlMappingException xmle) {
respStr = "Error in mapping input XML in the desired format. Please send it in the specified format. Detailed exception is "
+ xmle;
} catch (final Exception e) {
respStr = "Internal Server error.Please check logs for further details." + e;
}
if (!respStr.isEmpty()) {
try {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, respStr);
} catch (final IOException ioe) {
}
}
}
示例4: runReporting
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; //导入依赖的package包/类
/**
* To run Reporting.
* @param req {@link HttpServletRequest}
* @param resp {@link HttpServletResponse}
*/
@RequestMapping(value = "/runReporting", method = RequestMethod.POST)
@ResponseBody
public void runReporting(final HttpServletRequest req, final HttpServletResponse resp) {
LOGGER.info("Start processing the run reporting web service");
String respStr = WebServiceUtil.EMPTY_STRING;
try {
if (req instanceof DefaultMultipartHttpServletRequest) {
InputStream instream = null;
final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) req;
final MultiValueMap<String, MultipartFile> fileMap = multiPartRequest.getMultiFileMap();
for (final String fileName : fileMap.keySet()) {
final MultipartFile multiPartFile = multiPartRequest.getFile(fileName);
instream = multiPartFile.getInputStream();
final Source source = XMLUtil.createSourceFromStream(instream);
final ReportingOptions option = (ReportingOptions) batchSchemaDao.getJAXB2Template().getJaxb2Marshaller()
.unmarshal(source);
final String installerPath = option.getInstallerPath();
if (installerPath == null || installerPath.isEmpty()
|| !installerPath.toLowerCase(Locale.getDefault()).contains(WebServiceUtil.BUILD_XML)) {
respStr = "Improper input to server. Installer path not specified or it does not contain the build.xml path.";
} else {
LOGGER.info("synchronizing the database");
reportingService.syncDatabase(installerPath);
break;
}
}
} else {
respStr = IMPROPER_INPUT_TO_SERVER;
LOGGER.error(SERVER_ERROR_MSG + respStr);
}
} catch (final XmlMappingException xmle) {
respStr = ERROR_IN_MAPPING_INPUT + xmle;
LOGGER.error(SERVER_ERROR_MSG + respStr);
} catch (final Exception e) {
respStr = INTERNAL_SERVER_ERROR + e;
LOGGER.error(SERVER_ERROR_MSG + respStr);
}
if (!respStr.isEmpty()) {
try {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, respStr);
LOGGER.error(SERVER_ERROR_MSG + respStr);
} catch (final IOException ioe) {
LOGGER.info(ERROR_WHILE_SENDING_ERROR_RESPONSE_TO_CLIENT + ioe, ioe);
}
}
}
示例5: validateInputAndPerformExtraction
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; //导入依赖的package包/类
private String validateInputAndPerformExtraction(final HttpServletRequest req, final HttpServletResponse resp,
final String respStr, final String workingDir, final DefaultMultipartHttpServletRequest multiPartRequest,
final Set<String> fileNameSet, final String batchClassIdentifier, final String documentType, final String hocrFileName)
throws IOException, FileNotFoundException, DCMAException {
InputStream instream;
OutputStream outStream;
String respStrLocal = respStr;
try {
BatchClass batchClass = bcService.getBatchClassByIdentifier(batchClassIdentifier);
if (batchClass == null) {
respStrLocal = "Please enter valid batch class identifier";
} else {
Set<String> loggedInUserRole = getUserRoles(req);
if (!isBatchClassViewableToUser(batchClassIdentifier, loggedInUserRole, isSuperAdmin(req))) {
respStrLocal = USER_NOT_AUTHORIZED_TO_VIEW_THE_BATCH_CLASS + batchClassIdentifier;
LOGGER.error(SERVER_ERROR_MSG + respStrLocal);
} else {
BatchPlugin regularRegexPlugin = batchClassPPService.getPluginProperties(batchClassIdentifier,
"REGULAR_REGEX_EXTRACTION");
if (regularRegexPlugin == null || regularRegexPlugin.getPropertiesSize() == 0) {
respStrLocal = "Fuzzy DB plugin is not configured for batch class : " + batchClassIdentifier
+ " . Please select proper batch class";
LOGGER.error(SERVER_ERROR_MSG + respStrLocal);
}
for (final String fileName : fileNameSet) {
if (fileName.equalsIgnoreCase(hocrFileName)) {
LOGGER.info("hocr file name found : " + hocrFileName);
final MultipartFile multiPartFile = multiPartRequest.getFile(fileName);
instream = multiPartFile.getInputStream();
final File file = new File(workingDir + File.separator + fileName);
outStream = new FileOutputStream(file);
final byte[] buf = new byte[WebServiceUtil.bufferSize];
int len = instream.read(buf);
while (len > 0) {
outStream.write(buf, 0, len);
len = instream.read(buf);
}
break;
}
}
final File hocrFile = new File(workingDir + File.separator + hocrFileName);
if (hocrFile.exists()) {
respStrLocal = performRegexExtraction(resp, workingDir, hocrFile.getAbsolutePath(), batchClassIdentifier,
documentType);
}
}
}
} catch (Exception exception) {
LOGGER.error("Error occurred while extracting fields using regular regex extarction.");
throw new DCMAException(exception.getMessage(), exception);
}
return respStrLocal;
}