Best SeLion code snippet using com.paypal.selion.grid.servlets.transfer.UploadRequestProcessor.initializeApacheCommonsSystem
Source:UploadRequestProcessor.java
...207 private ServletFileUpload servletFileUpload;208 private List<FileItem> fileItems;209 public MultipartUploadRequestProcessor(TransferContext transferContext) {210 super(transferContext);211 initializeApacheCommonsSystem();212 }213 public void populateManagedArtifactList() {214 LOGGER.entering();215 try {216 saveUploadedData();217 } catch (FileUploadException e) {218 throw new ArtifactUploadException(e.getMessage());219 }220 LOGGER.exiting();221 }222 private void saveUploadedData() throws FileUploadException {223 LOGGER.entering();224 int count = parseRequestAsFileItems();225 if (count > 1) {226 throw new ArtifactUploadException("Only one file supported for upload using multipart");227 }228 // Get parameters from headers and override it with request parameters.229 populateHeadersMap();230 for (FileItem fileItem : fileItems) {231 if (!fileItem.isFormField()) {232 UploadedArtifact uploadedArtifact = createUploadedArtifactUsing(transferContext.getHeadersMap(),233 fileItem.get());234 ManagedArtifact managedArtifact = repository.saveContents(uploadedArtifact);235 managedArtifactList.add(managedArtifact);236 }237 }238 LOGGER.exiting();239 }240 private int parseRequestAsFileItems() throws FileUploadException {241 int fileCount = 0;242 if (fileItems == null) {243 fileItems = servletFileUpload.parseRequest(httpServletRequest);244 }245 for (FileItem fileItem : fileItems) {246 if (!fileItem.isFormField()) {247 ++fileCount;248 }249 }250 return fileCount;251 }252 private void populateHeadersMap() {253 Map<String, String> headersMap = getRequestHeadersMap();254 Map<String, Boolean> artifactParams = managedArtifactRequestParameters.getParameters();255 for (FileItem fileItem : fileItems) {256 if (fileItem.isFormField()) {257 String parameter = fileItem.getFieldName().trim();258 if (artifactParams.containsKey(parameter)) {259 headersMap.put(parameter, fileItem.getString().trim());260 }261 } else {262 // TODO fix assumption that the only other parameter is the fileName263 headersMap.put(ManagedArtifact.ARTIFACT_FILE_NAME, isNotBlank(fileItem.getName().trim()));264 }265 }266 checkForRequiredParameters(headersMap);267 transferContext.setHeadersMap(headersMap);268 }269 // TODO See if this can be merged with ApplicationUploadRequestProcessor#checkRequiredParameters270 private void checkForRequiredParameters(Map<String, String> headersMap) {271 if (!headersMap.containsKey(ManagedArtifact.ARTIFACT_FILE_NAME)) {272 throw new ArtifactUploadException("Required input ["273 + ManagedArtifact.ARTIFACT_FILE_NAME + "] is missing or has no value");274 }275 for (String param : managedArtifactRequestParameters.getParameters().keySet()) {276 boolean isRequired = managedArtifactRequestParameters.isRequired(param);277 if (isRequired && StringUtils.isBlank(headersMap.get(param))) {278 throw new ArtifactUploadException("Required input [" + param279 + "] is missing or has no value");280 }281 }282 }283 private String isNotBlank(String fileName) {284 if (StringUtils.isBlank(fileName)) {285 throw new ArtifactUploadException("File name is empty in multipart upload request");286 }287 return fileName;288 }289 private void initializeApacheCommonsSystem() {290 DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();291 diskFileItemFactory.setSizeThreshold(MAX_FILE_SIZE);292 servletFileUpload = new ServletFileUpload(diskFileItemFactory);293 servletFileUpload.setFileSizeMax(MAX_FILE_SIZE);294 }295 }296}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!