How to use UploadedArtifact class of com.paypal.selion.grid.servlets.transfer package

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

Source:UploadRequestProcessor.java Github

copy

Full Screen

...25import org.apache.commons.fileupload.servlet.ServletFileUpload;26import org.apache.commons.io.IOUtils;27import org.apache.commons.lang.StringUtils;28import com.paypal.selion.grid.servlets.transfer.ManagedArtifact.RequestParameters;29import com.paypal.selion.grid.servlets.transfer.UploadedArtifact.UploadedArtifactBuilder;30import com.paypal.selion.logging.SeLionGridLogger;31import com.paypal.selion.utils.ConfigParser;32/**33 * <code>UploadRequestProcessor</code> processes any HTTP upload request for any type that extends34 * {@link ManagedArtifact}.35 */36public interface UploadRequestProcessor {37 /**38 * Content Type for multipart form-data request.39 */40 String MULTIPART_CONTENT_TYPE = "multipart/form-data";41 /**42 * Content Type for application form-url-encoded request.43 */44 String APPLICATION_URLENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded";45 /**46 * Max file size configuration property retrieved from SeLionConfig file.47 */48 String MAX_FILE_CONFIG_PROPERTY = "artifactMaxFileSize";49 /**50 * @return a {@link List} of {@link ManagedArtifact} which represent items on the {@link ManagedArtifactRepository}51 */52 List<ManagedArtifact> getUploadedData();53 /**54 * <code>AbstractUploadRequestProcessor</code> is abstract super class for concrete implementations that work on55 * types of {@link ManagedArtifact}. The class initializes a {@link ServerRepository} of {@link ManagedArtifact} to56 * use during processing.57 */58 abstract class AbstractUploadRequestProcessor implements UploadRequestProcessor {59 private static final SeLionGridLogger LOGGER = SeLionGridLogger.getLogger(AbstractUploadRequestProcessor.class);60 /**61 * Maximum size permitted for a single upload artifact.62 */63 public final int MAX_FILE_SIZE;64 protected TransferContext transferContext;65 protected HttpServletRequest httpServletRequest;66 protected ServerRepository repository;67 protected List<ManagedArtifact> managedArtifactList;68 protected RequestParameters managedArtifactRequestParameters;69 private ManagedArtifact instance;70 protected AbstractUploadRequestProcessor(TransferContext transferContext) {71 super();72 MAX_FILE_SIZE = ConfigParser.parse().getInt(MAX_FILE_CONFIG_PROPERTY);73 this.transferContext = transferContext;74 this.httpServletRequest = transferContext.getHttpServletRequest();75 repository = ManagedArtifactRepository.getInstance();76 managedArtifactRequestParameters = getManagedArtifactInstance().getRequestParameters();77 managedArtifactList = new ArrayList<>();78 }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 }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

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;2public class ArtifactTest {3 public static void main(String[] args) {4 UploadedArtifact artifact = new UploadedArtifact("artifactName", "artifactPath");5 System.out.println(artifact.getArtifactName());6 System.out.println(artifact.getArtifactPath());7 }8}9import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;10public class ArtifactTest {11 public static void main(String[] args) {12 UploadedArtifact artifact = new UploadedArtifact("artifactName", "artifactPath");13 System.out.println(artifact.getArtifactName());14 System.out.println(artifact.getArtifactPath());15 }16}17import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;18public class ArtifactTest {19 public static void main(String[] args) {20 UploadedArtifact artifact = new UploadedArtifact("artifactName", "artifactPath");21 System.out.println(artifact.getArtifactName());22 System.out.println(artifact.getArtifactPath());23 }24}25import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;26public class ArtifactTest {27 public static void main(String[] args) {28 UploadedArtifact artifact = new UploadedArtifact("artifactName", "artifactPath");29 System.out.println(artifact.getArtifactName());30 System.out.println(artifact.getArtifactPath());31 }32}33import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;34public class ArtifactTest {35 public static void main(String[]

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;2import java.io.File;3public class FileUploadDemo {4public static void main(String[] args) {5UploadedArtifact artifact = new UploadedArtifact(new File("C:\\test.txt"));6System.out.println(artifact.getArtifactName());7System.out.println(artifact.getArtifactSize());8System.out.println(artifact.getArtifactType());9System.out.println(artifact.getArtifactPath());10}11}12import com.paypal.selion.grid.servlets.transfer.FileUploadHelper;13import java.io.File;14public class FileUploadDemo {15public static void main(String[] args) {16FileUploadHelper helper = new FileUploadHelper();17helper.uploadFile(new File("C:\\test.txt"));18}19}20import com.paypal.selion.grid.servlets.transfer.FileUploadHelper;21import java.io.File;22public class FileUploadDemo {23public static void main(String[] args) {24FileUploadHelper helper = new FileUploadHelper();25UploadedArtifact artifact = helper.uploadFileAndGetArtifact(new File("C:\\test.txt"));26System.out.println(artifact.getArtifactName());27System.out.println(artifact.getArtifactSize());28System.out.println(artifact.getArtifactType());29System.out.println(artifact.getArtifactPath());30}31}32File file = new File("C:\\test.txt");33Assert.assertTrue(file.exists());34Assert.assertTrue(file.isFile());35Assert.assertTrue(file.canRead());36Assert.assertEquals(4, file.length());

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;2import java.io.File;3import org.openqa.selenium.remote.DesiredCapabilities;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.testng.annotations.Test;10import com.paypal.selion.annotations.WebTest;11import com.paypal.selion.platform.grid.Grid;12import com.paypal.selion.platform.grid.browsercapabilities.DefaultCapabilitiesBuilder;13import com.paypal.selion.platform.utilities.WebDriverWaitUtils;14import com.paypal.selion.reports.runtime.SeLionReporter;15import com.paypal.selion.reports.runtime.SeLionReporter.logLevel;16import com.paypal.selion.testcomponents.BasicPageImpl;17import com.paypal.selion.testcomponents.HtmlPage;18import com.paypal.selion.testcomponents.SeLionSauceLabsPage;19import com.paypal.selion.testcomponents.SeLionTestPage;20import com.paypal.selion.testcomponents.SeLionTestPageImpl;21import com.paypal.selion.testcomponents.SeLionTestPageImpl2;22import com.paypal.selion.testcomponents.SeLionTestPageImpl3;23import com.paypal.selion.testcomponents.SeLionTestPageImpl4;24import com.paypal.selion.testcomponents.SeLionTestPageImpl5;25import com.paypal.selion.testcomponents.SeLionTestPageImpl6;26import com.paypal.selion.testcomponents.SeLionTestPageImpl7;27import com.paypal.selion.testcomponents.SeLionTestPageImpl8;28import com.paypal.selion.testcomponents.SeLionTestPageImpl9;29import com.paypal.selion.testcomponents.SeLionTestPageImpl10;30import com.paypal.selion.testcomponents.SeLionTestPageImpl11;31import com.paypal.selion.testcomponents.SeLionTestPageImpl12;32import com.paypal.selion.testcomponents.SeLionTestPageImpl13;33import com.paypal.selion.testcomponents.SeLionTestPageImpl14;34import com.paypal.selion.testcomponents.SeLionTestPageImpl15;35import com.paypal.selion.testcomponents.SeLionTestPageImpl16;36import com.paypal.selion.testcomponents.SeLionTestPageImpl17;37import com.paypal.selion.testcomponents.SeLionTestPageImpl18

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;2UploadedArtifact artifact = new UploadedArtifact();3artifact.setFileName("sampleFile.png");4artifact.setFileLocation("C:\\sampleFile.png");5artifact.setFileType("image/png");6artifact.setFileContent("Base64 encoded file content");7artifact.setFileTime("2015-01-01 00:00:00");8artifact.setFileHash("SHA-1 hash of the file content");9artifact.setFileChecksum("MD5 checksum of the file content");10artifact.setFileOwner("username of the user who uploaded the file");11artifact.setFileGroup("groupname of the user who uploaded the file");12artifact.setFilePermissions("644");13artifact.setFileDescription("Description of the file");14artifact.setFileTags("tag1,tag2,tag3");15artifact.setFileAttributes("attribute1,attribute2,attribute3");16artifact.setFileHidden(false);17artifact.setFileLocked(false);18artifact.setFileDownloadCount(0);19artifact.setFileExpirationDate("2015-01-01 00:00:00");20artifact.setFileExpirationAction("delete");21artifact.setFileExpirationActionParameters("param1,param2,param3");22artifact.setFileExpirationActionTime("2015-01-01 00:00:00");23artifact.setFileExpirationActionStatus("success");24artifact.setFileExpirationActionMessage("File deleted successfully");25artifact.setFileExpirationActionUser("username of the user who deleted the file");26artifact.setFileExpirationActionUserIP("IP address of the user who deleted the file");27artifact.setFileExpirationActionUserAgent("User Agent of the user who deleted the file");28artifact.setFileExpirationActionUserHost("Host of the user who deleted the file");29artifact.setFileExpirationActionUserOS("OS of the user who deleted the file");30artifact.setFileExpirationActionUserBrowser("Browser of the user who deleted the file");31artifact.setFileExpirationActionUserBrowserVersion("Browser version of the user who deleted the file");32artifact.setFileExpirationActionUserReferer("Referer of the user who deleted the file");33artifact.setFileExpirationActionUserRefererHost("Referer host of the user who deleted the file");34artifact.setFileExpirationActionUserRefererPath("Referer path

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact();2artifact.setFileName("test.txt");3artifact.setFileContent("test content".getBytes());4artifact.setMimeType("text/plain");5artifact.setUploadTime(new Date().getTime());6artifact.setUploadedBy("test");7artifact.setFileSize(11);8artifact.setArtifactUUID(UUID.randomUUID().toString());9artifact.setArtifactType(ArtifactType.LOG);10artifact.setArtifactCategory(ArtifactCategory.SERVER);11artifact.setArtifactOwner("test");12artifact.setArtifactDescription("test");13artifact.setArtifactTags(new String[]{"test"});14artifact.setArtifactName("test");15Artifact artifact = new Artifact();16artifact.setFileName("test.txt");17artifact.setFileContent("test content".getBytes());18artifact.setMimeType("text/plain");19artifact.setUploadTime(new Date().getTime());20artifact.setUploadedBy("test");21artifact.setFileSize(11);22artifact.setArtifactUUID(UUID.randomUUID().toString());23artifact.setArtifactType(ArtifactType.LOG);24artifact.setArtifactCategory(ArtifactCategory.SERVER);25artifact.setArtifactOwner("test");26artifact.setArtifactDescription("test");27artifact.setArtifactTags(new String[]{"test"});28artifact.setArtifactName("test");29artifact.setArtifactPath("/test/test.txt");30ArtifactManager manager = new ArtifactManager();31manager.uploadArtifact(artifact);32ArtifactManager manager = new ArtifactManager();33manager.uploadArtifact(artifact, "test");34ArtifactManager manager = new ArtifactManager();35manager.uploadArtifact(artifact, "test", "test");36ArtifactManager manager = new ArtifactManager();37manager.uploadArtifact(artifact, "test", "test", "test");38ArtifactManager manager = new ArtifactManager();39manager.uploadArtifact(artifact, "test", "test", "test", "test");40ArtifactManager manager = new ArtifactManager();41manager.uploadArtifact(artifact, "test", "test", "test", "test", "test");

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact("C:\\Users\\xyz\\Desktop\\test.txt");2UploadedArtifact artifact = new UploadedArtifact("test.txt");3File file = new File("C:\\Users\\xyz\\Desktop\\test.txt");4UploadedArtifact artifact = new UploadedArtifact(file);5String downloadUrl = artifact.getDownloadUrl();6URL url = new URL(downloadUrl);7URLConnection connection = url.openConnection();8connection.setDoOutput(true);9InputStream inputStream = connection.getInputStream();10FileOutputStream outputStream = new FileOutputStream(file);11byte[] buffer = new byte[4096];12int length;13while ((length = inputStream.read(buffer)) > 0) {14 outputStream.write(buffer, 0, length);15}16inputStream.close();17outputStream.close();18java.io.FileNotFoundException: C:\Users\xyz\Desktop\test.txt (The system cannot find the path specified)19URL url = new URL(downloadUrl);20FileUtils.copyURLToFile(url, file);21java.io.FileNotFoundException: C:\Users\xyz\Desktop\test.txt (The system cannot find the path specified)22URL url = new URL(downloadUrl);23URLConnection connection = url.openConnection();24connection.setDoOutput(true);25InputStream inputStream = connection.getInputStream();26FileUtils.copyInputStreamToFile(inputStream, file);27java.io.FileNotFoundException: C:\Users\xyz\Desktop\test.txt (The system cannot find the path specified)28URL url = new URL(downloadUrl);29URLConnection connection = url.openConnection();30connection.setDoOutput(true);31InputStream inputStream = connection.getInputStream();32FileUtils.copyInputStreamToFile(inputStream, file);33java.io.FileNotFoundException: C:\Users\xyz\Desktop\test.txt (The system cannot find the path specified)34URL url = new URL(downloadUrl);35URLConnection connection = url.openConnection();36connection.setDoOutput(true);37InputStream inputStream = connection.getInputStream();38FileUtils.copyInputStreamToFile(inputStream, file);39java.io.FileNotFoundException: C:\Users\xyz\Desktop\test.txt (The system cannot find

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\\Users\\user\\Desktop\\test.txt");2uploadedArtifact.downloadFile("C:\\Users\\user\\Desktop\\test.txt");3uploadedArtifact.deleteFile();4UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\\Users\\user\\Desktop\\test.txt");5uploadedArtifact.downloadFile("C:\\Users\\user\\Desktop\\test.txt");6uploadedArtifact.deleteFile();7UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\\Users\\user\\Desktop\\test.txt");8uploadedArtifact.downloadFile("C:\\Users\\user\\Desktop\\test.txt");9uploadedArtifact.deleteFile();10UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\Users\user\Desktop\test.txt");11uploadedArtifact.downloadFile("C:\Users\user\Desktop\test.txt");12uploadedArtifact.deleteFile();13UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\Users\user\Desktop\test.txt");14uploadedArtifact.downloadFile("C:\Users\user\Desktop\test.txt");15uploadedArtifact.deleteFile();16UploadedArtifact uploadedArtifact = new UploadedArtifact("C:\Users\user\Desktop\test.txt");17uploadedArtifact.downloadFile("C:\Users\user\Desktop\test.txt");18uploadedArtifact.deleteFile();

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.

Run SeLion automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful