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

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

Source:UploadRequestProcessor.java Github

copy

Full Screen

...79 public List<ManagedArtifact> getUploadedData() {80 LOGGER.entering();81 SeLionGridLogger.getLogger(AbstractUploadRequestProcessor.class).entering();82 if (managedArtifactList.isEmpty()) {83 populateManagedArtifactList();84 }85 SeLionGridLogger.getLogger(AbstractUploadRequestProcessor.class).exiting(managedArtifactList);86 LOGGER.exiting(managedArtifactList);87 return managedArtifactList;88 }89 protected ManagedArtifact getManagedArtifactInstance() {90 if ((instance == null) && (repository != null)) {91 try {92 instance = repository.getConfiguredManagedArtifactClass().newInstance();93 } catch (InstantiationException | IllegalAccessException e) {94 throw new ArtifactUploadException(e.getCause().getMessage(), e);95 }96 }97 return instance;98 }99 protected UploadedArtifact createUploadedArtifactUsing(Map<String, String> headerMap,100 byte[] contents) {101 UploadedArtifactBuilder uploadedArtifactBuilder = new UploadedArtifactBuilder(contents);102 Map<String, Boolean> artifactParams = managedArtifactRequestParameters.getParameters();103 Map<String, String> meta = new HashMap<>();104 for (String inboundHeader : headerMap.keySet()) {105 if (artifactParams.containsKey(inboundHeader)) {106 meta.put(inboundHeader, headerMap.get(inboundHeader));107 }108 }109 uploadedArtifactBuilder.withMetaInfo(meta);110 return uploadedArtifactBuilder.build();111 }112 protected Map<String, String> getRequestHeadersMap() {113 Map<String, String> headersMap = new HashMap<>();114 Map<String, Boolean> artifactParams = managedArtifactRequestParameters.getParameters();115 for (String header : artifactParams.keySet()) {116 String value = httpServletRequest.getHeader(header);117 if (!StringUtils.isBlank(value)) {118 headersMap.put(header, value);119 }120 }121 return headersMap;122 }123 protected abstract void populateManagedArtifactList();124 }125 /**126 * <code>ApplicationUploadRequestProcessor</code> is an implementation of {@link AbstractUploadRequestProcessor} for127 * {@link ManagedArtifact}s. The implementation is native using streams for parsing128 * 'application/x-www-form-urlencoded' type requests. Artifact upload are saved into repository and returned as a129 * {@link List} after processing. Since the file name may not be deduced from such requests the clients MUST pass130 * the HTTP header 'fileName'. HTTP header 'folderName' is optional parameter. Additional HTTP headers may apply and131 * are defined by the {@link ManagedArtifact} implementation.132 * 133 * Sample curl command for uploading a form-urlencoded file134 * 135 * <pre>136 * {@code137 * curl -v -H 'filename:<fileName>' --data-binary @/path/tofile http://[hostname]:[port]/[upload-context-path] 138 * curl -v -H 'filename:<fileName>' -H 'folderName:<folderName>' --data-binary @/path/tofile http://[hostname]:[port]/[upload-context-path]139 * }140 * </pre>141 */142 final class ApplicationUploadRequestProcessor extends AbstractUploadRequestProcessor {143 private static final SeLionGridLogger LOGGER = SeLionGridLogger144 .getLogger(ApplicationUploadRequestProcessor.class);145 public ApplicationUploadRequestProcessor(TransferContext transferContext) {146 super(transferContext);147 }148 public void populateManagedArtifactList() {149 LOGGER.entering();150 try {151 saveUploadedData();152 } catch (IOException e) {153 throw new ArtifactUploadException("IOException in parsing file contents", e.getCause());154 }155 LOGGER.exiting();156 }157 private void saveUploadedData() throws IOException {158 populateHeadersMap();159 byte[] contents = parseFileContents();160 UploadedArtifact uploadedArtifact = createUploadedArtifactUsing(transferContext.getHeadersMap(), contents);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 }...

Full Screen

Full Screen

populateManagedArtifactList

Using AI Code Generation

copy

Full Screen

1import java.io.BufferedReader;2import java.io.File;3import java.io.FileReader;4import java.io.FileWriter;5import java.io.IOException;6import java.util.HashMap;7import java.util.Map;8import com.paypal.selion.grid.servlets.transfer.UploadRequestProcessor;9public class GetArtifacts {10 public static void main(String[] args) throws IOException {11 String path = "C:\\Users\\username\\Desktop\\artifacts";12 File dir = new File(path);13 File[] files = dir.listFiles();14 Map<String, String> map = new HashMap<String, String>();15 File artifacts = new File(path + "\\artifacts.txt");16 File md5s = new File(path + "\\md5s.txt");17 FileWriter artifactsWriter = new FileWriter(artifacts);18 FileWriter md5sWriter = new FileWriter(md5s);19 for (File file : files) {20 String fileName = file.getName();21 String md5 = UploadRequestProcessor.getMd5(file);22 map.put(fileName, md5);23 }24 for (Map.Entry<String, String> entry : map.entrySet()) {25 String fileName = entry.getKey();26 String md5 = entry.getValue();27 artifactsWriter.write(fileName + System.getProperty("line.separator"));

Full Screen

Full Screen

populateManagedArtifactList

Using AI Code Generation

copy

Full Screen

1List<Artifact> artifacts = new ArrayList<Artifact>();2artifacts.add(new Artifact("TestArtifact1", "TestArtifact1"));3artifacts.add(new Artifact("TestArtifact2", "TestArtifact2"));4artifacts.add(new Artifact("TestArtifact3", "TestArtifact3"));5UploadRequestProcessor uploadRequestProcessor = new UploadRequestProcessor();6uploadRequestProcessor.populateManagedArtifactList(request, artifacts);7artifacts = (List<Artifact>) request.getAttribute("artifacts");8Assert.assertEquals(artifacts.size(), 3);9Assert.assertEquals(artifacts.get(0).getArtifactName(), "TestArtifact1");10Assert.assertEquals(artifacts.get(0).getArtifactLocation(), "TestArtifact1");11Assert.assertEquals(artifacts.get(1).getArtifactName(), "TestArtifact2");12Assert.assertEquals(artifacts.get(1).getArtifactLocation(), "TestArtifact2");13Assert.assertEquals(artifacts.get(2).getArtifactName(), "TestArtifact3");14Assert.assertEquals(artifacts.get(2).getArtifactLocation(), "TestArtifact3");15artifacts = new ArrayList<Artifact>();16artifacts.add(new Artifact("TestArtifact1", "TestArtifact1"));17artifacts.add(new Artifact("TestArtifact2", "TestArtifact2"));18artifacts.add(new Artifact("TestArtifact3", "TestArtifact3"));19request = new MockHttpServletRequest();20uploadRequestProcessor.populateManagedArtifactList(request, artifacts);21artifacts = (List<Artifact>) request.getAttribute("artifacts");22Assert.assertEquals(artifacts.size(),

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