/** * Create payload to supply with POST to REST API * * @return */ private FormDataMultiPart createParametersForm() { FormDataMultiPart form = new FormDataMultiPart(); if ( verCount != -1 && !purgeRev ) { form.field( VER_COUNT, Integer.toString( verCount ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( delFrom != null && !purgeRev ) { form.field( DEL_DATE, delFrom, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( fileFilter != null ) { form.field( FILE_FILTER, fileFilter, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( logLevel != null ) { form.field( LOG_LEVEL, logLevel, MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeFiles ) { form.field( PURGE_FILES, Boolean.toString( purgeFiles ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeRev ) { form.field( PURGE_REV, Boolean.toString( purgeRev ), MediaType.MULTIPART_FORM_DATA_TYPE ); } if ( purgeShared ) { form.field( PURGE_SHARED, Boolean.toString( purgeShared ), MediaType.MULTIPART_FORM_DATA_TYPE ); } return form; }
multipart.field( RestParams.COMMIT_ID, props.getProperty( Project.GIT_UUID_KEY ) ); multipart.field( RestParams.MODULE_GROUPID, props.getProperty( Project.GROUP_ID_KEY ) ); multipart.field( RestParams.MODULE_ARTIFACTID, props.getProperty( Project.ARTIFACT_ID_KEY ) ); multipart.field( RestParams.MODULE_VERSION, props.getProperty( Project.PROJECT_VERSION_KEY ) ); multipart.field( RestParams.USERNAME, username ); multipart.field( RestParams.VCS_REPO_URL, props.getProperty( Project.GIT_URL_KEY ) ); multipart.field( RestParams.TEST_PACKAGE, props.getProperty( Project.TEST_PACKAGE_BASE ) ); multipart.field( RestParams.RUNNER_COUNT, runnerCount.toString() ); multipart.field( RestParams.MD5, props.getProperty( Project.MD5_KEY ) );
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(); }
@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 ); }
mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } else { mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE);
private void addDeployFormFields(String name, FormDataMultiPart deployform) { // add the name field, the name is the archive filename without extension deployform.field("name", name, MediaType.TEXT_PLAIN_TYPE); // add the target field (the default is "server" - Admin Server) deployform.field("target", this.configuration.getTarget(), MediaType.TEXT_PLAIN_TYPE); // add the libraries field (optional) if (this.configuration.getLibraries() != null) { deployform.field("libraries", this.configuration.getLibraries(), MediaType.TEXT_PLAIN_TYPE); } // add the properties field (optional) if (this.configuration.getProperties() != null) { deployform.field("properties", this.configuration.getProperties(), MediaType.TEXT_PLAIN_TYPE); } // add the type field (optional, the only valid value is "osgi", other values are ommited) if (this.configuration.getType() != null && "osgi".equals(this.configuration.getType())) { deployform.field("type", this.configuration.getType(), MediaType.TEXT_PLAIN_TYPE); } } }
/** * upload from the given inputstream * * @param fileToUpload * @param filename * @param contents * @param comment * @throws Exception */ public synchronized void upload(InputStream fileToUpload, String filename, String contents, String comment) throws Exception { TokenResult token = getEditToken("File:" + filename, "edit"); final FormDataMultiPart multiPart = new FormDataMultiPart(); // http://stackoverflow.com/questions/5772225/trying-to-upload-a-file-to-a-jax-rs-jersey-server multiPart.bodyPart(new StreamDataBodyPart("file", fileToUpload)); multiPart.field("filename", filename); multiPart.field("ignorewarnings", "true"); multiPart.field("text", contents); if (!comment.isEmpty()) multiPart.field("comment", comment); String params = ""; Api api = this.getActionResult("upload", params, token, multiPart); handleError(api); }
public AtlasImportResult importData(AtlasImportRequest request, String absoluteFilePath) throws AtlasServiceException { FileDataBodyPart filePart = new FileDataBodyPart("data", new File(absoluteFilePath)); MultiPart multipartEntity = new FormDataMultiPart() .field("request", AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE) .bodyPart(filePart); return callAPI(IMPORT, AtlasImportResult.class, multipartEntity); }
/** * Serialize the given Java object into string according the given * Content-Type (only JSON is supported for now). */ public Object serialize(Object obj, String contentType, Map<String, Object> formParams) throws ApiException { if (contentType.startsWith("multipart/form-data")) { FormDataMultiPart mp = new FormDataMultiPart(); for (Entry<String, Object> param: formParams.entrySet()) { if (param.getValue() instanceof File) { File file = (File) param.getValue(); mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.MULTIPART_FORM_DATA_TYPE)); } else { mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE); } } return mp; } else if (contentType.startsWith("application/x-www-form-urlencoded")) { return this.getXWWWFormUrlencodedParams(formParams); } else if (contentType.startsWith("text/csv")) { return this.serializeToCsv(obj); } else { // We let Jersey attempt to serialize the body return obj; } }
mp.bodyPart(new FileDataBodyPart(param.getKey(), file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); } else { mp.field(param.getKey(), parameterToString(param.getValue()), MediaType.MULTIPART_FORM_DATA_TYPE);
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(ids != null) { for(String id:ids) { mp.field("ids[]", id, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(ids != null) { for(String id:ids) { mp.field("ids[]", id, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
public void undeploy(Archive<?> archive) throws DeploymentException { if (archive == null) { throw new IllegalArgumentException("archive must not be null"); } else { deploymentName = createDeploymentName(archive.getName()); try { // Build up the POST form to send to Glassfish final FormDataMultiPart form = new FormDataMultiPart(); form.field("target", this.configuration.getTarget(), MediaType.TEXT_PLAIN_TYPE); form.field("operation", DELETE_OPERATION, MediaType.TEXT_PLAIN_TYPE); glassFishClient.doUndeploy(this.deploymentName, form); } catch (GlassFishClientException e) { throw new DeploymentException("Could not undeploy " + archive.getName(), e); } } }
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; mp.field("undoData", undoData, MediaType.MULTIPART_FORM_DATA_TYPE); if(hasFields) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; mp.field("publishData", publishData, MediaType.MULTIPART_FORM_DATA_TYPE); if(hasFields) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(vertexIds != null) { for(String vertexId:vertexIds) { mp.field("vertexIds[]", vertexId, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(userIds != null) { for(String userId:userIds) { mp.field("userIds[]", userId, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
FormDataMultiPart mp = new FormDataMultiPart(); hasFields = true; if(userIds != null) { for(String userId:userIds) { mp.field("userIds[]", userId, MediaType.MULTIPART_FORM_DATA_TYPE); } } if(hasFields && !mp.getFields().isEmpty()) postBody = mp;
mp.field("visibilitySource", fileForImport.getVisibilitySource(), MediaType.MULTIPART_FORM_DATA_TYPE); FormDataContentDisposition dispo = FormDataContentDisposition .name("file")
@Test public void test() throws Exception { UploadCredentials credentials = new GcsUploadCredentialBuilder(new TestingIdentityService(PRIVATE_KEY_FILE_PATH), "file.png"). setCreatorId(CuidAdapter.userId(1)). setOwnerId(ResourceId.generateId()). setBucket("ai-dev-field-blob-test"). setKey(BlobId.generate().asString()). setMaxContentLengthInMegabytes(10). expireAfter(Duration.standardMinutes(5)). build(); FormDataMultiPart form = new FormDataMultiPart(); for (Map.Entry<String, String> entry : credentials.getFormFields().entrySet()) { form.field(entry.getKey(), entry.getValue()); } form.field("file", Resources.asByteSource(Resources.getResource(getClass(), "goabout.png")).read(), MediaType.valueOf(PNG.toString())); Client.create() .resource(credentials.getUrl()) .entity(form, MediaType.MULTIPART_FORM_DATA_TYPE) .post(); }