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

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

Source:UploadRequestProcessor.java Github

copy

Full Screen

...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 }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()) {...

Full Screen

Full Screen

createUploadedArtifactUsing

Using AI Code Generation

copy

Full Screen

1File file = new File("C:\\Users\\test\\Documents\\test.txt");2String url = UploadRequestProcessor.createUploadedArtifactUsing(file);3File file = DownloadRequestProcessor.getArtifactUsing(url, "C:\\Users\\test\\Documents\\test.txt");4File file = new File("C:\\Users\\test\\Documents\\test.txt");5String url = UploadRequestProcessor.createUploadedArtifactUsing(file);6File file = DownloadRequestProcessor.getArtifactUsing(url, "C:\\Users\\test\\Documents\\test.txt");7File file = new File("C:\\Users\\test\\Documents\\test.txt");8String url = UploadRequestProcessor.createUploadedArtifactUsing(file);

Full Screen

Full Screen

createUploadedArtifactUsing

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.transfer.UploadRequestProcessor;2import org.openqa.selenium.remote.RemoteWebDriver;3import java.io.File;4import java.io.IOException;5import java.net.URL;6import com.paypal.selion.platform.grid.Grid;7import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;8import com.paypal.selion.platform.grid.browsercapabilities.MobileCapabilityBuilder;9import com.paypal.selion.platform.grid.browsercapabilities.MobilePlatform;10public class UploadFileToNode {11 public static void main(String[] args) throws IOException {12 File file = new File("C:\\Users\\test\\Desktop\\test.txt");13 RemoteWebDriver driver = new RemoteWebDriver(url, new DefaultCapabilitiesBuilder().getCapabilities());14 String sessionID = driver.getSessionId().toString();15 UploadRequestProcessor.createUploadedArtifactUsing(sessionID, file);16 driver.quit();17 }18}

Full Screen

Full Screen

createUploadedArtifactUsing

Using AI Code Generation

copy

Full Screen

1public void createUploadedArtifactUsing() throws Exception {2 String artifactName = "selenium-server-standalone-2.39.0.jar";3 String artifactPath = "src/test/resources/artifacts/" + artifactName;4 String artifactType = "jar";5 String artifactDescription = "Selenium Server Standalone";6 String artifactCategory = "SELENIUM_SERVER";7 String artifactVersion = "2.39.0";8 String artifactGroup = "org.seleniumhq.selenium";9 String artifactRepo = "selenium-repo";10 String artifactRepoUsername = "admin";11 String artifactRepoPassword = "admin123";12 String artifactRepoType = "maven2";13 String artifactRepoSnapshot = "true";14 String artifactRepoReleases = "true";15 String artifactRepoChecksum = "true";16 String artifactRepoLayout = "default";17 String artifactRepoIndex = "true";18 String artifactRepoIndexDir = "index";19 String artifactRepoIndexUsername = "admin";20 String artifactRepoIndexPassword = "admin123";21 String artifactRepoIndexType = "maven2";22 String artifactRepoIndexSnapshot = "true";23 String artifactRepoIndexReleases = "true";24 String artifactRepoIndexChecksum = "true";25 String artifactRepoIndexLayout = "default";26 String artifactRepoIndexIndex = "true";27 String artifactRepoIndexIndexDir = "index";28 String artifactRepoIndexIndexUsername = "admin";29 String artifactRepoIndexIndexPassword = "admin123";30 String artifactRepoIndexIndexType = "maven2";31 String artifactRepoIndexIndexSnapshot = "true";32 String artifactRepoIndexIndexReleases = "true";33 String artifactRepoIndexIndexChecksum = "true";34 String artifactRepoIndexIndexLayout = "default";35 String artifactRepoIndexIndexIndex = "true";36 String artifactRepoIndexIndexIndexDir = "index";

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