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

Best SeLion code snippet using com.paypal.selion.grid.servlets.transfer.UploadedArtifact.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;2import com.paypal.selion.platform.grid.Grid;3import com.paypal.selion.platform.grid.GridManager;4import java.io.File;5import java.io.IOException;6public class UploadedArtifactExample {7 public static void main(String[] args) throws IOException {8 Grid grid = GridManager.getThreadLocalGrid();9 UploadedArtifact artifact = new UploadedArtifact(grid.getWebDriver(), new File("C:\\test\\test.txt"));10 String url = artifact.getUrl();11 System.out.println(url);12 }13}14import com.paypal.selion.grid.servlets.transfer.DownloadedArtifact;15import com.paypal.selion.platform.grid.Grid;16import com.paypal.selion.platform.grid.GridManager;17import java.io.File;18import java.io.IOException;19public class DownloadedArtifactExample {20 public static void main(String[] args) throws IOException {21 Grid grid = GridManager.getThreadLocalGrid();22 DownloadedArtifact artifact = new DownloadedArtifact(grid.getWebDriver(), new File("C:\\test\\test.txt"));23 String url = artifact.getUrl();24 System.out.println(url);25 }26}27import com.paypal.selion.grid.servlets.transfer.UploadedArtifact;28import com.paypal.selion.platform.grid.Grid;29import com.paypal.selion.platform.grid.GridManager;30import java.io.File;31import java.io.IOException;32public class UploadedArtifactExample {33 public static void main(String[] args) throws IOException {34 Grid grid = GridManager.getThreadLocalGrid();35 UploadedArtifact artifact = new UploadedArtifact(grid.getWebDriver(), new File("C:\\test\\test.txt"));36 String url = artifact.getUrl();37 System.out.println(url);38 }39}40import com.paypal.selion.grid.servlets.transfer.DownloadedArtifact;41import com.paypal.selion.platform.grid.Grid;42import com.paypal.selion.platform.grid.GridManager;43import java.io.File;44import java.io.IOException;45public class DownloadedArtifactExample {46 public static void main(String[] args) throws IOException {47 Grid grid = GridManager.getThreadLocalGrid();48 DownloadedArtifact artifact = new DownloadedArtifact(grid.getWebDriver(), new File

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact ( "artifactId" );2UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" );3UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" );4UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" );5UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" , "artifactDescription" );6UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" , "artifactDescription" , "artifactLocation" );7UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" , "artifactDescription" , "artifactLocation" , "artifactDate" );8UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" , "artifactDescription" , "artifactLocation" , "artifactDate" , "artifactTags" );9UploadedArtifact artifact = new UploadedArtifact ( "artifactId" , "artifactName" , "artifactType" , "artifactSize" , "artifactDescription" , "artifactLocation" , "artifactDate" , "artifactTags" , "artifactOwner" );

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact();2String artifactPath = artifact.getArtifactPath("artifactName");3String artifactPath = artifact.getArtifactPath("artifactName", "artifactType");4String artifactPath = artifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");5UploadedArtifact artifact = new UploadedArtifact();6String artifactPath = artifact.getArtifactPath("artifactName");7String artifactPath = artifact.getArtifactPath("artifactName", "artifactType");8String artifactPath = artifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");9String artifactPath = UploadedArtifact.getArtifactPath("artifactName");10String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType");11String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");12String artifactPath = UploadedArtifact.getArtifactPath("artifactName");13String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType");14String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");15UploadedArtifact artifact = new UploadedArtifact();16String artifactPath = artifact.getArtifactPath("artifactName");17String artifactPath = artifact.getArtifactPath("artifactName", "artifactType");18String artifactPath = artifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");19UploadedArtifact artifact = new UploadedArtifact();20String artifactPath = artifact.getArtifactPath("artifactName");21String artifactPath = artifact.getArtifactPath("artifactName", "artifactType");22String artifactPath = artifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");23String artifactPath = UploadedArtifact.getArtifactPath("artifactName");24String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType");25String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");26String artifactPath = UploadedArtifact.getArtifactPath("artifactName");27String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType");28String artifactPath = UploadedArtifact.getArtifactPath("artifactName", "artifactType", "artifactVersion");

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact();2artifact.setFileName("fileName");3artifact.setArtifactName("artifactName");4artifact.setArtifactType("artifactType");5artifact.setArtifactContent("artifactContent");6artifact.setArtifactContentType("artifactContentType");7artifact.setArtifactContentEncoding("artifactContentEncoding");8artifact.setArtifactContentLength(0);9artifact.setArtifactContentDisposition("artifactContentDisposition");10artifact.setArtifactContentTransferEncoding("artifactContentTransferEncoding");11artifact.setArtifactContentMD5("artifactContentMD5");12artifact.setArtifactLastModified(new Date());13artifact.setArtifactLastModifiedBy("artifactLastModifiedBy");14artifact.setArtifactLastModifiedByHost("artifactLastModifiedByHost");15artifact.setArtifactLastModifiedByIP("artifactLastModifiedByIP");16artifact.setArtifactLastModifiedByOS("artifactLastModifiedByOS");17artifact.setArtifactLastModifiedByOSVersion("artifactLastModifiedByOSVersion");18artifact.setArtifactLastModifiedByJavaVersion("artifactLastModifiedByJavaVersion");19UploadedArtifact artifact = new UploadedArtifact();20artifact.setFileName("fileName");21artifact.setArtifactName("artifactName");22artifact.setArtifactType("artifactType");23artifact.setArtifactContent("artifactContent");24artifact.setArtifactContentType("artifactContentType");25artifact.setArtifactContentEncoding("artifactContentEncoding");26artifact.setArtifactContentLength(0);27artifact.setArtifactContentDisposition("artifactContentDisposition");28artifact.setArtifactContentTransferEncoding("artifactContentTransferEncoding");29artifact.setArtifactContentMD5("artifactContentMD5");30artifact.setArtifactLastModified(new Date());31artifact.setArtifactLastModifiedBy("artifactLastModifiedBy");32artifact.setArtifactLastModifiedByHost("artifactLastModifiedByHost");33artifact.setArtifactLastModifiedByIP("artifactLastModifiedByIP");34artifact.setArtifactLastModifiedByOS("artifactLastModifiedByOS");35artifact.setArtifactLastModifiedByOSVersion("artifactLastModifiedByOSVersion");36artifact.setArtifactLastModifiedByJavaVersion("artifactLastModifiedByJavaVersion");37UploadedArtifact artifact = new UploadedArtifact();38artifact.setFileName("fileName");39artifact.setArtifactName("artifactName");40artifact.setArtifactType("artifactType");41artifact.setArtifactContent("artifactContent");42artifact.setArtifactContentType("artifactContentType");43artifact.setArtifactContentEncoding("artifactContentEncoding");44artifact.setArtifactContentLength(0);45artifact.setArtifactContentDisposition("

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = UploadedArtifact.getArtifact("image1.png");2File file = artifact.getFile();3UploadedArtifact artifact = UploadedArtifact.getArtifact("image2.png");4File file = artifact.getFile();5UploadedArtifact artifact = UploadedArtifact.getArtifact("image3.png");6File file = artifact.getFile();7UploadedArtifact artifact = UploadedArtifact.getArtifact("image4.png");8File file = artifact.getFile();9UploadedArtifact artifact = UploadedArtifact.getArtifact("image5.png");10File file = artifact.getFile();11UploadedArtifact artifact = UploadedArtifact.getArtifact("image6.png");12File file = artifact.getFile();13UploadedArtifact artifact = UploadedArtifact.getArtifact("image7.png");14File file = artifact.getFile();15UploadedArtifact artifact = UploadedArtifact.getArtifact("image8.png");16File file = artifact.getFile();17UploadedArtifact artifact = UploadedArtifact.getArtifact("image9.png");18File file = artifact.getFile();19UploadedArtifact artifact = UploadedArtifact.getArtifact("image10.png");20File file = artifact.getFile();21UploadedArtifact artifact1 = UploadedArtifact.getArtifact("image1.png");22File file1 = artifact1.getFile();23UploadedArtifact artifact2 = UploadedArtifact.getArtifact("image2.png");24File file2 = artifact2.getFile();25UploadedArtifact artifact3 = UploadedArtifact.getArtifact("image3.png");26File file3 = artifact3.getFile();

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact("filename");2String path = artifact.getPath();3UploadedArtifact artifact = new UploadedArtifact("filename");4String name = artifact.getName();5UploadedArtifact artifact = new UploadedArtifact("filename");6long size = artifact.getSize();7UploadedArtifact artifact = new UploadedArtifact("filename");8File file = artifact.getFile();9UploadedArtifact artifact = new UploadedArtifact("filename");10byte[] bytes = artifact.getBytes();11UploadedArtifact artifact = new UploadedArtifact("filename");12InputStream stream = artifact.getInputStream();13UploadedArtifact artifact = new UploadedArtifact("filename");14String content = artifact.getContent();15UploadedArtifact artifact = new UploadedArtifact("filename");16String content = artifact.getContent("UTF-16");17UploadedArtifact artifact = new UploadedArtifact("filename");18artifact.delete();19UploadedArtifact artifact = new UploadedArtifact("filename");20artifact.delete(true);

Full Screen

Full Screen

UploadedArtifact

Using AI Code Generation

copy

Full Screen

1UploadedArtifact artifact = new UploadedArtifact("artifactName", "artifactPath");2artifact.setFile(new File("path to file"));3artifact.setArtifactType(ArtifactType.FILE);4artifact.setArtifactSubType(ArtifactSubType.JPEG);5artifact.setArtifactOwner("artifactOwner");6artifact.setArtifactDescription("artifactDescription");7artifact.setArtifactGroup("artifactGroup");8artifact.setArtifactTag("artifactTag");9artifact.setArtifactVersion("artifactVersion");10artifact.setArtifactVisibility(ArtifactVisibility.PUBLIC);11artifact.setArtifactCategory("artifactCategory");12artifact.setArtifactContentType("artifactContentType");13artifact.setArtifactContentEncoding("artifactContentEncoding");14artifact.setArtifactContentLanguage("artifactContentLanguage");15artifact.setArtifactContentLength(100);16artifact.setArtifactContentDisposition("artifactContentDisposition");17artifact.setArtifactContentMD5("artifactContentMD5");18artifact.setArtifactContentLocation("artifactContentLocation");19artifact.setArtifactContentFeatures("artifactContentFeatures");20artifact.setArtifactContentExpires("artifactContentExpires");21artifact.setArtifactContentAllow("artifactContentAllow");22artifact.setArtifactContentExtension("artifactContentExtension");23artifact.setArtifactContentStatus("artifactContentStatus");24artifact.setArtifactContentOther("artifac

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful