@Override public void store( final Project project, final Summary summary, final File resultsFile, final Class<?> testClass ) throws FileNotFoundException, MalformedURLException { Preconditions.checkNotNull( summary, "The summary argument cannot be null." ); // upload the results file InputStream in = new FileInputStream( resultsFile ); FormDataMultiPart part = new FormDataMultiPart(); part.field( FILENAME, resultsFile.getName() ); FormDataBodyPart body = new FormDataBodyPart( CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); WebResource resource = Client.create().resource( coordinatorFig.getEndpoint() ); resource = addQueryParameters( resource, project, me ); String result = resource.path( coordinatorFig.getStoreResultsPath() ) .queryParam( RUN_ID, summary.getRunId() ) .queryParam( RUN_NUMBER, "" + summary.getRunNumber() ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( String.class, part ); LOG.debug( "Got back result from results file store = {}", result ); }
fdmp.bodyPart( new FormDataBodyPart( "properties", baos.toString( "UTF-8" ), APPLICATION_XML_TYPE ) ); fdmp.field( IMPORT_PATH_KEY, pathEncoded, MULTIPART_FORM_DATA_TYPE ); fdmp.field( "fileUpload", fileInputStream, MULTIPART_FORM_DATA_TYPE ); fdmp.getField( "fileUpload" ).setContentDisposition( FormDataContentDisposition.name( "fileUpload" ).fileName( nameEncoded ).build() );
@PUT @Path("16x16") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response post16x16Image(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) { return this.putImage(Filename.FILENAME_SMALL_ICON, uploadedInputStream, body.getMediaType()); }
} else if (body instanceof FormDataMultiPart) { FormDataMultiPart form = (FormDataMultiPart) body; File file = (File) form.getField("file").getEntity(); try { InputStream fileInStream = new FileInputStream(file);
tagList = new ArrayList<>(tagParts.size()); for (FormDataBodyPart part : tagParts) tagList.add(part.getValueAs(String.class)); } else tagList = new ArrayList<>(0); String[] tags = new String[tagList.size()]; entity.setMimeType(uploadedFilePart.getMediaType().toString()); if (entity.getFilename() == null) entity.setFilename(uploadedFileDetail.getFileName()); entity.setMimeType(uploadedFilePart.getMediaType().toString()); entity.setFilename(uploadedFileDetail.getFileName()); entity.setFileSize(new Long(uploadedFile.length));
public MetadataTempFilesListDto uploadMetadataFilesToTempDir( InputStream metadataFile, List<FormDataBodyPart> localeFiles ) throws Exception { List<InputStream> bundles = null; List<String> fileNames = null; if ( localeFiles != null && localeFiles.size() != 0 ) { bundles = new ArrayList<InputStream>(); fileNames = new ArrayList<String>(); for ( FormDataBodyPart localeFile : localeFiles ) { InputStream inputStream = new ByteArrayInputStream( localeFile.getValueAs( byte[].class ) ); bundles.add( inputStream ); fileNames.add( localeFile.getFormDataContentDisposition().getFileName() ); } } return uploadMetadataFilesToTempDir( metadataFile, bundles, fileNames ); }
@Test public void testConvertToMailgun() throws Exception { EmailWrapper wrapper = getTypicalEmailWrapper(); try (FormDataMultiPart formData = new MailgunService().parseToEmail(wrapper)) { assertEquals(wrapper.getSenderName() + " <" + wrapper.getSenderEmail() + ">", formData.getField("from").getValue()); assertEquals(wrapper.getRecipient(), formData.getField("to").getValue()); assertEquals(wrapper.getBcc(), formData.getField("bcc").getValue()); assertEquals(wrapper.getReplyTo(), formData.getField("h:Reply-To").getValue()); assertEquals(wrapper.getSubject(), formData.getField("subject").getValue()); assertEquals(wrapper.getContent(), formData.getField("html").getValue()); } }
public void importMetadataDatasource( String domainId, InputStream metadataFile, FormDataContentDisposition metadataFileInfo, boolean overwrite, List<FormDataBodyPart> localeFiles, List<FormDataContentDisposition> localeFilesInfo, RepositoryFileAclDto acl ) throws PentahoAccessControlException, PlatformImportException, Exception { if ( StringUtils.isEmpty( domainId ) ) { throw new PlatformImportException( Messages.getString( "MetadataDatasourceService.ERROR_005_DOMAIN_NAME_EMPTY" ) ); } List<InputStream> localeFileStreams = null; List<String> localeFileNames = null; if ( localeFiles != null ) { localeFileStreams = new ArrayList<InputStream>(); localeFileNames = new ArrayList<String>(); for ( int i = 0; i < localeFiles.size(); i++ ) { logger.info( "create language file" ); InputStream inputStream = createNewByteArrayInputStream( localeFiles.get( i ).getValueAs( byte[].class ) ); localeFileStreams.add( inputStream ); localeFileNames.add( localeFilesInfo.get( i ).getFileName() ); } } importMetadataDatasource( domainId, metadataFile, overwrite, localeFileStreams, localeFileNames, acl ); }
@PUT @Path("50x50") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response post50x50Image(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) { return this.putImage(Filename.FILENAME_BIG_ICON, uploadedInputStream, body.getMediaType()); }
} else if (body instanceof FormDataMultiPart) { FormDataMultiPart form = (FormDataMultiPart) body; File file = (File) form.getField("file").getEntity(); try { InputStream fileInStream = new FileInputStream(file);
FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); multipart.bodyPart( body );
@PUT @Path("image.jpg") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response putImage(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) { try { SelfServiceMetaDataUtils.ensureDataXmlExists(this.id); } catch (IOException e) { throw new WebApplicationException(e); } RepositoryFileReference ref = new RepositoryFileReference(this.id, "image.jpg"); Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType()); if (StringUtils.isEmpty(this.application.getImageUrl())) { this.application.setImageUrl("image.jpg"); persist(); } return response; }
} else if (body instanceof FormDataMultiPart) { FormDataMultiPart form = (FormDataMultiPart) body; File file = (File) form.getField("file").getEntity(); try { InputStream fileInStream = new FileInputStream(file);
static void testUpload(TestParams testParams) throws Exception { FormDataMultiPart part = new FormDataMultiPart(); part.field( RestParams.COMMIT_ID, QUERY_PARAMS.get( RestParams.COMMIT_ID ) ); part.field( RestParams.MODULE_GROUPID, QUERY_PARAMS.get( RestParams.MODULE_GROUPID ) ); part.field( RestParams.MODULE_ARTIFACTID, QUERY_PARAMS.get( RestParams.MODULE_ARTIFACTID ) ); part.field( RestParams.MODULE_VERSION, QUERY_PARAMS.get( RestParams.MODULE_VERSION ) ); part.field( RestParams.USERNAME, QUERY_PARAMS.get( RestParams.USERNAME ) ); part.field( RestParams.VCS_REPO_URL, "ssh://git@stash.safehaus.org:7999/chop/main.git" ); part.field( RestParams.TEST_PACKAGE, QUERY_PARAMS.get( RestParams.TEST_PACKAGE ) ); part.field( RestParams.MD5, "d7d4829506f6cb8c0ab2da9cb1daca02" ); File tmpFile = File.createTempFile("runner", "jar"); FileInputStream in = new FileInputStream( tmpFile ); FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); ClientResponse response = testParams.addQueryParameters( QUERY_PARAMS ) .setEndpoint( UploadResource.ENDPOINT ) .newWebResource() .path( "/runner" ) .type( MediaType.MULTIPART_FORM_DATA ) .accept( MediaType.TEXT_PLAIN ) .post( ClientResponse.class, part ); assertEquals( Response.Status.CREATED.getStatusCode(), response.getStatus() ); assertEquals( UploadResource.SUCCESSFUL_TEST_MESSAGE, response.getEntity( String.class ) ); tmpFile.delete(); }
@PUT @Path("icon.jpg") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response putIcon(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataBodyPart body) { try { SelfServiceMetaDataUtils.ensureDataXmlExists(this.id); } catch (IOException e) { throw new WebApplicationException(e); } RepositoryFileReference ref = new RepositoryFileReference(this.id, "icon.jpg"); Response response = RestUtils.putContentToFile(ref, uploadedInputStream, body.getMediaType()); if (StringUtils.isEmpty(this.application.getIconUrl())) { this.application.setIconUrl("icon.jpg"); persist(); } return response; }
static void testStoreResults( TestParams testParams ) throws Exception { FormDataMultiPart part = new FormDataMultiPart(); File tmpFile = File.createTempFile("results", "tmp"); FileInputStream in = new FileInputStream( tmpFile ); FormDataBodyPart body = new FormDataBodyPart( RestParams.CONTENT, in, MediaType.APPLICATION_OCTET_STREAM_TYPE ); part.bodyPart( body ); ClientResponse response = testParams.addQueryParameters( QUERY_PARAMS ) .setEndpoint( RunManagerResource.ENDPOINT ) .newWebResource() .queryParam( RestParams.RUNNER_HOSTNAME, "localhost" ) .queryParam( RestParams.RUN_ID, "112316437" ) .queryParam( RestParams.RUN_NUMBER, "3" ) .path( "/store" ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .accept( MediaType.APPLICATION_JSON ) .post( ClientResponse.class, part ); tmpFile.delete(); assertEquals( Response.Status.CREATED.getStatusCode(), response.getStatus() ); assertEquals( UploadResource.SUCCESSFUL_TEST_MESSAGE, response.getEntity( String.class ) ); }
public Response onPost(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @Context UriInfo uriInfo, String fileName) { // existence check not required as instantiation of the resource ensures that the object only exists if the resource exists FilesResource.LOGGER.debug("Beginning with file upload"); if (StringUtils.isEmpty(fileName)) { return Response.status(Status.BAD_REQUEST).build(); } RepositoryFileReference ref = this.fileName2fileRef(fileName, false); // TODO: instead of fixing the media type, we could overwrite the browser's mediatype by using some user configuration BufferedInputStream bis = new BufferedInputStream(uploadedInputStream); org.apache.tika.mime.MediaType mediaType = BackendUtils.getFixedMimeType(bis, fileName, org.apache.tika.mime.MediaType.parse(body.getMediaType().toString())); Response response = RestUtils.putContentToFile(ref, bis, mediaType); if (response.getStatus() == Status.INTERNAL_SERVER_ERROR.getStatusCode()) { return response; } try { BackendUtils.synchronizeReferences(RepositoryFactory.getRepository(), (ArtifactTemplateId) fileDir.getParent()); } catch (IOException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } String URL = RestUtils.getAbsoluteURL(this.fileDir) + Util.URLencode(fileName); return Response.created(RestUtils.createURI(URL)).entity(this.getAllFileMetas()).build(); }
private FormDataBodyPart getImportRequestBodyPart(AtlasImportRequest request) { return new FormDataBodyPart(IMPORT_REQUEST_PARAMTER, AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE); }
RestUtils.putContentToFile(iconRef, uploadedInputStream, body.getMediaType());