How to use checkRequiredParameters method of com.paypal.selion.grid.servlets.transfer.UploadRequestProcessor class

Best SeLion code snippet using com.paypal.selion.grid.servlets.transfer.UploadRequestProcessor.checkRequiredParameters

Source:UploadRequestProcessor.java Github

copy

Full Screen

...161 ManagedArtifact managedArtifact = repository.saveContents(uploadedArtifact);162 managedArtifactList.add(managedArtifact);163 }164 private void populateHeadersMap() {165 checkRequiredParameters();166 transferContext.setHeadersMap(getRequestHeadersMap());167 }168 private void checkRequiredParameters() {169 if (StringUtils.isBlank(httpServletRequest.getHeader(ManagedArtifact.ARTIFACT_FILE_NAME))) {170 throw new ArtifactUploadException("Required header [" + ManagedArtifact.ARTIFACT_FILE_NAME171 + "] is missing or has no value");172 }173 for (String param : managedArtifactRequestParameters.getParameters().keySet()) {174 boolean isRequired = managedArtifactRequestParameters.isRequired(param);175 if (isRequired && StringUtils.isBlank(httpServletRequest.getHeader(param))) {176 throw new ArtifactUploadException("Required header [" + param + "] is missing or has no value");177 }178 }179 }180 private byte[] parseFileContents() throws IOException {181 int fileSize = httpServletRequest.getContentLength();182 if (fileSize <= 0) {183 throw new ArtifactUploadException("File is empty");184 }185 return IOUtils.toByteArray(httpServletRequest.getInputStream());186 }187 }188 /**189 * <code>MultipartUploadRequestProcessor</code> is an implementation of {@link AbstractUploadRequestProcessor} for190 * {@link DefaultManagedArtifact}. The implementation relies on 'commons-fileupload' library for parsing191 * 'multipart/form-data' type requests. Multiple artifact uploads are saved into repository and returned as a192 * {@link List} after processing. The clients pass 'folderName' is an optional parameter. The clients may choose to193 * pass them as either HTTP headers or request parameters: if using CURL then -F option (name=value) pair or -H194 * (HTTP headers). Additional HTTP headers or request parameters may apply and are defined by the195 * {@link ManagedArtifact} implementation. The implementation limits to only one file upload. Sample curl command196 * for uploading a multipart file197 * 198 * <pre>199 * {@code200 * curl -v -H 'folderName:<folderName>' -F file=@/path/tofile http://[hostname]:[port]/[upload-context-path]201 * }202 * </pre>203 */204 final class MultipartUploadRequestProcessor extends AbstractUploadRequestProcessor {205 private static final SeLionGridLogger LOGGER = SeLionGridLogger206 .getLogger(MultipartUploadRequestProcessor.class);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) {...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful